X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/decb3a6a16ea5acf1dfcdb1b70cb6edaa09840c0..a6c129111b38341eb561b110fd1566b260740675:/contrib/src/net/email.cpp diff --git a/contrib/src/net/email.cpp b/contrib/src/net/email.cpp index a4b9c44aaa..7ca1633ab7 100644 --- a/contrib/src/net/email.cpp +++ b/contrib/src/net/email.cpp @@ -9,10 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "email.h" -#endif - // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" @@ -31,11 +27,19 @@ #include "wx/net/smapi.h" #endif +#ifdef __UNIX__ +#include "wx/filefn.h" +#include "wx/timer.h" +#include "wx/wfstream.h" +#include "stdlib.h" +#include "unistd.h" +#endif + // Send a message. -// Specify profile, or leave it to wxWindows to find the current user name +// Specify profile, or leave it to wxWidgets to find the current user name #ifdef __WXMSW__ -bool wxEmail::Send(wxMailMessage& message, const wxString& profileName) +bool wxEmail::Send(wxMailMessage& message, const wxString& profileName, const wxString& WXUNUSED(sendMail)) { wxASSERT (message.m_to.GetCount() > 0) ; @@ -52,6 +56,66 @@ bool wxEmail::Send(wxMailMessage& message, const wxString& profileName) return session.Send(message); } +#elif defined(__UNIX__) +bool +wxEmail::Send(wxMailMessage& message, + const wxString& profileName, + const wxString& sendMail) +{ + wxASSERT_MSG( !message.m_to.IsEmpty(), _T("no recipients to send mail to") ) ; + + + // The 'from' field is optionally supplied by the app; it's not needed + // by MAPI, and on Unix, will be guessed if not supplied. + wxString from = message.m_from; + if ( from.empty() ) + { + from = wxGetEmailAddress(); + } + + wxString msg; + msg << wxT("To: "); + + const size_t rcptCount = message.m_to.GetCount(); + for (size_t rcpt = 0; rcpt < rcptCount; rcpt++) + { + if ( rcpt ) + msg << wxT(", "); + msg << message.m_to[rcpt]; + } + + msg << wxT("\nFrom: ") << from << wxT("\nSubject: ") << message.m_subject; + msg << wxT("\n\n") << message.m_body; + + wxString filename; + filename.Printf(wxT("/tmp/msg-%ld-%ld-%ld.txt"), (long) getpid(), wxGetLocalTime(), + (long) rand()); + + { + wxFileOutputStream stream(filename); + if (stream.Ok()) + { + stream.Write(msg, msg.Length()); + } + else + { + return FALSE ; + } + } + + // TODO search for a suitable sendmail if sendMail is empty + wxString sendmail(sendMail); + + wxString cmd; + cmd << sendmail << wxT(" < ") << filename; + + // TODO: check return code + wxSystem(cmd.c_str()); + + wxRemoveFile(filename); + + return TRUE; +} #else #error Send not yet implemented for this platform. #endif