]> git.saurik.com Git - wxWidgets.git/commitdiff
Added simple UNIX implementation
authorJulian Smart <julian@anthemion.co.uk>
Thu, 6 Sep 2001 19:27:52 +0000 (19:27 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Thu, 6 Sep 2001 19:27:52 +0000 (19:27 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11568 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

contrib/include/wx/net/email.h
contrib/include/wx/net/msg.h
contrib/src/net/NetVC.dsp
contrib/src/net/email.cpp
contrib/src/net/smapi.cpp

index 1c312b49807725c2d5e860f55e5e37197c78e418..2d50316206bd76410caaef7c77cab71478b0a0e1 100644 (file)
@@ -33,7 +33,8 @@ public:
 
     // Send a message.
     // Specify profile, or leave it to wxWindows to find the current user name
-    static bool Send(wxMailMessage& message, const wxString& profileName = wxEmptyString );
+    static bool Send(wxMailMessage& message, const wxString& profileName = wxEmptyString,
+        const wxString& sendMail = wxT("/usr/lib/sendmail -t"));
     
 protected:
 };
index ffc77727f59c387d9a79f8aa4e269e778e7f37b8..3350738898e2d84d856b326ac28155e9d41df7b0 100644 (file)
@@ -27,12 +27,14 @@ public:
 
     // A common usage
     wxMailMessage(const wxString& subject, const wxString& to,
-        const wxString& body, const wxString& attachment = wxEmptyString,
+        const wxString& body, const wxString& from = wxEmptyString,
+        const wxString& attachment = wxEmptyString,
         const wxString& attachmentTitle = wxEmptyString)
     {
         m_to.Add(to);
         m_subject = subject;
         m_body = body;
+        m_from = from;
         if (!attachment.IsEmpty())
         {
             m_attachments.Add(attachment);
@@ -52,9 +54,11 @@ public:
 
     void SetSubject(const wxString& subject) { m_subject = subject; }
     void SetBody(const wxString& body) { m_body = body; }
+    void SetFrom(const wxString& from) { m_from = from; }
 
 public:
     wxArrayString  m_to;               //The To: Recipients
+    wxString       m_from;             //The From: email address (optional)
     wxArrayString  m_cc;               //The CC: Recipients
     wxArrayString  m_bcc;              //The BCC Recipients
     wxString       m_subject;         //The Subject of the message
index 6d59a075eaeeed72062c68bd1aa52a9a9308409e..d4281ccf40780aa636b835904b7510271203b11a 100644 (file)
@@ -84,15 +84,23 @@ LIB32=link.exe -lib
 # Name "NetVC - Win32 Debug"
 # Begin Source File
 
-SOURCE=.\smapi.cpp
+SOURCE=.\email.cpp
 # End Source File
 # Begin Source File
 
-SOURCE=.\email.cpp
+SOURCE=..\..\include\wx\net\email.h
 # End Source File
 # Begin Source File
 
-SOURCE=.\web.cpp
+SOURCE=..\..\include\wx\net\msg.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\readme.txt
+# End Source File
+# Begin Source File
+
+SOURCE=.\smapi.cpp
 # End Source File
 # Begin Source File
 
@@ -100,7 +108,11 @@ SOURCE=..\..\include\wx\net\smapi.h
 # End Source File
 # Begin Source File
 
-SOURCE=.\readme.txt
+SOURCE=.\web.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\wx\net\web.h
 # End Source File
 # End Target
 # End Project
index a4b9c44aaa1e764bb73cbc5d011be9f42f8ac9f3..7f314927fcc2d95ac8ce7b04b9f7b96cc5c4d720 100644 (file)
 #include "wx/net/smapi.h"
 #endif
 
+#ifdef __UNIX__
+#include "wx/filefn.h"
+#include "wx/timer.h"
+#include "wx/wfstream.h"
+#include "stdlib.h"
+#include "process.h"
+#endif
+
 // Send a message.
 // Specify profile, or leave it to wxWindows 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 +60,64 @@ 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 (message.m_to.GetCount() > 0) ;
+
+    // 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.IsEmpty())
+    {
+        from = wxGetEmailAddress();
+    }
+
+    wxASSERT (!from.IsEmpty());
+
+    wxString msg;
+    msg << wxT("To: ");
+
+    size_t i;
+    for (i = 0; i < message.m_to.GetCount(); i++)
+    {
+        msg << message.m_to[i];
+        if (i < message.m_to.GetCount())
+            msg << wxT(", ");
+    }
+
+    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
index 4412ad15a21694b46d7bc0c2fdcdd3619e991dfc..81617a39b8ee192886df367654a544ae627aa2e3 100644 (file)
@@ -286,6 +286,17 @@ bool wxMapiSession::Send(wxMailMessage& message)
     
     //Allocate the recipients array
     mapiMessage.lpRecips = new MapiRecipDesc[mapiMessage.nRecipCount];
+
+    // If we have a 'From' field, use it
+    if (!message.m_from.IsEmpty())
+    {
+        mapiMessage.lpOriginator = new MapiRecipDesc;
+        ZeroMemory(mapiMessage.lpOriginator, sizeof(MapiRecipDesc));
+
+        mapiMessage.lpOriginator->ulRecipClass = MAPI_ORIG;
+        // TODO Do we have to call Resolve?
+        mapiMessage.lpOriginator->lpszName = (LPSTR) message.m_from.c_str();
+    }
     
     //Setup the "To" recipients
     int nRecipIndex = 0;
@@ -413,8 +424,9 @@ bool wxMapiSession::Send(wxMailMessage& message)
     if (nAttachmentSize)
         delete [] mapiMessage.lpFiles;
     
-    //Free up the Recipients memory
+    //Free up the Recipients and Originator memory
     delete [] mapiMessage.lpRecips;
+    delete mapiMessage.lpOriginator;
     
     return bSuccess;
 }