Main Page

Wino Documentation

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


File Index

Wino File List

Here is a list of all documented files with brief descriptions:
base64.cpp [code]
base64.h [code]
cmdprot.cpp [code]
cmdprot.h [code]
email.cpp [code]
email.h [code]
mime.cpp [code]
mime.h [code]
smtp.cpp [code]
smtp.h [code]
snddlg.cpp [code]
snddlg.h [code]
states.cpp [code]
states.h [code]
wino.cpp [code]
wino.h [code]


Annotated Index

Wino Compound List

Here are the classes, structs, unions and interfaces with brief descriptions:
ConnectedState | This state is active, if the server connection is established
DataState | This state is active, when the data was sent
HeloState | This state is active, when the helo message was sent
InitialState | This state is the initial state, when no server connection is made
MailState | Base class for all mail states
RcptListState | This state is active as long as there are additional recipients and no error occured (TODO: error-handling not implemented)
SendDialog | Define the one and only dialog for this application
SendMailFromState | This state is active, when the from message was sent
StartDataState | This state is active, when the DATA command was sent
WinoApp | Define the Wino (Wino Is Not Outlook) application type
WinoDialog | Define the one and only dialog for this application
wxBase64 | Helper class for encoding / decoding base64
wxCmdlineProtocol | Base class for all command line oriented internet protocols
wxEmailMessage | An email without transport mechanism specific declarations or implementations
wxMimePart | Public helper class for MIME encoding and type determining
wxRecipientsIterator | Public helper class for iterating through all recipients of an email
wxSMTP | Implementation of the sendmail class for SMTP email sending
wxSMTPListener | Public available interface for classes who wants to be notified asynchronly about SMTP events


ConnectedState Class Reference

This state is active, if the server connection is established. More...

#include <states.h>

Inheritance diagram for ConnectedState::

MailState List of all members.

Public Methods

void onResponse (wxSMTP &context, int smtpCode) const
Switches to HeloState, if welcome message is received. More...

Detailed Description

This state is active, if the server connection is established.

Definition at line 44 of file states.h.

Member Function Documentation

void ConnectedState::onResponse | ( | wxSMTP & | context,
 |  | int | smtpCode
 | ) | const [virtual]

Switches to HeloState, if welcome message is received.

See also:
HeloState.

Reimplemented from MailState.

Definition at line 29 of file states.cpp.

References wxSMTP::ChangeState(), and wxCmdlineProtocol::Write().


DataState Class Reference

This state is active, when the data was sent. More...

#include <states.h>

Inheritance diagram for DataState::

MailState List of all members.

Public Methods

void onResponse (wxSMTP &context, int smtpCode) const
Acknowledges by calling MailContext::OnDataSuccess, if the data sent was acknowledged. More...

Detailed Description

This state is active, when the data was sent.

Definition at line 115 of file states.h.

Member Function Documentation

void DataState::onResponse | ( | wxSMTP & | context,
 |  | int | smtpCode
 | ) | const [virtual]

Acknowledges by calling MailContext::OnDataSuccess, if the data sent was acknowledged.

See also:
SendmailImpl::OnDataSuccess().

Reimplemented from MailState.

Definition at line 89 of file states.cpp.

References wxSMTP::OnDataSuccess().


HeloState Class Reference

This state is active, when the helo message was sent. More...

#include <states.h>

Inheritance diagram for HeloState::

MailState List of all members.

Public Methods

void onResponse (wxSMTP &context, int smtpCode) const
Switches to SendMailFromState, if the helo message was acknowledged. More...

Detailed Description

This state is active, when the helo message was sent.

Definition at line 58 of file states.h.

Member Function Documentation

void HeloState::onResponse | ( | wxSMTP & | context,
 |  | int | smtpCode
 | ) | const [virtual]

Switches to SendMailFromState, if the helo message was acknowledged.

See also:
SendMailFromState.

Reimplemented from MailState.

Definition at line 41 of file states.cpp.

References wxSMTP::ChangeState(), and wxSMTP::SendFrom().


InitialState Class Reference

This state is the initial state, when no server connection is made. More...

#include <states.h>

Inheritance diagram for InitialState::

MailState List of all members.

Public Methods

void onConnect (wxSMTP &context, wxSocketEvent &event) const
Switches to ConnectedState, if successfully connected. More...

Detailed Description

This state is the initial state, when no server connection is made.

Definition at line 30 of file states.h.

Member Function Documentation

void InitialState::onConnect | ( | wxSMTP & | context,
 |  | wxSocketEvent & | event
 | ) | const [virtual]

Switches to ConnectedState, if successfully connected.

See also:
ConnectedState.

Reimplemented from MailState.

Definition at line 19 of file states.cpp.

References wxSMTP::ChangeState().


MailState Class Reference

Base class for all mail states. More...

#include <states.h>

Inheritance diagram for MailState::

ConnectedState DataState HeloState InitialState RcptListState SendMailFromState StartDataState List of all members.

Detailed Description

Base class for all mail states.

