Alessandro Bonazzi 5e9513c5b2 Patch level : 12.00
Files correlati     :

Commento:
wxSMTP
2024-11-05 20:43:31 +01:00

105 lines
6.8 KiB
C++

/*
* Purpose: private wxWindows mail transport implementation
* Author: Frank Buß
* Created: 2002
*/
#include <wx/sckstrm.h>
#include "smtp.h"
#include "states.h"
#define SOCKET_ID 1
wxSMTPListener g_nullListener;
wxSMTP::wxSMTP(wxSMTPListener* pListener) :
m_pMailState(&g_initialState)
{
if (pListener) {
m_pListener = pListener;
} else {
m_pListener = &g_nullListener;
}
m_pMessage = NULL;
}
wxSMTP::~wxSMTP()
{
}
void wxSMTP::EvaluateLine(const wxString& line)
{
// TODO: implementing response timeout somewhere
// TODO: implementing multiline response
// get command
unsigned long cmd = 0;
line.ToULong(&cmd);
m_pMailState->onResponse(*this, cmd);
}
void wxSMTP::OnConnect(wxSocketEvent& event)
{
m_pMailState->onConnect(*this, event);
}
void wxSMTP::Send(wxEmailMessage* pMessage)
{
// no message means nothing to do
if (!pMessage) return;
m_pMessage = pMessage;
// add recipients from message
wxRecipientsIterator ri = m_pMessage->GetRecipientsIterator();
while (ri.HasNext()) m_recipients.Add(ri.GetNext());
m_count = 0;
// init new socket connection
m_pMailState = &g_initialState;
Connect();
}
void wxSMTP::ChangeState(const MailState& mailState)
{
m_pMailState = &mailState;
}
void wxSMTP::SendNextRecipient()
{
if (m_count < m_recipients.GetCount()) {
m_currentRecipient = m_recipients[m_count++];
Write(wxT("RCPT TO:<") + m_currentRecipient + wxT(">\x00d\x00a"));
} else {
ChangeState(g_startDataState);
Write(wxT("DATA\x00d\x00a"));
}
}
void wxSMTP::OnRecipientError()
{
m_pListener->OnRecipientAdded(m_currentRecipient, 0);
}
void wxSMTP::OnRecipientSuccess()
{
m_pListener->OnRecipientAdded(m_currentRecipient, 1);
}
void wxSMTP::OnDataSuccess()
{
m_pListener->OnDataSent(1);
}
void wxSMTP::SendFrom()
{
Write(wxT("MAIL FROM:<") + m_pMessage->GetFrom() + wxT(">\x00d\x00a"));
}
void wxSMTP::SendData()
{
wxSocketOutputStream out(*this);
// wxFileOutputStream out("mail.txt");
m_pMessage->Encode(out);
}