Main Page   Class Hierarchy   Compound List   File List   Compound Members  

states.cpp

00001 /*
00002  * Purpose: private wxWindows helper classes for SMTP
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006 
00007 #include "states.h"
00008 
00009 
00010 const InitialState g_initialState;
00011 const ConnectedState g_connectedState;
00012 const HeloState g_heloState;
00013 const SendMailFromState g_sendMailFromState;
00014 const RcptListState g_rcptListState;
00015 const StartDataState g_startDataState;
00016 const DataState g_dataState;
00017 
00018 
00019 void InitialState::onConnect(wxSMTP& context, wxSocketEvent& event) const
00020 {
00021     if (event.GetSocketEvent() == wxSOCKET_CONNECTION) {
00022         context.ChangeState(g_connectedState);
00023     } else {
00024         // error
00025     }
00026 }
00027 
00028 
00029 void ConnectedState::onResponse(wxSMTP& context, int smtpCode) const
00030 {
00031     if (smtpCode == 220) {
00032         context.ChangeState(g_heloState);
00033         // TODO: using some wxWindows function for getting the hostname
00034         context.Write("HELO localhost\x00d\x00a");
00035     } else {
00036         // error
00037     }
00038 }
00039 
00040 
00041 void HeloState::onResponse(wxSMTP& context, int smtpCode) const
00042 {
00043     if (smtpCode == 250) {
00044         context.ChangeState(g_sendMailFromState);
00045         context.SendFrom();
00046     } else {
00047         // error
00048     }
00049 }
00050 
00051 
00052 void SendMailFromState::onResponse(wxSMTP& context, int smtpCode) const
00053 {
00054     if (smtpCode == 250) {
00055         context.ChangeState(g_rcptListState);
00056         context.SendNextRecipient();
00057     } else {
00058         // error
00059     }
00060 }
00061 
00062 
00063 void RcptListState::onResponse(wxSMTP& context, int smtpCode) const
00064 {
00065     switch (smtpCode) {
00066         case 250:
00067         case 251:
00068             context.OnRecipientSuccess();
00069             break;
00070         case 421:  // service not available
00071             // error
00072             break;
00073         default:
00074             context.OnRecipientError();
00075     }
00076     context.SendNextRecipient();
00077 }
00078 
00079 
00080 void StartDataState::onResponse(wxSMTP& context, int smtpCode) const
00081 {
00082     if (smtpCode == 354) {
00083         context.ChangeState(g_dataState);
00084         context.SendData();
00085     }
00086 }
00087 
00088 
00089 void DataState::onResponse(wxSMTP& context, int smtpCode) const
00090 {
00091     if (smtpCode == 250) {
00092         context.OnDataSuccess();
00093     }
00094 }

Generated on Mon May 6 01:14:20 2002 for Wino by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001