Every mail state is only instantiated once and has no attributes (flyweight pattern? I don't know the name). The only reason for the state classes is not to have a big switch-case block.

Definition at line 20 of file states.h.


RcptListState Class Reference

This state is active as long as there are additional recipients and no error occured (TODO: error-handling not implemented). More...

#include <states.h>

Inheritance diagram for RcptListState::

MailState List of all members.

Public Methods

void onResponse (wxSMTP &context, int smtpCode) const
SendmailImpl wwitches to StartDataState, if there are no more recipients. More...

Detailed Description

This state is active as long as there are additional recipients and no error occured (TODO: error-handling not implemented).

Definition at line 87 of file states.h.

Member Function Documentation

void RcptListState::onResponse | ( | wxSMTP & | context,
 |  | int | smtpCode
 | ) | const [virtual]

SendmailImpl wwitches to StartDataState, if there are no more recipients.

See also:
StartDataState.

Reimplemented from MailState.

Definition at line 63 of file states.cpp.

References wxSMTP::OnRecipientError(), wxSMTP::OnRecipientSuccess(), and wxSMTP::SendNextRecipient().


SendDialog Class Reference

Define the one and only dialog for this application. More...

#include <snddlg.h>

Inheritance diagram for SendDialog::

wxSMTPListener List of all members.

Public Methods

SendDialog (WinoDialog &winoDialog)
Setup the dialog controls and center the dialog. More...

void | OnSocketError (int errorCode)
wxSMTPListener interface: Is called if an error occured (not implemented). More...

void | OnRecipientAdded (const wxString &address, int errorCode)
wxSMTPListener interface: Is called if the server acknowleded a recipient. More...

void | OnDataSent (int errorCode)
wxSMTPListener interface: Is called if the server acknowleded the email text was sent. More...

Detailed Description

Define the one and only dialog for this application.

Definition at line 20 of file snddlg.h.

Constructor & Destructor Documentation

SendDialog::SendDialog ( WinoDialog & winoDialog )

Setup the dialog controls and center the dialog.

Definition at line 138 of file snddlg.cpp.

References wxEmailMessage::AddFile(), wxEmailMessage::AddTo(), wxSMTP::Send(), and wxCmdlineProtocol::SetHost().

Member Function Documentation

void SendDialog::OnDataSent ( int errorCode ) [virtual]

wxSMTPListener interface: Is called if the server acknowleded the email text was sent.

Reimplemented from wxSMTPListener.

Definition at line 247 of file snddlg.cpp.

void SendDialog::OnRecipientAdded | ( | const wxString & | address,
 |  | int | errorCode
 | ) | [virtual]

wxSMTPListener interface: Is called if the server acknowleded a recipient.

Reimplemented from wxSMTPListener.

Definition at line 237 of file snddlg.cpp.

void SendDialog::OnSocketError ( int errorCode ) [virtual]

wxSMTPListener interface: Is called if an error occured (not implemented).

Reimplemented from wxSMTPListener.

Definition at line 233 of file snddlg.cpp.


SendMailFromState Class Reference

This state is active, when the from message was sent. More...

#include <states.h>

Inheritance diagram for SendMailFromState::

MailState List of all members.

Public Methods

void onResponse (wxSMTP &context, int smtpCode) const
Switches to RcptListState, if the from message was acknowledged. More...

Detailed Description

This state is active, when the from message was sent.

Definition at line 72 of file states.h.

Member Function Documentation

void SendMailFromState::onResponse | ( | wxSMTP & | context,
 |  | int | smtpCode
 | ) | const [virtual]

Switches to RcptListState, if the from message was acknowledged.

See also:
RcptListState.

Reimplemented from MailState.

Definition at line 52 of file states.cpp.

References wxSMTP::ChangeState(), and wxSMTP::SendNextRecipient().


StartDataState Class Reference

This state is active, when the DATA command was sent. More...

#include <states.h>

Inheritance diagram for StartDataState::

MailState List of all members.

Public Methods

void onResponse (wxSMTP &context, int smtpCode) const
Switches to DataState, if the DATA command was acknowledged. More...

Detailed Description

This state is active, when the DATA command was sent.

Definition at line 101 of file states.h.

Member Function Documentation

void StartDataState::onResponse | ( | wxSMTP & | context,
 |  | int | smtpCode
 | ) | const [virtual]

Switches to DataState, if the DATA command was acknowledged.

See also:
DataState.

Reimplemented from MailState.

Definition at line 80 of file states.cpp.

References wxSMTP::ChangeState(), and wxSMTP::SendData().


WinoApp Class Reference

Define the Wino (Wino Is Not Outlook) application type. More...

#include <wino.h>

List of all members.

Public Methods

bool OnInit ()
Shows the WinoDialog and return false, for terminating the program after closing the modal dialog. More...

Detailed Description

Define the Wino (Wino Is Not Outlook) application type.

Definition at line 20 of file wino.h.

Member Function Documentation

bool WinoApp::OnInit ( void )

Shows the WinoDialog and return false, for terminating the program after closing the modal dialog.

Returns:
false.

Definition at line 36 of file wino.cpp.


WinoDialog Class Reference

Define the one and only dialog for this application. More...

#include <wino.h>

List of all members.

Public Methods

WinoDialog (wxWindow *parent)
Setup the dialog controls and center the dialog. More...

void | OnSendButton (wxCommandEvent &event)
Sends the email. More...

void | OnFileAddButton (wxCommandEvent &event)
Adds an file attachment. More...

void | OnFileRemoveButton (wxCommandEvent &event)
Removes the currently selected file attachment. More...

void | OnAddressAddButton (wxCommandEvent &event)
Adds a Address Manager database. More...

void | OnAddressRemoveButton (wxCommandEvent &event)
Removes the currently selected Address Manager database. More...

Friends

class | SendDialog

Detailed Description

Define the one and only dialog for this application.

Definition at line 34 of file wino.h.

Constructor & Destructor Documentation

WinoDialog::WinoDialog ( wxWindow * parent )

Setup the dialog controls and center the dialog.

Definition at line 46 of file wino.cpp.

Member Function Documentation

void WinoDialog::OnAddressAddButton ( wxCommandEvent & event )

Adds a Address Manager database.

Definition at line 160 of file wino.cpp.

void WinoDialog::OnAddressRemoveButton ( wxCommandEvent & event )

Removes the currently selected Address Manager database.

Definition at line 169 of file wino.cpp.

void WinoDialog::OnFileAddButton ( wxCommandEvent & event )

Adds an file attachment.

Definition at line 141 of file wino.cpp.

void WinoDialog::OnFileRemoveButton ( wxCommandEvent & event )

Removes the currently selected file attachment.

Definition at line 150 of file wino.cpp.

void WinoDialog::OnSendButton ( wxCommandEvent & event )

Sends the email.

Definition at line 134 of file wino.cpp.


wxBase64 Class Reference

Helper class for encoding / decoding base64. More...

#include <base64.h>

List of all members.

Static Public Methods

wxString | Encode (const wxUint8 *pData, size_t length)
Converts a byte array to a base64 encoded string. More...

wxString | Decode (const wxString &data)
Decodes a base64 encoded string. More...

Detailed Description

Helper class for encoding / decoding base64.

Definition at line 22 of file base64.h.

Member Function Documentation

wxString wxBase64::Decode ( const wxString & data ) [static]

Decodes a base64 encoded string.

Parameters:
data The base64 encoded string.
Returns:
The decoded binary string (may contain 0).

Definition at line 79 of file base64.cpp.

wxString wxBase64::Encode | ( | const wxUint8 * | pData,
 |  | size_t | len
 | ) | [static]

Converts a byte array to a base64 encoded string.

Parameters:
pData | The byte array.
length | The length of the byte array.
Returns:
The base64 representation of the byte array.

Definition at line 30 of file base64.cpp.

Referenced by wxMimePart::Encode().


wxCmdlineProtocol Class Reference

Base class for all command line oriented internet protocols. More...

#include <cmdprot.h>

Inheritance diagram for wxCmdlineProtocol::

wxSMTP List of all members.

Public Methods

void | SetHost (const wxString &host, const wxString &user="", const wxString &password="")
Sets the SMTP server and the optional login information. More...

virtual void | EvaluateLine (const wxString &line)=0
Is called for every line input. More...

virtual void | OnConnect (wxSocketEvent &event)=0
Is called if successfully connected to the server. More...

void | OnInput (wxSocketEvent &event)
This method is called if new data is available on the socket. More...

void | OnSocketEvent (wxSocketEvent &event)
Message handler for wxWindows socket events. More...

void | Write (const wxString &msg)
Writes the specified string to the socket. More...

Detailed Description

Base class for all command line oriented internet protocols.

Definition at line 20 of file cmdprot.h.

Member Function Documentation

virtual void wxCmdlineProtocol::EvaluateLine ( const wxString & line ) [pure virtual]

Is called for every line input.

Parameters:
line The server response.

Reimplemented in wxSMTP.

Referenced by OnInput().

virtual void wxCmdlineProtocol::OnConnect ( wxSocketEvent & event ) [pure virtual]

Is called if successfully connected to the server.

Parameters:
event The wxSOCKET_CONNECTION event.

Reimplemented in wxSMTP.

Referenced by OnSocketEvent().

void wxCmdlineProtocol::OnInput ( wxSocketEvent & event )

This method is called if new data is available on the socket.

It extracts one line, terminated by CRLF, and calls EvaluateLine.

Parameters:
event The wxSOCKET_INPUT event.

Definition at line 68 of file cmdprot.cpp.

References EvaluateLine().

Referenced by OnSocketEvent().

void wxCmdlineProtocol::OnSocketEvent ( wxSocketEvent & event )

Message handler for wxWindows socket events.

Definition at line 99 of file cmdprot.cpp.

References OnConnect(), and OnInput().

void wxCmdlineProtocol::SetHost | ( | const wxString & | host,
 |  | const wxString & | user = "",
 |  | const wxString & | password = ""
 | ) |

Sets the SMTP server and the optional login information.

No server connection will be established until 'Send' is called.

Parameters:
host | SMTP server.
user | User used for login, if specified.
password | Password used for login, if specified.

Definition at line 46 of file cmdprot.cpp.

Referenced by SendDialog::SendDialog().

void wxCmdlineProtocol::Write ( const wxString & msg )

Writes the specified string to the socket.

Parameters:
msg The string to be written.

Definition at line 117 of file cmdprot.cpp.

Referenced by ConnectedState::onResponse(), wxSMTP::SendFrom(), and wxSMTP::SendNextRecipient().


wxEmailMessage Class Reference

An email without transport mechanism specific declarations or implementations. More...

#include <email.h>

List of all members.

Public Methods

wxEmailMessage (const wxString &subject, const wxString &text, const wxString &from)
Constructs a new email. More...

const wxString & | GetFrom ()
Gets the from string, which was specified in the constructor. More...

void | AddRecipient (const wxString &address)
Adds an additional recipient. More...

void | AddTo (const wxString &address)
Adds an additional recipient in the to-field. More...

void | AddCc (const wxString &address)
Adds an additional recipient in the cc-field. More...

void | AddBcc (const wxString &address)
Adds an additional recipient in the bcc-field. More...

void | AddFile (const wxFileName &fileName, const wxString mimeMainType="", const wxString mimeSubType="")
Adds an file attachment. More...

wxRecipientsIterator GetRecipientsIterator ()
Returns an iterator for iterating through all recipients: to, cc and bcc. More...

void | Encode (wxOutputStream &out)
Writes the message as one blob, MIME encoded, if necessary, e.g. More...

Friends

class | wxRecipientsIterator

Detailed Description

An email without transport mechanism specific declarations or implementations.

Definition at line 22 of file email.h.

Constructor & Destructor Documentation

wxEmailMessage::wxEmailMessage | ( | const wxString & | subject,
 |  | const wxString & | text,
 |  | const wxString & | from
 | ) |

Constructs a new email.

Parameters:
subject | Subject.
text | The body text.
from | From.

Definition at line 11 of file email.cpp.

Member Function Documentation

void wxEmailMessage::AddBcc ( const wxString & address )

Adds an additional recipient in the bcc-field.

Parameters:
address The email address of the recipient.

Definition at line 38 of file email.cpp.

void wxEmailMessage::AddCc ( const wxString & address )

Adds an additional recipient in the cc-field.

Parameters:
address The email address of the recipient.

Definition at line 33 of file email.cpp.

void wxEmailMessage::AddFile | ( | const wxFileName & | fileName,
 |  | const wxString | mimeMainType = "",
 |  | const wxString | mimeSubType = ""
 | ) |

Adds an file attachment.

If no mime-type is specified the type will be determined by the file extension.

Parameters:
fileName | Filename of the new file attachment.
mimeMainType | MIME main type, like 'image'.
mimeSubType | MIME sub type, like 'jpeg'.

Definition at line 43 of file email.cpp.

Referenced by SendDialog::SendDialog().

void wxEmailMessage::AddRecipient ( const wxString & address )

Adds an additional recipient.

You can add as many recipients as you want and don't have to specify it in the email message, for example if you want to send a mailing list. The RFC 821 (SMTP) garantuees 100 recipients at once, but most

Parameters:
address Email address of the additional recipient.

Definition at line 23 of file email.cpp.

void wxEmailMessage::AddTo ( const wxString & address )

Adds an additional recipient in the to-field.

Parameters:
address The email address of the recipient.

Definition at line 28 of file email.cpp.

Referenced by SendDialog::SendDialog().

void wxEmailMessage::Encode ( wxOutputStream & out )

Writes the message as one blob, MIME encoded, if necessary, e.g.

for sending it with SMTP.

Parameters:
out The output stream to which the email has to be written.

Definition at line 54 of file email.cpp.

Referenced by wxSMTP::SendData().

const wxString & wxEmailMessage::GetFrom ( )

Gets the from string, which was specified in the constructor.

Returns:
The from string.

Definition at line 18 of file email.cpp.

Referenced by wxSMTP::SendFrom().

wxRecipientsIterator wxEmailMessage::GetRecipientsIterator ( )

Returns an iterator for iterating through all recipients: to, cc and bcc.

Returns:
A new iterator for this object.
See also:
wxRecipientsIterator.

Definition at line 49 of file email.cpp.

Referenced by wxSMTP::Send().


wxMimePart Class Reference

Public helper class for MIME encoding and type determining. More...

#include <mime.h>

List of all members.

Public Methods

wxMimePart (const wxFileName &fileName)
Constructs a MIME part and tries to determine the type from the filename extension. More...

void Encode (wxOutputStream &out)
Writes the file MIME encoded (currently only base64) to the specified stream. More...

Detailed Description

Public helper class for MIME encoding and type determining.

Definition at line 17 of file mime.h.

Constructor & Destructor Documentation

wxMimePart::wxMimePart ( const wxFileName & fileName )

Constructs a MIME part and tries to determine the type from the filename extension.

If this doesn't work, it sets the default type application/octet-stream. The specified file will be read if Encode is called.

Parameters:
fileName File to be encoded as a MIME part.

Definition at line 36 of file mime.cpp.

Member Function Documentation

void wxMimePart::Encode ( wxOutputStream & out )

Writes the file MIME encoded (currently only base64) to the specified stream.

Parameters:
out The stream, to which the MIME part will be written.

Definition at line 54 of file mime.cpp.

References wxBase64::Encode().


wxRecipientsIterator Class Reference

Public helper class for iterating through all recipients of an email. More...

#include <email.h>

List of all members.

Public Methods

wxRecipientsIterator (const wxEmailMessage &emailMessage)
Creates a new iterator for the specified wxEmailMessage object. More...

bool | HasNext ()
Test if there are any more email recipients to be iterated. More...

wxString | GetNext ()
Gets the next email recipient and increments the iterator pointer. More...

Detailed Description

Public helper class for iterating through all recipients of an email.

Definition at line 108 of file email.h.

Constructor & Destructor Documentation

wxRecipientsIterator::wxRecipientsIterator ( const wxEmailMessage & emailMessage )

Creates a new iterator for the specified wxEmailMessage object.

Parameters:
emailMessage The wxEmailMessage object for which the iterator should iterate all recipients.

Definition at line 86 of file email.cpp.

Member Function Documentation

wxString wxRecipientsIterator::GetNext ( )

Gets the next email recipient and increments the iterator pointer.

Returns:
The next email recipient.

Definition at line 107 of file email.cpp.

References wxEmailMessage::m_bccArray, wxEmailMessage::m_ccArray, wxEmailMessage::m_rcptArray, and wxEmailMessage::m_toArray.

Referenced by wxSMTP::Send().

bool wxRecipientsIterator::HasNext ( )

Test if there are any more email recipients to be iterated.

The test doesn't increment the internal iterator counter.

Returns:
true, if there are more email recipients.

Definition at line 95 of file email.cpp.

References wxEmailMessage::m_bccArray, wxEmailMessage::m_ccArray, wxEmailMessage::m_rcptArray, and wxEmailMessage::m_toArray.

Referenced by wxSMTP::Send().


wxSMTP Class Reference

Implementation of the sendmail class for SMTP email sending. More...

#include <smtp.h>

Inheritance diagram for wxSMTP::

wxCmdlineProtocol List of all members.

Public Methods

void | Send (wxEmailMessage *pMessage)
Called by Sendmail::Send(). More...

void | EvaluateLine (const wxString &line)
Is called for every line input. More...

void | OnConnect (wxSocketEvent &event)
Is called if successfully connected to the server. More...

void | ChangeState (const MailState &mailState)
Changes the internal state. More...

void | SendNextRecipient ()
Is called by the SendMailFromState, if the SMTP server has acknowledged. More...

void | OnRecipientError ()
Is called by RcptListState if the SMTP server denied the current recipient. More...

void | OnRecipientSuccess ()
Is called by RcptListState if the SMTP server accepts the current recipient. More...

void | OnDataSuccess ()
Is called by DataState if the data was sent successfully. More...

void | SendFrom ()
Is called by HeloState to indicate that the from command can be sent. More...

void | SendData ()
Is called by StartDataState to indicate that the DATA command can be sent. More...

Detailed Description

Implementation of the sendmail class for SMTP email sending.

Definition at line 55 of file smtp.h.

Member Function Documentation

void wxSMTP::ChangeState ( const MailState & mailState )

Changes the internal state.

Parameters:
pMailState The new state.
See also:
MailState.

Definition at line 67 of file smtp.cpp.

Referenced by InitialState::onConnect(), StartDataState::onResponse(), SendMailFromState::onResponse(), HeloState::onResponse(), ConnectedState::onResponse(), and SendNextRecipient().

void wxSMTP::EvaluateLine ( const wxString & line ) [virtual]

Is called for every line input.

Parameters:
line The server response.

Reimplemented from wxCmdlineProtocol.

Definition at line 35 of file smtp.cpp.

References MailState::onResponse().

void wxSMTP::OnConnect ( wxSocketEvent & event ) [virtual]

Is called if successfully connected to the server.

Parameters:
event The wxSOCKET_CONNECTION event.

Reimplemented from wxCmdlineProtocol.

Definition at line 46 of file smtp.cpp.

References MailState::onConnect().

void wxSMTP::OnDataSuccess ( )

Is called by DataState if the data was sent successfully.

Definition at line 93 of file smtp.cpp.

References wxSMTPListener::OnDataSent().

Referenced by DataState::onResponse().

void wxSMTP::OnRecipientError ( )

Is called by RcptListState if the SMTP server denied the current recipient.

Definition at line 83 of file smtp.cpp.

References wxSMTPListener::OnRecipientAdded().

Referenced by RcptListState::onResponse().

void wxSMTP::OnRecipientSuccess ( )

Is called by RcptListState if the SMTP server accepts the current recipient.

Definition at line 88 of file smtp.cpp.

References wxSMTPListener::OnRecipientAdded().

Referenced by RcptListState::onResponse().

void wxSMTP::Send ( wxEmailMessage * pMessage )

Called by Sendmail::Send().

See also:
Sendmail::Send()

Definition at line 51 of file smtp.cpp.

References wxRecipientsIterator::GetNext(), wxEmailMessage::GetRecipientsIterator(), and wxRecipientsIterator::HasNext().

Referenced by SendDialog::SendDialog().

void wxSMTP::SendData ( )

Is called by StartDataState to indicate that the DATA command can be sent.

Definition at line 103 of file smtp.cpp.

References wxEmailMessage::Encode().

Referenced by StartDataState::onResponse().

void wxSMTP::SendFrom ( )

Is called by HeloState to indicate that the from command can be sent.

Definition at line 98 of file smtp.cpp.

References wxEmailMessage::GetFrom(), and wxCmdlineProtocol::Write().

Referenced by HeloState::onResponse().

void wxSMTP::SendNextRecipient ( )

Is called by the SendMailFromState, if the SMTP server has acknowledged.

This method sends then the next recipient, until all recipients have been sent. Then the StartDataState will be set.

Definition at line 72 of file smtp.cpp.

References ChangeState(), and wxCmdlineProtocol::Write().

Referenced by RcptListState::onResponse(), and SendMailFromState::onResponse().


wxSMTPListener Class Reference

Public available interface for classes who wants to be notified asynchronly about SMTP events. More...

#include <smtp.h>

Inheritance diagram for wxSMTPListener::

SendDialog List of all members.

Public Methods

virtual void | OnSocketError (int errorCode)
Will be called on errors. More...

virtual void | OnRecipientAdded (const wxString &address, int errorCode)
Will be called if the SMTP server has acknowledged the RCPT command, which is the case, if a recipient was added. More...

virtual void | OnDataSent (int errorCode)
Will be called if the SMTP server has acknowledged the DATA command, which is the case, if the email text was sent. More...

Detailed Description

Public available interface for classes who wants to be notified asynchronly about SMTP events.

Such classes can use this class as a base class and implement the methods of this class for receiving and evaluating some events.

See also:
For an example see WinoDialog.

Definition at line 23 of file smtp.h.

Member Function Documentation

virtual void wxSMTPListener::OnDataSent ( int errorCode ) [inline, virtual]

Will be called if the SMTP server has acknowledged the DATA command, which is the case, if the email text was sent.

TODO: Currently this is only sent, if the email was successfully sent.

Parameters:
address | The recipient who was added.
errorCode | 1, if successfully added, 0 otherwise. TODO: perhaps a error enumeration type would be better.

Reimplemented in SendDialog.

Definition at line 47 of file smtp.h.

Referenced by wxSMTP::OnDataSuccess().

virtual void wxSMTPListener::OnRecipientAdded | ( | const wxString & | address,
 |  | int | errorCode
 | ) | [inline, virtual]

Will be called if the SMTP server has acknowledged the RCPT command, which is the case, if a recipient was added.

Parameters:
address | The recipient who was added.
errorCode | 1, if successfully added, 0 otherwise. TODO: perhaps a error enumeration type would be better.

Reimplemented in SendDialog.

Definition at line 38 of file smtp.h.

Referenced by wxSMTP::OnRecipientError(), and wxSMTP::OnRecipientSuccess().

virtual void wxSMTPListener::OnSocketError ( int errorCode ) [inline, virtual]

Will be called on errors.

Not implemented.

Parameters:
errorCode TODO: What type of error code should we use?

Reimplemented in SendDialog.

Definition at line 30 of file smtp.h.


Hierarchical Index

Wino Class Hierarchy

This inheritance list is sorted roughly, but not completely, alphabetically:
  • MailState
    • ConnectedState
    • DataState
    • HeloState
    • InitialState
    • RcptListState
    • SendMailFromState
    • StartDataState
  • WinoApp
  • WinoDialog
  • wxBase64
  • wxCmdlineProtocol
    • wxSMTP
  • wxEmailMessage
  • wxMimePart
  • wxRecipientsIterator
  • wxSMTPListener
    • SendDialog


Compound Member Index

Wino Compound Members

Here is a list of all documented class members with links to the classes they belong to:
  • AddBcc() : wxEmailMessage
  • AddCc() : wxEmailMessage
  • AddFile() : wxEmailMessage
  • AddRecipient() : wxEmailMessage
  • AddTo() : wxEmailMessage
  • ChangeState() : wxSMTP
  • Decode() : wxBase64
  • Encode() : wxMimePart, wxEmailMessage, wxBase64
  • EvaluateLine() : wxSMTP, wxCmdlineProtocol
  • GetFrom() : wxEmailMessage
  • GetNext() : wxRecipientsIterator
  • GetRecipientsIterator() : wxEmailMessage
  • HasNext() : wxRecipientsIterator
  • OnAddressAddButton() : WinoDialog
  • OnAddressRemoveButton() : WinoDialog
  • onConnect() : InitialState
  • OnConnect() : wxSMTP, wxCmdlineProtocol
  • OnDataSent() : SendDialog, wxSMTPListener
  • OnDataSuccess() : wxSMTP
  • OnFileAddButton() : WinoDialog
  • OnFileRemoveButton() : WinoDialog
  • OnInit() : WinoApp
  • OnInput() : wxCmdlineProtocol
  • OnRecipientAdded() : SendDialog, wxSMTPListener
  • OnRecipientError() : wxSMTP
  • OnRecipientSuccess() : wxSMTP
  • onResponse() : DataState, StartDataState, RcptListState, SendMailFromState, HeloState, ConnectedState
  • OnSendButton() : WinoDialog
  • OnSocketError() : SendDialog, wxSMTPListener
  • OnSocketEvent() : wxCmdlineProtocol
  • Send() : wxSMTP
  • SendData() : wxSMTP
  • SendDialog() : SendDialog
  • SendFrom() : wxSMTP
  • SendNextRecipient() : wxSMTP
  • SetHost() : wxCmdlineProtocol
  • WinoDialog() : WinoDialog
  • Write() : wxCmdlineProtocol
  • wxEmailMessage() : wxEmailMessage
  • wxMimePart() : wxMimePart
  • wxRecipientsIterator() : wxRecipientsIterator


base64.cpp Source File

base64.cpp

00001 //*********************************************************************
00002 //* Base64 - a simple base64 encoder and decoder.
00003 //*
00004 //*     Copyright (c) 1999, Bob Withers - bwit@pobox.com
00005 //*
00006 //* This code may be freely used for any purpose, either personal
00007 //* or commercial, provided the authors copyright notice remains
00008 //* intact.
00009 //*********************************************************************
00010 //
00011 // converted to wxWindows by Frank Buß
00012 //
00013
00014 #include "Base64.h"
00015
00016 const wxChar fillchar = '=';
00017
00018                         // 00000000001111111111222222
00019                         // 01234567890123456789012345
00020 static wxString     cvt = _T("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
00021
00022                         // 22223333333333444444444455
00023                         // 67890123456789012345678901
00024                           "abcdefghijklmnopqrstuvwxyz"
00025
00026                         // 555555556666
00027                         // 234567890123
00028                           "0123456789+/");
00029
00030 wxString wxBase64::Encode(const wxUint8* pData, size_t len)
00031 {
00032     size_t c;
00033     wxString ret;
00034     ret.Alloc(len * 4 / 3 + len * 2 / 50);
00035     size_t resultLen = 0;
00036     wxString cr("\x00d\x00a");
00037
00038     for (size_t i = 0; i < len; ++i)
00039     {
00040         c = (pData[i] >> 2) & 0x3f;
00041         ret.Append(cvt[c], 1);
00042         if (++resultLen == 72) { ret += cr; resultLen = 0; }
00043         c = (pData[i] << 4) & 0x3f;
00044         if (++i < len)
00045             c |= (pData[i] >> 4) & 0x0f;
00046
00047         ret.Append(cvt[c], 1);
00048         if (++resultLen == 72) { ret += cr; resultLen = 0; }
00049         if (i < len)
00050         {
00051             c = (pData[i] << 2) & 0x3f;
00052             if (++i < len)
00053                 c |= (pData[i] >> 6) & 0x03;
00054
00055             ret.Append(cvt[c], 1);
00056         }
00057         else
00058         {
00059             ++i;
00060             ret.Append(fillchar, 1);
00061         }
00062         if (++resultLen == 72) { ret += cr; resultLen = 0; }
00063
00064         if (i < len)
00065         {
00066             c = pData[i] & 0x3f;
00067             ret.Append(cvt[c], 1);
00068         }
00069         else
00070         {
00071             ret.Append(fillchar, 1);
00072         }
00073         if (++resultLen == 72) { ret += cr; resultLen = 0; }
00074     }
00075
00076     return ret;
00077 }
00078
00079 wxString wxBase64::Decode(const wxString& data)
00080 {
00081     int c;
00082     int c1;
00083     size_t len = data.Length();
00084     wxString ret;
00085     ret.Alloc(data.Length() * 3 / 4);
00086
00087     for (size_t i = 0; i < len; ++i)
00088     {
00089         // TODO: check all Find results for -1 as result of wrong input data for release build
00090         c = cvt.Find(data[i]);
00091         wxASSERT_MSG(c >= 0, _T("invalid base64 input"));
00092         ++i;
00093         c1 = cvt.Find(data[i]);
00094         wxASSERT_MSG(c1 >= 0, _T("invalid base64 input"));
00095         c = (c << 2) | ((c1 >> 4) & 0x3);
00096         ret.Append(c, 1);
00097         if (++i < len)
00098         {
00099             c = data[i];
00100             if (fillchar == c)
00101                 break;
00102
00103             c = cvt.Find(c);
00104             wxASSERT_MSG(c >= 0, _T("invalid base64 input"));
00105             c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
00106             ret.Append(c1, 1);
00107         }
00108
00109         if (++i < len)
00110         {
00111             c1 = data[i];
00112             if (fillchar == c1)
00113                 break;
00114
00115             c1 = cvt.Find(c1);
00116             wxASSERT_MSG(c1 >= 0, _T("invalid base64 input"));
00117             c = ((c << 6) & 0xc0) | c1;
00118             ret.Append(c, 1);
00119         }
00120     }
00121
00122     return ret;
00123 }


base64.h Source File

base64.h

00001 //*********************************************************************
00002 //* C_Base64 - a simple base64 encoder and decoder.
00003 //*
00004 //*     Copyright (c) 1999, Bob Withers - bwit@pobox.com
00005 //*
00006 //* This code may be freely used for any purpose, either personal
00007 //* or commercial, provided the authors copyright notice remains
00008 //* intact.
00009 //*********************************************************************
00010 //
00011 // converted to wxWindows by Frank Buß
00012 //
00013
00014 #ifndef BASE64_H
00015 #define BASE64_H
00016
00017 #include <wx/wx.h>
00018
00022 class wxBase64
00023 {
00024 public:
00031     static wxString Encode(const wxUint8* pData, size_t length);
00032
00038     static wxString Decode(const wxString& data);
00039 };
00040
00041 #endif


Member List

ConnectedState Member List

This is the complete list of members for ConnectedState, including all inherited members.
onResponse(wxSMTP &context, int smtpCode) const ConnectedState [virtual]


Member List

DataState Member List

This is the complete list of members for DataState, including all inherited members.
onResponse(wxSMTP &context, int smtpCode) const DataState [virtual]


Member List

HeloState Member List

This is the complete list of members for HeloState, including all inherited members.
onResponse(wxSMTP &context, int smtpCode) const HeloState [virtual]


Member List

InitialState Member List

This is the complete list of members for InitialState, including all inherited members.
onConnect(wxSMTP &context, wxSocketEvent &event) const InitialState [virtual]


Member List

MailState Member List

This is the complete list of members for MailState, including all inherited members.


Member List

RcptListState Member List

This is the complete list of members for RcptListState, including all inherited members.
onResponse(wxSMTP &context, int smtpCode) const RcptListState [virtual]


Member List

SendDialog Member List

This is the complete list of members for SendDialog, including all inherited members.
OnDataSent(int errorCode) | SendDialog | [virtual]
OnRecipientAdded(const wxString &address, int errorCode) | SendDialog | [virtual]
OnSocketError(int errorCode) | SendDialog | [virtual]
SendDialog(WinoDialog &winoDialog) | SendDialog |


Member List

SendMailFromState Member List

This is the complete list of members for SendMailFromState, including all inherited members.
onResponse(wxSMTP &context, int smtpCode) const SendMailFromState [virtual]


Member List

StartDataState Member List

This is the complete list of members for StartDataState, including all inherited members.
onResponse(wxSMTP &context, int smtpCode) const StartDataState [virtual]


Member List

WinoApp Member List

This is the complete list of members for WinoApp, including all inherited members.
OnInit() WinoApp


Member List

WinoDialog Member List

This is the complete list of members for WinoDialog, including all inherited members.
OnAddressAddButton(wxCommandEvent &event) | WinoDialog
OnAddressRemoveButton(wxCommandEvent &event) | WinoDialog
OnFileAddButton(wxCommandEvent &event) | WinoDialog
OnFileRemoveButton(wxCommandEvent &event) | WinoDialog
OnSendButton(wxCommandEvent &event) | WinoDialog
WinoDialog(wxWindow *parent) | WinoDialog


Member List

wxBase64 Member List

This is the complete list of members for wxBase64, including all inherited members.
Decode(const wxString &data) | wxBase64 | [static]
Encode(const wxUint8 *pData, size_t length) | wxBase64 | [static]


Member List

wxCmdlineProtocol Member List

This is the complete list of members for wxCmdlineProtocol, including all inherited members.
EvaluateLine(const wxString &line)=0 | wxCmdlineProtocol | [pure virtual]
OnConnect(wxSocketEvent &event)=0 | wxCmdlineProtocol | [pure virtual]
OnInput(wxSocketEvent &event) | wxCmdlineProtocol |
OnSocketEvent(wxSocketEvent &event) | wxCmdlineProtocol |
SetHost(const wxString &host, const wxString &user="", const wxString &password="") | wxCmdlineProtocol |
Write(const wxString &msg) | wxCmdlineProtocol |


Member List

wxEmailMessage Member List

This is the complete list of members for wxEmailMessage, including all inherited members.
AddBcc(const wxString &address) | wxEmailMessage
AddCc(const wxString &address) | wxEmailMessage
AddFile(const wxFileName &fileName, const wxString mimeMainType="", const wxString mimeSubType="") | wxEmailMessage
AddRecipient(const wxString &address) | wxEmailMessage
AddTo(const wxString &address) | wxEmailMessage
Encode(wxOutputStream &out) | wxEmailMessage
GetFrom() | wxEmailMessage
GetRecipientsIterator() | wxEmailMessage
wxEmailMessage(const wxString &subject, const wxString &text, const wxString &from) | wxEmailMessage


Member List

wxMimePart Member List

This is the complete list of members for wxMimePart, including all inherited members.
Encode(wxOutputStream &out) | wxMimePart
wxMimePart(const wxFileName &fileName) | wxMimePart


Member List

wxRecipientsIterator Member List

This is the complete list of members for wxRecipientsIterator, including all inherited members.
GetNext() | wxRecipientsIterator
HasNext() | wxRecipientsIterator
wxRecipientsIterator(const wxEmailMessage &emailMessage) | wxRecipientsIterator


Member List

wxSMTP Member List

This is the complete list of members for wxSMTP, including all inherited members.
ChangeState(const MailState &mailState) | wxSMTP |
EvaluateLine(const wxString &line) | wxSMTP | [virtual]
OnConnect(wxSocketEvent &event) | wxSMTP | [virtual]
OnDataSuccess() | wxSMTP |
OnInput(wxSocketEvent &event) | wxCmdlineProtocol |
OnRecipientError() | wxSMTP |
OnRecipientSuccess() | wxSMTP |
OnSocketEvent(wxSocketEvent &event) | wxCmdlineProtocol |
Send(wxEmailMessage *pMessage) | wxSMTP |
SendData() | wxSMTP |
SendFrom() | wxSMTP |
SendNextRecipient() | wxSMTP |
SetHost(const wxString &host, const wxString &user="", const wxString &password="") | wxCmdlineProtocol |
Write(const wxString &msg) | wxCmdlineProtocol |


Member List

wxSMTPListener Member List

This is the complete list of members for wxSMTPListener, including all inherited members.
OnDataSent(int errorCode) | wxSMTPListener | [inline, virtual]
OnRecipientAdded(const wxString &address, int errorCode) | wxSMTPListener | [inline, virtual]
OnSocketError(int errorCode) | wxSMTPListener | [inline, virtual]


cmdprot.cpp Source File

cmdprot.cpp

00001 /*
00002  * Purpose: private wxWindows mail transport implementation
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006
00007 #include <wx/sckstrm.h>
00008
00009 #include "cmdprot.h"
00010
00011 #define SOCKET_ID 1
00012
00013 class wxCmdlineProtocolSocketEventHandler : public wxEvtHandler
00014 {
00015 public:
00016     wxCmdlineProtocolSocketEventHandler(wxCmdlineProtocol& callback) : m_callback(callback)
00017     {
00018     }
00019
00020     void OnSocketEvent(wxSocketEvent& event)
00021     {
00022         m_callback.OnSocketEvent(event);
00023     }
00024
00025 private:
00026     wxCmdlineProtocol& m_callback;
00027
00028     DECLARE_EVENT_TABLE()
00029 };
00030
00031 BEGIN_EVENT_TABLE(wxCmdlineProtocolSocketEventHandler, wxEvtHandler)
00032   EVT_SOCKET(SOCKET_ID, wxCmdlineProtocolSocketEventHandler::OnSocketEvent)
00033 END_EVENT_TABLE()
00034
00035
00036 wxCmdlineProtocol::wxCmdlineProtocol()
00037 {
00038     m_pCmdlineProtocolSocketEventHandler = new wxCmdlineProtocolSocketEventHandler(*this);
00039 }
00040
00041 wxCmdlineProtocol::~wxCmdlineProtocol()
00042 {
00043     delete m_pCmdlineProtocolSocketEventHandler;
00044 }
00045
00046 void wxCmdlineProtocol::SetHost(const wxString& host, const wxString& user, const wxString& password)
00047 {
00048     m_host = host;
00049     m_user = user;
00050     m_password = password;
00051 }
00052
00053 void wxCmdlineProtocol::Connect()
00054 {
00055     if (IsConnected()) Close();
00056     SetTimeout(60);
00057     SetEventHandler(*m_pCmdlineProtocolSocketEventHandler, SOCKET_ID);
00058     SetNotify(wxSOCKET_CONNECTION_FLAG | wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
00059     Notify(TRUE);
00060
00061     // connect
00062     wxIPV4address addr;
00063     addr.Hostname(m_host);
00064     addr.Service(25);  // TODO: perhaps the port should not be hardcoded?
00065     wxSocketClient::Connect(addr, FALSE);
00066 }
00067
00068 void wxCmdlineProtocol::OnInput(wxSocketEvent& event)
00069 {
00070     // TODO: implementing response timeout somewhere
00071
00072     // get data
00073     const int bufsize = 256;
00074     char buf[bufsize];
00075     Read(buf, bufsize);
00076     m_inputLine += wxString(buf, LastCount());
00077
00078     // search for a newline
00079     while (true) {
00080         size_t pos = 0;
00081         while (pos < m_inputLine.Length() - 1) {
00082             if (m_inputLine[pos] == 13) {
00083                 if (m_inputLine[pos + 1] == 10)
00084                 {
00085                     // line found, evaluate
00086                     EvaluateLine(m_inputLine.Mid(0, pos));
00087
00088                     // adjust buffer
00089                     m_inputLine = m_inputLine.Mid(pos + 2);
00090                     return;
00091                 }
00092                 break;
00093             }
00094             pos++;
00095         }
00096     }
00097 }
00098
00099 void wxCmdlineProtocol::OnSocketEvent(wxSocketEvent& event)
00100 {
00101     wxString s = _("OnSocketEvent: ");
00102
00103     switch(event.GetSocketEvent())
00104     {
00105         case wxSOCKET_INPUT:
00106             OnInput(event);
00107             break;
00108         case wxSOCKET_LOST:
00109             // TODO: error handling
00110             break;
00111         case wxSOCKET_CONNECTION:
00112             OnConnect(event);
00113             break;
00114     }
00115 }
00116
00117 void wxCmdlineProtocol::Write(const wxString& msg)
00118 {
00119     wxSocketClient::Write(msg, msg.Length());
00120 }
00121


cmdprot.h Source File

cmdprot.h

00001 /*
00002  * Purpose: base class for all command line oriented internet protocols
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006
00007 #ifndef CMDPROT_H
00008 #define CMDPROT_H
00009
00010 #include <wx/wx.h>
00011
00012 #include "email.h"
00013
00014
00015 class wxCmdlineProtocolSocketEventHandler;
00016
00020 class wxCmdlineProtocol : public wxSocketClient
00021 {
00022 public:
00023     wxCmdlineProtocol();
00024
00025     ~wxCmdlineProtocol();
00026
00034     void SetHost(const wxString& host, const wxString& user = "", const wxString& password = "");
00035
00036     void Connect();
00037
00038     // handling for wxSOCKET_INPUT
00039
00044     virtual void EvaluateLine(const wxString& line) = 0;
00045
00050     virtual void OnConnect(wxSocketEvent& event) = 0;
00051
00057     void OnInput(wxSocketEvent& event);
00058
00062     void OnSocketEvent(wxSocketEvent& event);
00063
00068     void Write(const wxString& msg);
00069
00070 private:
00071     wxCmdlineProtocolSocketEventHandler* m_pCmdlineProtocolSocketEventHandler;
00072     bool m_bConnected;
00073     wxString m_inputLine;
00074     wxString m_host;
00075     wxString m_user;
00076     wxString m_password;
00077 };
00078
00079 #endif


email.cpp Source File

email.cpp

00001 /*
00002  * Purpose: wxWindows email implementation
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006
00007 #include "email.h"
00008 #include "Base64.h"
00009
00010
00011 wxEmailMessage::wxEmailMessage(const wxString& subject, const wxString& text, const wxString& from) :
00012     m_subject(subject),
00013     m_text(text),
00014     m_from(from)
00015 {
00016 }
00017
00018 const wxString& wxEmailMessage::GetFrom()
00019 {
00020     return m_from;
00021 }
00022
00023 void wxEmailMessage::AddRecipient(const wxString& address)
00024 {
00025     m_rcptArray.Add(address);
00026 }
00027
00028 void wxEmailMessage::AddTo(const wxString& address)
00029 {
00030     m_toArray.Add(address);
00031 }
00032
00033 void wxEmailMessage::AddCc(const wxString& address)
00034 {
00035     m_ccArray.Add(address);
00036 }
00037
00038 void wxEmailMessage::AddBcc(const wxString& address)
00039 {
00040     m_bccArray.Add(address);
00041 }
00042
00043 void wxEmailMessage::AddFile(const wxFileName& fileName, const wxString mimeMainType, const wxString mimeSubType)
00044 {
00045     // add new entry
00046     m_mimeParts.Add(wxMimePart(fileName));
00047 }
00048
00049 wxRecipientsIterator wxEmailMessage::GetRecipientsIterator()
00050 {
00051     return wxRecipientsIterator(*this);
00052 }
00053
00054 void wxEmailMessage::Encode(wxOutputStream& out)
00055 {
00056     // TODO: use only MIME if neccessary
00057     wxString header;
00058     wxString cr("\x00d\x00a");
00059     // TODO: calculate a more random boundary
00060     wxString boundary("---_0123456789-boundary-9876543210_---");
00061     wxString boundarySep = "--" + boundary + cr;
00062     header << "From: " << m_from << cr;
00063     // TODO: add to, cc and bcc in the right format with line breaking, if too long
00064     header << "Bcc:" << cr
00065            << "Subject: " << m_subject << cr  // TODO: add Date:
00066            << "MIME-Version: 1.0" << cr
00067            << "Content-Type: multipart/mixed; boundary=\"" << boundary << "\"" << cr
00068            << cr
00069            << cr
00070            << "This is a multi-part message in MIME format" << cr
00071            << cr
00072            << boundarySep
00073            << "Content-Type: text/plain; charset=iso-8859-1" << cr
00074            << "Content-Transfer-Encoding: 8bit" << cr
00075            << cr
00076            << m_text << cr;  // TODO: is it possible in MIME message to have a single '.' on a line?
00077     out.Write((const char*) header, header.Length());
00078     for (size_t i = 0; i < m_mimeParts.GetCount(); i++) {
00079         out.Write((const char*) boundarySep, boundarySep.Length());
00080         m_mimeParts[i].Encode(out);
00081     }
00082     wxString footer = "--" + boundary + "--" + cr + "." + cr;  // TODO: perhaps moving the '.\r\n' sequence to another place
00083     out.Write((const char*) footer, footer.Length());
00084 }
00085
00086 wxRecipientsIterator::wxRecipientsIterator(const wxEmailMessage& emailMessage) :
00087     m_emailMessage(emailMessage)
00088 {
00089     m_rcptCount = 0;
00090     m_toCount = 0;
00091     m_ccCount = 0;
00092     m_bccCount = 0;
00093 }
00094
00095 bool wxRecipientsIterator::HasNext()
00096 {
00097     if (m_rcptCount < m_emailMessage.m_rcptArray.GetCount() ||
00098         m_toCount < m_emailMessage.m_toArray.GetCount() ||
00099         m_ccCount < m_emailMessage.m_ccArray.GetCount() ||
00100         m_bccCount < m_emailMessage.m_bccArray.GetCount())
00101     {
00102         return true;
00103     }
00104     return false;
00105 }
00106
00107 wxString wxRecipientsIterator::GetNext()
00108 {
00109     if (m_rcptCount < m_emailMessage.m_rcptArray.GetCount()) {
00110         return m_emailMessage.m_rcptArray[m_rcptCount++];
00111     } else if (m_toCount < m_emailMessage.m_toArray.GetCount()) {
00112         return m_emailMessage.m_toArray[m_toCount++];
00113     } else if (m_ccCount < m_emailMessage.m_ccArray.GetCount()) {
00114         return m_emailMessage.m_ccArray[m_ccCount++];
00115     } else if (m_bccCount < m_emailMessage.m_bccArray.GetCount()) {
00116         return m_emailMessage.m_bccArray[m_bccCount++];
00117     }
00118     return "";
00119 }
00120


email.h Source File

email.h

00001 /*
00002  * Purpose: wxWindows email implementation
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006
00007 #ifndef EMAIL_H
00008 #define EMAIL_H
00009
00010 #include <wx/wx.h>
00011 #include <wx/filename.h>
00012 #include <wx/wfstream.h>
00013
00014 #include "mime.h"
00015
00016 // forward declaration
00017 class wxRecipientsIterator;
00018
00022 class wxEmailMessage
00023 {
00024 public:
00031     wxEmailMessage(const wxString& subject, const wxString& text, const wxString& from);
00032
00037     const wxString& GetFrom();
00038
00046     void AddRecipient(const wxString& address);
00047
00052     void AddTo(const wxString& address);
00053
00058     void AddCc(const wxString& address);
00059
00064     void AddBcc(const wxString& address);
00065
00066     // loads the file in memory and adds it to the message.
00067
00075     void AddFile(const wxFileName& fileName, const wxString mimeMainType = "", const wxString mimeSubType = "");
00076
00082     wxRecipientsIterator GetRecipientsIterator();
00083
00088     //
00089     void Encode(wxOutputStream& out);
00090
00091 private:
00092     wxString m_subject;
00093     wxString m_text;
00094     wxString m_from;
00095     wxArrayString m_rcptArray;
00096     wxArrayString m_toArray;
00097     wxArrayString m_ccArray;
00098     wxArrayString m_bccArray;
00099     wxArrayMimePart m_mimeParts;
00100
00101     friend class wxRecipientsIterator;
00102 };
00103
00104
00108 class wxRecipientsIterator
00109 {
00110 public:
00116     wxRecipientsIterator(const wxEmailMessage& emailMessage);
00117
00123     bool HasNext();
00124
00129     wxString GetNext();
00130
00131 private:
00132     const wxEmailMessage& m_emailMessage;
00133     size_t m_rcptCount;
00134     size_t m_toCount;
00135     size_t m_ccCount;
00136     size_t m_bccCount;
00137
00138 };
00139
00140
00141 #endif


mime.cpp Source File

mime.cpp

00001 /*
00002  * Purpose: wxWindows mime implementation
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006
00007 #include "email.h"
00008 #include "Base64.h"
00009
00010
00011 #include "wx/arrimpl.cpp"
00012 WX_DEFINE_OBJARRAY(wxArrayMimePart);
00013
00014 struct wxMimeTypeMapping
00015 {
00016     const wxChar* extension;
00017     const wxChar* mainType;
00018     const wxChar* subType;
00019 };
00020
00021 // extension, main type, sub type
00022 // TODO: must be merged / integrated / substituted with wxFileType
00023 static const wxMimeTypeMapping g_mimeTypeMappings[] =
00024 {
00025     { _T("txt"), _T("text"), _T("plain") },
00026     { _T("htm"), _T("text"), _T("html") },
00027     { _T("html"), _T("text"), _T("html") },
00028     { _T("gif"), _T("image"), _T("gif") },
00029     { _T("png"), _T("image"), _T("png") },
00030     { _T("jpg"), _T("image"), _T("jpeg") },
00031     { _T("jpeg"), _T("image"), _T("jpeg") },
00032     { _T("pdf"), _T("application"), _T("pdf") },
00033     { _T("doc"), _T("application"), _T("msword") }
00034 };
00035
00036 wxMimePart::wxMimePart(const wxFileName& fileName) :
00037     m_fileName(fileName)
00038 {
00039     // setup default encoding
00040     m_mainType = _T("application");
00041     m_subType = _T("octet-stream");
00042
00043     // try to determine encoding by filename extension
00044     wxString ext = fileName.GetExt().Lower();
00045     for (int i = 0; i < sizeof(g_mimeTypeMappings) / sizeof(wxMimeTypeMapping); i++) {
00046         if (g_mimeTypeMappings[i].extension == ext) {
00047             m_mainType = g_mimeTypeMappings[i].mainType;
00048             m_subType = g_mimeTypeMappings[i].subType;
00049             break;
00050         }
00051     }
00052 }
00053
00054 void wxMimePart::Encode(wxOutputStream& out)
00055 {
00056     // TODO: error handling for every return
00057     // TODO: encoding it on-the-fly without loading it all in memory
00058     wxFileInputStream in(m_fileName.GetFullPath());
00059     if (!in.Ok()) return;
00060
00061     // determine file length
00062     // TODO: perhaps this can be added to wxFileName for size()
00063     in.SeekI(0, wxFromEnd);
00064     size_t len = (size_t) in.TellI();
00065     in.SeekI(0);
00066     // that's possible for windows (#include <sys/types.h> and #include <sys/stat.h>):
00067     // struct _stat lenStat;
00068     // if (_stat(filename, &lenStat) == -1) return error;
00069     // size_t len = (size_t) lenStat.st_size;
00070
00071     if (len == 0) return;
00072
00073     // read file
00074     wxUint8* pData = new wxUint8[len];
00075     if (!pData) {
00076         wxASSERT_MSG(pData != NULL, _T("out of memory"));
00077         return;
00078     }
00079     in.Read(pData, len);
00080
00081     // write encoded mime part to stream
00082     wxString cr("\x00d\x00a");
00083     wxString result;
00084     result << "Content-Type: " << m_mainType << "/" << m_subType << "; name=\"" << m_fileName.GetFullName() + "\"" + cr
00085            << "Content-Transfer-Encoding: base64" << cr
00086            << "Content-Disposition: attachment; filename=\"" << m_fileName.GetName() << "\"" << cr
00087            << cr
00088            << wxBase64::Encode(pData, len) << cr;
00089     out.Write((const char*) result, result.Length());
00090 }
00091


mime.h Source File

mime.h

00001 /*
00002  * Purpose: wxWindows mime implementation
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006
00007 #ifndef MIME_H
00008 #define MIME_H
00009
00010 #include <wx/wx.h>
00011 #include <wx/filename.h>
00012 #include <wx/wfstream.h>
00013
00017 class wxMimePart
00018 {
00019 public:
00026     wxMimePart(const wxFileName& fileName);
00027
00032     void Encode(wxOutputStream& out);
00033
00034 private:
00035     wxFileName m_fileName;
00036     wxString m_mainType;
00037     wxString m_subType;
00038 };
00039
00040 WX_DECLARE_OBJARRAY(wxMimePart, wxArrayMimePart);
00041
00042 #endif


smtp.cpp Source File

smtp.cpp

00001 /*
00002  * Purpose: private wxWindows mail transport implementation
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006
00007 #include <wx/sckstrm.h>
00008
00009 #include "smtp.h"
00010 #include "states.h"
00011
00012 #define SOCKET_ID 1
00013
00017 wxSMTPListener g_nullListener;
00018
00019
00020 wxSMTP::wxSMTP(wxSMTPListener* pListener) :
00021     m_pMailState(&g_initialState)
00022 {
00023     if (pListener) {
00024         m_pListener = pListener;
00025     } else {
00026         m_pListener = &g_nullListener;
00027     }
00028     m_pMessage = NULL;
00029 }
00030
00031 wxSMTP::~wxSMTP()
00032 {
00033 }
00034
00035 void wxSMTP::EvaluateLine(const wxString& line)
00036 {
00037     // TODO: implementing response timeout somewhere
00038     // TODO: implementing multiline response
00039
00040     // get command
00041     unsigned long cmd = 0;
00042     line.ToULong(&cmd);
00043     m_pMailState->onResponse(*this, cmd);
00044 }
00045
00046 void wxSMTP::OnConnect(wxSocketEvent& event)
00047 {
00048     m_pMailState->onConnect(*this, event);
00049 }
00050
00051 void wxSMTP::Send(wxEmailMessage* pMessage)
00052 {
00053     // no message means nothing to do
00054     if (!pMessage) return;
00055     m_pMessage = pMessage;
00056
00057     // add recipients from message
00058     wxRecipientsIterator ri = m_pMessage->GetRecipientsIterator();
00059     while (ri.HasNext()) m_recipients.Add(ri.GetNext());
00060     m_count = 0;
00061
00062     // init new socket connection
00063     m_pMailState = &g_initialState;
00064     Connect();
00065 }
00066
00067 void wxSMTP::ChangeState(const MailState& mailState)
00068 {
00069     m_pMailState = &mailState;
00070 }
00071
00072 void wxSMTP::SendNextRecipient()
00073 {
00074     if (m_count < m_recipients.GetCount()) {
00075         m_currentRecipient = m_recipients[m_count++];
00076         Write("RCPT TO:<" + m_currentRecipient + ">\x00d\x00a");
00077     } else {
00078         ChangeState(g_startDataState);
00079         Write("DATA\x00d\x00a");
00080     }
00081 }
00082
00083 void wxSMTP::OnRecipientError()
00084 {
00085     m_pListener->OnRecipientAdded(m_currentRecipient, 0);
00086 }
00087
00088 void wxSMTP::OnRecipientSuccess()
00089 {
00090     m_pListener->OnRecipientAdded(m_currentRecipient, 1);
00091 }
00092
00093 void wxSMTP::OnDataSuccess()
00094 {
00095     m_pListener->OnDataSent(1);
00096 }
00097
00098 void wxSMTP::SendFrom()
00099 {
00100     Write("MAIL FROM:<" + m_pMessage->GetFrom() + ">\x00d\x00a");
00101 }
00102
00103 void wxSMTP::SendData()
00104 {
00105     wxSocketOutputStream out(*this);
00106 //  wxFileOutputStream out("mail.txt");
00107     m_pMessage->Encode(out);
00108 }
00109


smtp.h Source File

smtp.h

00001 /*
00002  * Purpose: private wxWindows mail transport implementation
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006
00007 #ifndef SMPT_H
00008 #define SMPT_H
00009
00010 #include <wx/wx.h>
00011 #include <wx/protocol/protocol.h>
00012
00013 #include "email.h"
00014 #include "cmdprot.h"
00015
00016
00023 class wxSMTPListener
00024 {
00025 public:
00030     virtual void OnSocketError(int errorCode) {};
00031
00038     virtual void OnRecipientAdded(const wxString& address, int errorCode) {};
00039
00047     virtual void OnDataSent(int errorCode) {};
00048 };
00049
00050 class MailState;
00051
00055 class wxSMTP : public wxCmdlineProtocol //, public wxEvtHandler
00056 {
00057 public:
00058     wxSMTP(wxSMTPListener* pListener = NULL);
00059
00060     ~wxSMTP();
00061
00066     void Send(wxEmailMessage* pMessage);
00067
00068     void EvaluateLine(const wxString& line);
00069     void OnConnect(wxSocketEvent& event);
00070
00071     // MailStateContext interface
00072
00078     void ChangeState(const MailState& mailState);
00079
00085     void SendNextRecipient();
00086
00090     void OnRecipientError();
00091
00095     void OnRecipientSuccess();
00096
00100     void OnDataSuccess();
00101
00105     void SendFrom();
00106
00110     void SendData();
00111
00112 private:
00113     const MailState* m_pMailState;
00114     wxSMTPListener* m_pListener;
00115     wxEmailMessage* m_pMessage;
00116
00117     // current recipient and counts
00118     size_t m_count;
00119     wxString m_currentRecipient;
00120
00121     // all recipients
00122     wxArrayString m_recipients;
00123 };
00124
00125 #endif


snddlg.cpp Source File

snddlg.cpp

00001 /*
00002  * Purpose: Sample application for demonstrating and testing the wxWindows email support
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006
00007 #include <wx/datstrm.h>
00008
00009 #include "snddlg.h"
00010 #include "wino.h"
00011
00012 static const wxUint32 g_admFileId = ('a' | ('d' << 8) | ('m' << 16));
00013 static const wxUint32 g_admFileVersion = 1;
00014
00015 // file format tags
00016 enum {
00017     admTagEnd = 0,
00018     admTagGrid = 2
00019 };
00020
00021 BEGIN_EVENT_TABLE(SendDialog, wxDialog)
00022 END_EVENT_TABLE()
00023
00024 size_t g_emailCount;
00025
00026 static bool checkEmail(wxString& email)
00027 {
00028     static bool validChars[256];
00029     static bool initialized = false;
00030     if (!initialized) {
00031         unsigned i;
00032         for (i = 0; i <= 255; i++) validChars[i] = false;
00033         for (i = 'a'; i <= 'z'; i++) validChars[i] = true;
00034         for (i = 'A'; i <= 'Z'; i++) validChars[i] = true;
00035         for (i = '0'; i <= '9'; i++) validChars[i] = true;
00036         validChars['@'] = true;
00037         validChars['.'] = true;
00038         validChars['_'] = true;
00039         validChars['-'] = true;
00040         validChars['~'] = true;
00041         initialized = true;
00042     }
00043
00044     // check for valid emails
00045     unsigned atcount = 0;
00046     unsigned atposition = 0;
00047     if (email.Length() < 3) return false;
00048     for (unsigned i = 0; i < email.Length(); i++) {
00049         wxChar c = email[i];
00050         if (!validChars[c]) return false;
00051         if (c == '@') {
00052             atcount++;
00053             atposition = i;
00054             if (atcount > 1) return false;
00055         }
00056     }
00057     if (atcount != 1) return false;
00058     if (atposition == 0 || atposition == email.Length() - 1) return false;
00059
00060     // valid
00061     return true;
00062 }
00063
00064 static void addEmails(wxEmailMessage* pMessage, wxFileName* pFilename)
00065 {
00066     // open file; TODO: file locking
00067     wxFileInputStream fileInStream(pFilename->GetFullPath());
00068     wxDataInputStream in(fileInStream);
00069
00070     // check if right file format and file is readable
00071     wxUint32 id = in.Read32();
00072     wxUint32 version = in.Read32();
00073     if (!in.IsOk() || id != g_admFileId || version > g_admFileVersion) {
00074         wxMessageDialog errorDialog(NULL, "Fehler beim Öffnen der Datei " + pFilename->GetFullPath() + ", diese Datei wird ignoriert.", "Wino", wxOK | wxICON_INFORMATION);
00075         errorDialog.ShowModal();
00076         return;
00077     }
00078
00079     // read file
00080     bool end = false;
00081     while (!end) {
00082         wxUint32 tag = in.Read32();
00083         wxUint32 size = in.Read32();
00084         switch (tag) {
00085             case admTagGrid:
00086                 {
00087                     // read number of cols and rows
00088                     size_t cols = in.Read32();
00089                     size_t rows = in.Read32();
00090
00091                     // read column labels and widths
00092                     bool found = false;
00093                     size_t emailIndex = 0;
00094                     size_t i;
00095                     for (i = 0; i < cols; i++) {
00096                         wxString colLabel = in.ReadString();
00097                         if (colLabel.CmpNoCase("email") == 0) {
00098                             found = true;
00099                             emailIndex = i;
00100                         }
00101                         in.Read32();
00102                     }
00103                     if (!found) {
00104                         wxString error;
00105                         error << "Die Datei " << pFilename->GetFullPath() << " enthält keine Tabellenspalte\n"
00106                             << "mit dem Namen 'eMail' und wird daher ignoriert.";
00107                         wxMessageDialog errorDialog(NULL, error, "Wino", wxOK | wxICON_INFORMATION);
00108                         errorDialog.ShowModal();
00109                         return;
00110                     }
00111
00112                     // read emails
00113                     for (i = 0; i < rows; i++) {
00114                         for (size_t j = 0; j < cols; j++) {
00115                             if (j == emailIndex) {
00116                                 wxString email = in.ReadString();
00117                                 if (checkEmail(email)) {
00118                                     pMessage->AddRecipient(email);
00119                                     g_emailCount++;
00120                                 }
00121                             } else {
00122                                 in.ReadString();
00123                             }
00124                         }
00125                     }
00126                     return;
00127                 }
00128                 break;
00129             case admTagEnd:
00130                 end = true;
00131                 break;
00132             default:
00133                 fileInStream.SeekI(size, wxFromCurrent);
00134         }
00135     }
00136 }
00137
00138 SendDialog::SendDialog(WinoDialog& winoDialog)
00139                : wxDialog(&winoDialog, -1,
00140                           _("Wino eMail Versand"),
00141                           wxDefaultPosition,
00142                           wxDefaultSize,
00143                           wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL)
00144 {
00145     wxString server = winoDialog.m_pServerTextCtrl->GetValue().Trim();
00146     wxString subject = winoDialog.m_pSubjectTextCtrl->GetValue().Trim();
00147     wxString text = winoDialog.m_pTextTextCtrl->GetValue().Trim();
00148     wxString from = winoDialog.m_pFromTextCtrl->GetValue().Trim();
00149     wxString to = winoDialog.m_pToTextCtrl->GetValue().Trim();
00150
00151     g_emailCount = 0;
00152     m_successCount = 0;
00153     wxBusyCursor wait;
00154
00155     // create transport class
00156     m_pSMTP = new wxSMTP(this);
00157     m_pSMTP->SetHost(server);
00158
00159     // create message class
00160     m_pMessage = new wxEmailMessage(subject, text, from);
00161
00162     // add 'to'-recipient to message
00163     m_pMessage->AddTo(to);
00164
00165     // add files to message
00166     int i;
00167     for (i = 0; i < winoDialog.m_pFilelist->GetCount(); i++) {
00168         wxFileName* pFilename = (wxFileName*) winoDialog.m_pFilelist->GetClientData(i);
00169         m_pMessage->AddFile(*pFilename);
00170     }
00171
00172     // add emails to message
00173     for (i = 0; i < winoDialog.m_pAddresslist->GetCount(); i++) {
00174         wxFileName* pFilename = (wxFileName*) winoDialog.m_pAddresslist->GetClientData(i);
00175         addEmails(m_pMessage, pFilename);
00176     }
00177
00178     // convert email count to string
00179     wxString emailCount;
00180     emailCount << g_emailCount;
00181
00182     // create dialog
00183     wxBoxSizer* pTopSizer = new wxBoxSizer(wxVERTICAL);
00184
00185     wxBoxSizer* pStatusSizer = new wxBoxSizer(wxHORIZONTAL);
00186     pStatusSizer->Add(new wxStaticText(this, -1, "Status:"), 1, wxALIGN_CENTER | wxLEFT | wxTOP, 10);
00187     m_pStatusText = new wxStaticText(this, -1, "eMail-Adressen werden gesendet...", wxDefaultPosition, wxSize(100, 10));
00188     pStatusSizer->Add(m_pStatusText, 3, wxLEFT | wxTOP | wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER | wxEXPAND, 10);
00189     pTopSizer->Add(pStatusSizer, 0, wxEXPAND);
00190
00191     wxBoxSizer* pEmailCountSizer = new wxBoxSizer(wxHORIZONTAL);
00192     pEmailCountSizer->Add(new wxStaticText(this, -1, "Anzahl gültiger eMail Adressen:"), 1, wxALIGN_CENTER | wxLEFT | wxTOP, 10);
00193     m_pEmailCountText = new wxStaticText(this, -1, emailCount, wxDefaultPosition, wxSize(100, 10));
00194     pEmailCountSizer->Add(m_pEmailCountText, 3, wxLEFT | wxTOP | wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER | wxEXPAND, 10);
00195     pTopSizer->Add(pEmailCountSizer, 0, wxEXPAND);
00196
00197     wxBoxSizer* pEmailSuccessSizer = new wxBoxSizer(wxHORIZONTAL);
00198     pEmailSuccessSizer->Add(new wxStaticText(this, -1, "Davon erfolgreich versendet:"), 1, wxALIGN_CENTER | wxLEFT | wxTOP, 10);
00199     m_pEmailSuccessText = new wxStaticText(this, -1, "0", wxDefaultPosition, wxSize(100, 10));
00200     pEmailSuccessSizer->Add(m_pEmailSuccessText, 3, wxLEFT | wxTOP | wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER | wxEXPAND, 10);
00201     pTopSizer->Add(pEmailSuccessSizer, 0, wxEXPAND);
00202
00203     wxStaticBoxSizer* pLogSizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, "Bericht"), wxVERTICAL);
00204     m_pLogTextCtrl = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxSize(500, 300), wxTE_MULTILINE | wxTE_READONLY);
00205     pLogSizer->Add(m_pLogTextCtrl, 0, wxEXPAND | wxALL, 10);
00206     pTopSizer->Add(pLogSizer, 0, wxEXPAND | wxALL, 10);
00207
00208     wxBoxSizer* pSendCloseSizer = new wxBoxSizer(wxHORIZONTAL);
00209     wxButton* pCloseButton = new wxButton(this, wxID_CANCEL, "Beenden");
00210     pCloseButton->SetDefault();
00211     pSendCloseSizer->Add(pCloseButton, 0, wxALL, 10);
00212     pTopSizer->Add(pSendCloseSizer, 0, wxALIGN_RIGHT);
00213
00214     SetAutoLayout(true);
00215     SetSizer(pTopSizer);
00216     pTopSizer->Fit(this);
00217     pTopSizer->SetSizeHints(this);
00218
00219     // show dialog
00220     Centre(wxBOTH | wxCENTRE_ON_SCREEN);
00221
00222     // start email sending
00223     m_pSMTP->Send(m_pMessage);
00224 }
00225
00226 SendDialog::~SendDialog()
00227 {
00228     delete m_pSMTP;
00229     delete m_pMessage;
00230 }
00231
00232
00233 void SendDialog::OnSocketError(int errorCode)
00234 {
00235 }
00236
00237 void SendDialog::OnRecipientAdded(const wxString& address, int errorCode)
00238 {
00239     if (errorCode) {
00240         m_successCount++;
00241         wxString l;
00242         l << m_successCount;
00243         m_pEmailSuccessText->SetLabel(l);
00244     }
00245 }
00246
00247 void SendDialog::OnDataSent(int errorCode)
00248 {
00249     m_pStatusText->SetLabel("eMail-Versand beendet.");
00250     wxMessageBox(_("eMail-Versand beendet."), _("Wino"), wxOK | wxICON_INFORMATION);
00251 }


snddlg.h Source File

snddlg.h

00001 /*
00002  * Purpose: Sample application for demonstrating and testing the wxWindows email support
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006
00007 #ifndef SNDDLG_H
00008 #define SNDDLG_H
00009
00010 #include <wx/wx.h>
00011 #include <wx/listctrl.h>
00012
00013 #include "smtp.h"
00014
00015 class WinoDialog;
00016
00020 class SendDialog : public wxDialog, public wxSMTPListener
00021 {
00022 public:
00026     SendDialog(WinoDialog& winoDialog);
00027
00028     virtual ~SendDialog();
00029
00033     void OnSocketError(int errorCode);
00034
00038     void OnRecipientAdded(const wxString& address, int errorCode);
00039
00043     void OnDataSent(int errorCode);
00044
00045 private:
00046     wxSMTP* m_pSMTP;
00047     wxEmailMessage* m_pMessage;
00048
00049     wxStaticText* m_pStatusText;
00050     wxStaticText* m_pEmailCountText;
00051     wxStaticText* m_pEmailSuccessText;
00052     wxTextCtrl* m_pLogTextCtrl;
00053
00054     size_t m_successCount;
00055
00056     DECLARE_EVENT_TABLE()
00057 };
00058
00059
00060 #endif


states.cpp Source File

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 }


states.h Source File

states.h

00001 /*
00002  * Purpose: private wxWindows helper classes for SMTP
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006
00007 #ifndef STATES_H
00008 #define STATES_H
00009
00010 #include <wx/wx.h>
00011 #include <wx/socket.h>
00012
00013 #include "smtp.h"
00014
00020 class MailState
00021 {
00022 public:
00023     virtual void onConnect(wxSMTP& context, wxSocketEvent& event) const {}
00024     virtual void onResponse(wxSMTP& context, int smtpCode) const {}
00025 };
00026
00030 class InitialState : public MailState
00031 {
00032 public:
00037     void onConnect(wxSMTP& context, wxSocketEvent& event) const ;
00038 };
00039
00040
00044 class ConnectedState : public MailState
00045 {
00046 public:
00051     void onResponse(wxSMTP& context, int smtpCode) const ;
00052 };
00053
00054
00058 class HeloState : public MailState
00059 {
00060 public:
00065     void onResponse(wxSMTP& context, int smtpCode) const ;
00066 };
00067
00068
00072 class SendMailFromState : public MailState
00073 {
00074 public:
00079     void onResponse(wxSMTP& context, int smtpCode) const ;
00080 };
00081
00082
00087 class RcptListState : public MailState
00088 {
00089 public:
00094     void onResponse(wxSMTP& context, int smtpCode) const ;
00095 };
00096
00097
00101 class StartDataState : public MailState
00102 {
00103 public:
00108     void onResponse(wxSMTP& context, int smtpCode) const ;
00109 };
00110
00111
00115 class DataState : public MailState
00116 {
00117 public:
00122     void onResponse(wxSMTP& context, int smtpCode) const ;
00123 };
00124
00125 extern const InitialState g_initialState;
00126 extern const ConnectedState g_connectedState;
00127 extern const HeloState g_heloState;
00128 extern const SendMailFromState g_sendMailFromState;
00129 extern const RcptListState g_rcptListState;
00130 extern const StartDataState g_startDataState;
00131 extern const DataState g_dataState;
00132
00133 #endif


wino.cpp Source File

wino.cpp

00001 /*
00002  * Purpose: Sample application for demonstrating and testing the wxWindows email support
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006
00007 #include "wino.h"
00008 #include "snddlg.h"
00009
00010 static const char sccsid[] = "%W% %G%";
00011
00012 #include "wino.xpm"
00013 #include "snddlg.h"
00014
00015 enum {
00016     ID_SEND_BUTTON = 1,
00017     ID_FILE_ADD_BUTTON,
00018     ID_FILE_REMOVE_BUTTON,
00019     ID_ADDRESS_ADD_BUTTON,
00020     ID_ADDRESS_REMOVE_BUTTON
00021 };
00022
00023
00024 BEGIN_EVENT_TABLE(WinoDialog, wxDialog)
00025 EVT_BUTTON(ID_SEND_BUTTON, WinoDialog::OnSendButton)
00026 EVT_BUTTON(ID_FILE_ADD_BUTTON, WinoDialog::OnFileAddButton)
00027 EVT_BUTTON(ID_FILE_REMOVE_BUTTON, WinoDialog::OnFileRemoveButton)
00028 EVT_BUTTON(ID_ADDRESS_ADD_BUTTON, WinoDialog::OnAddressAddButton)
00029 EVT_BUTTON(ID_ADDRESS_REMOVE_BUTTON, WinoDialog::OnAddressRemoveButton)
00030 END_EVENT_TABLE()
00031
00032
00033 IMPLEMENT_APP(WinoApp)
00034
00035
00036 bool WinoApp::OnInit(void)
00037 {
00038     WinoDialog dialog(NULL);
00039     dialog.ShowModal();
00040
00041     return FALSE;
00042 }
00043
00044 #include "base64.h"
00045
00046 WinoDialog::WinoDialog(wxWindow *parent)
00047                : wxDialog(parent, -1,
00048                           _("Wino - Wino Is Not Outlook"),
00049                           wxDefaultPosition,
00050                           wxDefaultSize,
00051                           wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL)
00052 {
00053
00054     // TODO: save pointers to member variables in delete it in destructor
00055     wxBoxSizer* pTopSizer = new wxBoxSizer(wxVERTICAL);
00056
00057     wxBoxSizer* pServerSizer = new wxBoxSizer(wxHORIZONTAL);
00058     pServerSizer->Add(new wxStaticText(this, -1, "SMTP Server:"), 1, wxALIGN_CENTER | wxLEFT | wxTOP, 10);
00059     m_pServerTextCtrl = new wxTextCtrl(this, -1);
00060     pServerSizer->Add(m_pServerTextCtrl, 5, wxLEFT | wxTOP | wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER | wxEXPAND, 10);
00061     pTopSizer->Add(pServerSizer, 0, wxEXPAND);
00062
00063     wxBoxSizer* pFromSizer = new wxBoxSizer(wxHORIZONTAL);
00064     pFromSizer->Add(new wxStaticText(this, -1, "Absender:"), 1, wxALIGN_CENTER | wxLEFT | wxTOP, 10);
00065     m_pFromTextCtrl = new wxTextCtrl(this, -1);
00066     pFromSizer->Add(m_pFromTextCtrl, 5, wxLEFT | wxTOP | wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER | wxEXPAND, 10);
00067     pTopSizer->Add(pFromSizer, 0, wxEXPAND);
00068
00069     wxBoxSizer* pToSizer = new wxBoxSizer(wxHORIZONTAL);
00070     pToSizer->Add(new wxStaticText(this, -1, "An:"), 1, wxALIGN_CENTER | wxLEFT | wxTOP, 10);
00071     m_pToTextCtrl = new wxTextCtrl(this, -1);
00072     pToSizer->Add(m_pToTextCtrl, 5, wxLEFT | wxTOP | wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER | wxEXPAND, 10);
00073     pTopSizer->Add(pToSizer, 0, wxEXPAND);
00074
00075     wxBoxSizer* pSubjectSizer = new wxBoxSizer(wxHORIZONTAL);
00076     pSubjectSizer->Add(new wxStaticText(this, -1, "Betreff:"), 1, wxALIGN_CENTER | wxLEFT | wxTOP, 10);
00077     m_pSubjectTextCtrl = new wxTextCtrl(this, -1);
00078     pSubjectSizer->Add(m_pSubjectTextCtrl, 5, wxLEFT | wxTOP | wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER | wxEXPAND, 10);
00079     pTopSizer->Add(pSubjectSizer, 0, wxEXPAND);
00080
00081     m_pTextTextCtrl = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxSize(100, 200), wxTE_MULTILINE);
00082     pTopSizer->Add(m_pTextTextCtrl, 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, 10);
00083
00084     // list ctrls
00085     wxBoxSizer* pListsSizer = new wxBoxSizer(wxHORIZONTAL);
00086     wxBoxSizer* pFilelistSizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, "Dateianhänge"), wxVERTICAL);
00087     wxBoxSizer* pFilelistButtonsSizer = new wxBoxSizer(wxHORIZONTAL);
00088     pFilelistButtonsSizer->Add(new wxButton(this, ID_FILE_ADD_BUTTON, "Datei hinzufügen"), 1, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 10);
00089     pFilelistButtonsSizer->Add(new wxButton(this, ID_FILE_REMOVE_BUTTON, "Markierte entfernen"), 1, wxEXPAND | wxALL, 10);
00090     m_pFilelist = new wxListBox(this, -1, wxDefaultPosition, wxSize(50, 50));
00091     pFilelistSizer->Add(m_pFilelist, 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, 10);
00092     pFilelistSizer->Add(pFilelistButtonsSizer, 0, wxEXPAND);
00093     pListsSizer->Add(pFilelistSizer, 1, wxEXPAND | wxLEFT | wxTOP, 10);
00094     wxBoxSizer* pAddresslistSizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, "Address Manager Dateien"), wxVERTICAL);
00095     wxBoxSizer* pAddresslistButtonsSizer = new wxBoxSizer(wxHORIZONTAL);
00096     pAddresslistButtonsSizer->Add(new wxButton(this, ID_ADDRESS_ADD_BUTTON, "Datei hinzufügen"), 1, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 10);
00097     pAddresslistButtonsSizer->Add(new wxButton(this, ID_ADDRESS_REMOVE_BUTTON, "Markierte entfernen"), 1, wxEXPAND | wxALL, 10);
00098     m_pAddresslist = new wxListBox(this, -1, wxDefaultPosition, wxSize(50, 50));
00099     pAddresslistSizer->Add(m_pAddresslist, 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, 10);
00100     pAddresslistSizer->Add(pAddresslistButtonsSizer, 0, wxEXPAND);
00101     pListsSizer->Add(pAddresslistSizer, 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, 10);
00102     pTopSizer->Add(pListsSizer, 0, wxEXPAND);
00103
00104     // send close button
00105     wxBoxSizer* pSendCloseSizer = new wxBoxSizer(wxHORIZONTAL);
00106     pSendCloseSizer->Add(new wxButton(this, ID_SEND_BUTTON, "eMail verschicken"), 0, wxTOP | wxBOTTOM, 10);
00107     wxButton* pCloseButton = new wxButton(this, wxID_CANCEL, "Beenden");
00108     pCloseButton->SetDefault();
00109     pSendCloseSizer->Add(pCloseButton, 0, wxALL, 10);
00110     pTopSizer->Add(pSendCloseSizer, 0, wxALIGN_RIGHT);
00111
00112     SetAutoLayout(true);
00113     SetSizer(pTopSizer);
00114     pTopSizer->Fit(this);
00115     pTopSizer->SetSizeHints(this);
00116
00117     // set some default values for testing
00118     m_pServerTextCtrl->SetValue("merlin");  // my local unix server
00119     m_pSubjectTextCtrl->SetValue("");
00120     m_pTextTextCtrl->SetValue("");
00121     m_pFromTextCtrl->SetValue("fb@frank-buss.de");
00122     m_pToTextCtrl->SetValue("somebody@frank-buss.de");
00123
00124     // show dialog
00125     Centre(wxBOTH | wxCENTRE_ON_SCREEN);
00126 }
00127
00128
00129 WinoDialog::~WinoDialog()
00130 {
00131 }
00132
00133
00134 void WinoDialog::OnSendButton(wxCommandEvent &event)
00135 {
00136     SendDialog dialog(*this);
00137     dialog.ShowModal();
00138 }
00139
00140
00141 void WinoDialog::OnFileAddButton(wxCommandEvent &event)
00142 {
00143     wxFileDialog dialog(this, "Datei Hinzufügen", "", "", "Alle Dateien (*)|*", wxOPEN);
00144     if (dialog.ShowModal() == wxID_OK) {
00145         wxFileName* pFilename = new wxFileName(dialog.GetPath());
00146         m_pFilelist->Append(pFilename->GetFullName(), pFilename);
00147     }
00148 }
00149
00150 void WinoDialog::OnFileRemoveButton(wxCommandEvent &event)
00151 {
00152     int sel = m_pFilelist->GetSelection();
00153     if (sel != -1) {
00154         wxFileName* pFilename = (wxFileName*) m_pFilelist->GetClientData(sel);
00155         m_pFilelist->Delete(sel);
00156         delete pFilename;
00157     }
00158 }
00159
00160 void WinoDialog::OnAddressAddButton(wxCommandEvent &event)
00161 {
00162     wxFileDialog dialog(this, "Address Manager Datei Empfängerliste Hinzufügen", "", "", "Address Manager Dateien (*.adm)|*.adm", wxOPEN);
00163     if (dialog.ShowModal() == wxID_OK) {
00164         wxFileName* pFilename = new wxFileName(dialog.GetPath());
00165         m_pAddresslist->Append(pFilename->GetFullName(), pFilename);
00166     }
00167 }
00168
00169 void WinoDialog::OnAddressRemoveButton(wxCommandEvent &event)
00170 {
00171     int sel = m_pAddresslist->GetSelection();
00172     if (sel != -1) {
00173         wxFileName* pFilename = (wxFileName*) m_pAddresslist->GetClientData(sel);
00174         m_pAddresslist->Delete(sel);
00175         delete pFilename;
00176     }
00177 }
00178


wino.h Source File

wino.h

00001 /*
00002  * Purpose: Sample application for demonstrating and testing the wxWindows email support
00003  * Author:  Frank Buß
00004  * Created: 2002
00005  */
00006
00007 #ifndef WINO_H
00008 #define WINO_H
00009
00010 #include <wx/wx.h>
00011 #include <wx/listctrl.h>
00012
00013 #if !defined(__WXMSW__)
00014 extern char* wino_xpm[];
00015 #endif
00016
00020 class WinoApp : public wxApp
00021 {
00022 public:
00028     bool OnInit();
00029 };
00030
00034 class WinoDialog : public wxDialog
00035 {
00036 public:
00040     WinoDialog(wxWindow *parent);
00041     ~WinoDialog();
00042
00046     void OnSendButton(wxCommandEvent &event);
00047
00051     void OnFileAddButton(wxCommandEvent &event);
00052
00056     void OnFileRemoveButton(wxCommandEvent &event);
00057
00061     void OnAddressAddButton(wxCommandEvent &event);
00062
00066     void OnAddressRemoveButton(wxCommandEvent &event);
00067
00068 private:
00069     wxTextCtrl* m_pServerTextCtrl;
00070     wxTextCtrl* m_pFromTextCtrl;
00071     wxTextCtrl* m_pToTextCtrl;
00072     wxTextCtrl* m_pSubjectTextCtrl;
00073     wxTextCtrl* m_pTextTextCtrl;
00074     wxListBox* m_pFilelist;
00075     wxListBox* m_pAddresslist;
00076
00077     DECLARE_EVENT_TABLE()
00078
00079     friend class SendDialog;
00080 };
00081
00082
00083 #endif