94 lines
2.0 KiB
C++
94 lines
2.0 KiB
C++
/*
|
|
* Purpose: private wxWindows helper classes for SMTP
|
|
* Author: Frank Buß
|
|
* Created: 2002
|
|
*/
|
|
|
|
#include "states.h"
|
|
|
|
|
|
const InitialState g_initialState;
|
|
const ConnectedState g_connectedState;
|
|
const HeloState g_heloState;
|
|
const SendMailFromState g_sendMailFromState;
|
|
const RcptListState g_rcptListState;
|
|
const StartDataState g_startDataState;
|
|
const DataState g_dataState;
|
|
|
|
|
|
void InitialState::onConnect(wxSMTP& context, wxSocketEvent& event) const
|
|
{
|
|
if (event.GetSocketEvent() == wxSOCKET_CONNECTION) {
|
|
context.ChangeState(g_connectedState);
|
|
} else {
|
|
// error
|
|
}
|
|
}
|
|
|
|
|
|
void ConnectedState::onResponse(wxSMTP& context, int smtpCode) const
|
|
{
|
|
if (smtpCode == 220) {
|
|
context.ChangeState(g_heloState);
|
|
// TODO: using some wxWindows function for getting the hostname
|
|
context.Write(wxT("HELO localhost\x00d\x00a"));
|
|
} else {
|
|
// error
|
|
}
|
|
}
|
|
|
|
|
|
void HeloState::onResponse(wxSMTP& context, int smtpCode) const
|
|
{
|
|
if (smtpCode == 250) {
|
|
context.ChangeState(g_sendMailFromState);
|
|
context.SendFrom();
|
|
} else {
|
|
// error
|
|
}
|
|
}
|
|
|
|
|
|
void SendMailFromState::onResponse(wxSMTP& context, int smtpCode) const
|
|
{
|
|
if (smtpCode == 250) {
|
|
context.ChangeState(g_rcptListState);
|
|
context.SendNextRecipient();
|
|
} else {
|
|
// error
|
|
}
|
|
}
|
|
|
|
|
|
void RcptListState::onResponse(wxSMTP& context, int smtpCode) const
|
|
{
|
|
switch (smtpCode) {
|
|
case 250:
|
|
case 251:
|
|
context.OnRecipientSuccess();
|
|
break;
|
|
case 421: // service not available
|
|
// error
|
|
break;
|
|
default:
|
|
context.OnRecipientError();
|
|
}
|
|
context.SendNextRecipient();
|
|
}
|
|
|
|
|
|
void StartDataState::onResponse(wxSMTP& context, int smtpCode) const
|
|
{
|
|
if (smtpCode == 354) {
|
|
context.ChangeState(g_dataState);
|
|
context.SendData();
|
|
}
|
|
}
|
|
|
|
|
|
void DataState::onResponse(wxSMTP& context, int smtpCode) const
|
|
{
|
|
if (smtpCode == 250) {
|
|
context.OnDataSuccess();
|
|
}
|
|
} |