]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/src/net/smapi.cpp
Various dummy.cpp centralized in common/dummy.cpp. Build rebaked.
[wxWidgets.git] / contrib / src / net / smapi.cpp
index b684d08e2b05c939e4c5c805ad588a0ffed78c93..d5db18bf068dc82d782785d1616f8d4e41d619f6 100644 (file)
@@ -9,10 +9,6 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-#pragma implementation "smapi.h"
-#endif
-
 // For compilers that support precompilation, includes "wx/wx.h".
 #include "wx/wxprec.h"
 
 // For compilers that support precompilation, includes "wx/wx.h".
 #include "wx/wxprec.h"
 
@@ -20,6 +16,8 @@
 #pragma hdrstop
 #endif
 
 #pragma hdrstop
 #endif
 
+#ifdef __WXMSW__
+
 #ifndef WX_PRECOMP
 #include "wx/wx.h"
 #endif
 #ifndef WX_PRECOMP
 #include "wx/wx.h"
 #endif
 #include "wx/string.h"
 #include "wx/msw/private.h"
 
 #include "wx/string.h"
 #include "wx/msw/private.h"
 
+// mapi.h in Cygwin's include directory isn't a full implementation and is
+// not sufficient for this lib. However recent versions of Cygwin also
+// have another mapi.h in include/w32api which can be used.
+//
+#ifdef __CYGWIN__
+#include <w32api/mapi.h>
+#else
 #include <mapi.h>
 #include <mapi.h>
+#endif
 
 #include "wx/net/smapi.h"
 
 
 #include "wx/net/smapi.h"
 
-class wxMapiData
+class WXDLLIMPEXP_NETUTILS wxMapiData
 {
 public:
     wxMapiData()
 {
 public:
     wxMapiData()
@@ -141,16 +147,21 @@ bool wxMapiSession::Logon(const wxString& sProfileName, const wxString& sPasswor
     
     //Setup the ascii versions of the profile name and password
     int nProfileLength = sProfileName.Length();
     
     //Setup the ascii versions of the profile name and password
     int nProfileLength = sProfileName.Length();
-    int nPasswordLength = sPassword.Length();
     
     LPSTR pszProfileName = NULL;
     LPSTR pszPassword = NULL;
     
     LPSTR pszProfileName = NULL;
     LPSTR pszPassword = NULL;
+    wxCharBuffer cbProfile(1),cbPassword(1);
     if (nProfileLength)
     {
     if (nProfileLength)
     {
-//        pszProfileName = T2A((LPTSTR) (LPCTSTR) sProfileName);
-//        pszPassword = T2A((LPTSTR) (LPCTSTR) sPassword);
+#ifndef UNICODE
         pszProfileName = (LPSTR) sProfileName.c_str();
         pszPassword = (LPSTR) sPassword.c_str();
         pszProfileName = (LPSTR) sProfileName.c_str();
         pszPassword = (LPSTR) sPassword.c_str();
+#else
+        cbProfile = sProfileName.mb_str();
+        cbPassword = sPassword.mb_str();
+        pszProfileName = cbProfile.data();
+        pszPassword = cbPassword.data();
+#endif
     }
     
     //Setup the flags & UIParam parameters used in the MapiLogon call
     }
     
     //Setup the flags & UIParam parameters used in the MapiLogon call
@@ -189,7 +200,7 @@ bool wxMapiSession::Logon(const wxString& sProfileName, const wxString& sPasswor
         }
         else
         {
         }
         else
         {
-            wxLogDebug(_T("Failed to logon to MAPI using a shared session, Error:%d\n"), nError);
+            wxLogDebug(_T("Failed to logon to MAPI using a shared session, Error:%ld\n"), nError);
             m_data->m_nLastError = nError;
         }
     }
             m_data->m_nLastError = nError;
         }
     }
@@ -226,7 +237,7 @@ bool wxMapiSession::Logoff()
         ULONG nError = m_data->m_lpfnMAPILogoff(m_data->m_hSession, 0, 0, 0); 
         if (nError != SUCCESS_SUCCESS)
         {
         ULONG nError = m_data->m_lpfnMAPILogoff(m_data->m_hSession, 0, 0, 0); 
         if (nError != SUCCESS_SUCCESS)
         {
-            wxLogDebug(_T("Failed in call to MapiLogoff, Error:%d"), nError);
+            wxLogDebug(_T("Failed in call to MapiLogoff, Error:%ld"), nError);
             m_data->m_nLastError = nError;
             bSuccess = TRUE;
         }
             m_data->m_nLastError = nError;
             bSuccess = TRUE;
         }
@@ -251,12 +262,18 @@ bool wxMapiSession::Resolve(const wxString& sName, void* lppRecip1)
     wxASSERT(m_data->m_hSession); //MAPI session handle must be valid
     
     //Call the MAPIResolveName function
     wxASSERT(m_data->m_hSession); //MAPI session handle must be valid
     
     //Call the MAPIResolveName function
-//    LPSTR lpszAsciiName = T2A((LPTSTR) (LPCTSTR) sName);
+#ifndef UNICODE
     LPSTR lpszAsciiName = (LPSTR) sName.c_str();
     LPSTR lpszAsciiName = (LPSTR) sName.c_str();
+#else
+    wxCharBuffer cbName(1);
+    cbName = sName.mb_str();
+    LPSTR lpszAsciiName = cbName.data();
+#endif
     ULONG nError = m_data->m_lpfnMAPIResolveName(m_data->m_hSession, 0, lpszAsciiName, 0, 0, lppRecip);
     if (nError != SUCCESS_SUCCESS)
     {
     ULONG nError = m_data->m_lpfnMAPIResolveName(m_data->m_hSession, 0, lpszAsciiName, 0, 0, lppRecip);
     if (nError != SUCCESS_SUCCESS)
     {
-        wxLogDebug(_T("Failed to resolve the name: %s, Error:%d\n"), sName, nError);
+        wxLogDebug(_T("Failed to resolve the name: %s, Error:%ld\n"),
+                   sName.c_str(), nError);
         m_data->m_nLastError = nError;
     }
     
         m_data->m_nLastError = nError;
     }
     
@@ -277,10 +294,16 @@ bool wxMapiSession::Send(wxMailMessage& message)
     //Create the MapiMessage structure to match the message parameter send into us
     MapiMessage mapiMessage;
     ZeroMemory(&mapiMessage, sizeof(mapiMessage));
     //Create the MapiMessage structure to match the message parameter send into us
     MapiMessage mapiMessage;
     ZeroMemory(&mapiMessage, sizeof(mapiMessage));
+#ifndef UNICODE
     mapiMessage.lpszSubject = (LPSTR) message.m_subject.c_str();
     mapiMessage.lpszNoteText = (LPSTR) message.m_body.c_str();
     mapiMessage.lpszSubject = (LPSTR) message.m_subject.c_str();
     mapiMessage.lpszNoteText = (LPSTR) message.m_body.c_str();
-//    mapiMessage.lpszSubject = T2A((LPTSTR) (LPCTSTR) message.m_subject);
-//    mapiMessage.lpszNoteText = T2A((LPTSTR) (LPCTSTR) message.m_body);
+#else
+    wxCharBuffer cbSubject(1),cbBody(1),cbOriginator(1);
+    cbSubject = message.m_subject.mb_str();
+    cbBody = message.m_body.mb_str();
+    mapiMessage.lpszSubject = cbSubject.data();
+    mapiMessage.lpszNoteText = cbBody.data();
+#endif
     mapiMessage.nRecipCount = message.m_to.GetCount() + message.m_cc.GetCount() + message.m_bcc.GetCount();
     wxASSERT(mapiMessage.nRecipCount); //Must have at least 1 recipient!
     
     mapiMessage.nRecipCount = message.m_to.GetCount() + message.m_cc.GetCount() + message.m_bcc.GetCount();
     wxASSERT(mapiMessage.nRecipCount); //Must have at least 1 recipient!
     
@@ -295,7 +318,12 @@ bool wxMapiSession::Send(wxMailMessage& message)
 
         mapiMessage.lpOriginator->ulRecipClass = MAPI_ORIG;
         // TODO Do we have to call Resolve?
 
         mapiMessage.lpOriginator->ulRecipClass = MAPI_ORIG;
         // TODO Do we have to call Resolve?
+#ifndef UNICODE
         mapiMessage.lpOriginator->lpszName = (LPSTR) message.m_from.c_str();
         mapiMessage.lpOriginator->lpszName = (LPSTR) message.m_from.c_str();
+#else
+        cbOriginator = message.m_from.mb_str();
+        mapiMessage.lpOriginator->lpszName = cbOriginator.data();
+#endif
     }
     
     //Setup the "To" recipients
     }
     
     //Setup the "To" recipients
@@ -314,13 +342,16 @@ bool wxMapiSession::Send(wxMailMessage& message)
         if (Resolve(sName, (void*) &lpTempRecip))
         {
             //Resolve worked, put the resolved name back into the sName
         if (Resolve(sName, (void*) &lpTempRecip))
         {
             //Resolve worked, put the resolved name back into the sName
-            sName = lpTempRecip->lpszName;
+            sName = wxString(lpTempRecip->lpszName,*wxConvCurrent);
             
             //Don't forget to free up the memory MAPI allocated for us
             m_data->m_lpfnMAPIFreeBuffer(lpTempRecip);
         }
             
             //Don't forget to free up the memory MAPI allocated for us
             m_data->m_lpfnMAPIFreeBuffer(lpTempRecip);
         }
-        //recip.lpszName = T2A((LPTSTR) (LPCTSTR) sName);
+#ifndef UNICODE
         recip.lpszName = (LPSTR) sName.c_str();
         recip.lpszName = (LPSTR) sName.c_str();
+#else
+        recip.lpszName = sName.mb_str().release();
+#endif
         
         ++nRecipIndex;
     }
         
         ++nRecipIndex;
     }
@@ -339,13 +370,16 @@ bool wxMapiSession::Send(wxMailMessage& message)
         if (Resolve(sName, (void*) &lpTempRecip))
         {
             //Resolve worked, put the resolved name back into the sName
         if (Resolve(sName, (void*) &lpTempRecip))
         {
             //Resolve worked, put the resolved name back into the sName
-            sName = lpTempRecip->lpszName;
+            sName = wxString(lpTempRecip->lpszName,*wxConvCurrent);
             
             //Don't forget to free up the memory MAPI allocated for us
             m_data->m_lpfnMAPIFreeBuffer(lpTempRecip);
         }
             
             //Don't forget to free up the memory MAPI allocated for us
             m_data->m_lpfnMAPIFreeBuffer(lpTempRecip);
         }
-        //recip.lpszName = T2A((LPTSTR) (LPCTSTR) sName);
+#ifndef UNICODE
         recip.lpszName = (LPSTR) sName.c_str();
         recip.lpszName = (LPSTR) sName.c_str();
+#else
+        recip.lpszName = sName.mb_str().release();
+#endif
         
         ++nRecipIndex;
     }
         
         ++nRecipIndex;
     }
@@ -364,13 +398,16 @@ bool wxMapiSession::Send(wxMailMessage& message)
         if (Resolve(sName, (void*) &lpTempRecip))
         {
             //Resolve worked, put the resolved name back into the sName
         if (Resolve(sName, (void*) &lpTempRecip))
         {
             //Resolve worked, put the resolved name back into the sName
-            sName = lpTempRecip->lpszName;
+            sName = wxString(lpTempRecip->lpszName,wxConvCurrent);
             
             //Don't forget to free up the memory MAPI allocated for us
             m_data->m_lpfnMAPIFreeBuffer(lpTempRecip);
         }
             
             //Don't forget to free up the memory MAPI allocated for us
             m_data->m_lpfnMAPIFreeBuffer(lpTempRecip);
         }
-        //recip.lpszName = T2A((LPTSTR) (LPCTSTR) sName);
+#ifndef UNICODE
         recip.lpszName = (LPSTR) sName.c_str();
         recip.lpszName = (LPSTR) sName.c_str();
+#else
+        recip.lpszName = sName.mb_str().release();
+#endif
         
         ++nRecipIndex;
     }
         
         ++nRecipIndex;
     }
@@ -393,17 +430,23 @@ bool wxMapiSession::Send(wxMailMessage& message)
             ZeroMemory(&file, sizeof(MapiFileDesc));
             file.nPosition = 0xFFFFFFFF;
             wxString& sFilename = message.m_attachments[i];
             ZeroMemory(&file, sizeof(MapiFileDesc));
             file.nPosition = 0xFFFFFFFF;
             wxString& sFilename = message.m_attachments[i];
-            //file.lpszPathName = T2A((LPTSTR) (LPCTSTR) sFilename);
 
 
+#ifndef UNICODE
             file.lpszPathName = (LPSTR) sFilename.c_str();
             file.lpszPathName = (LPSTR) sFilename.c_str();
+#else
+            file.lpszPathName = sFilename.mb_str().release();
+#endif
             //file.lpszFileName = file.lpszPathName;
             file.lpszFileName = NULL;
 
             if (nTitleSize && !message.m_attachmentTitles[i].IsEmpty())
             {
                 wxString& sTitle = message.m_attachmentTitles[i];
             //file.lpszFileName = file.lpszPathName;
             file.lpszFileName = NULL;
 
             if (nTitleSize && !message.m_attachmentTitles[i].IsEmpty())
             {
                 wxString& sTitle = message.m_attachmentTitles[i];
-                //file.lpszFileName = T2A((LPTSTR) (LPCTSTR) sTitle);
+#ifndef UNICODE
                 file.lpszFileName = (LPSTR) sTitle.c_str();
                 file.lpszFileName = (LPSTR) sTitle.c_str();
+#else
+                file.lpszFileName = sTitle.mb_str().release();
+#endif
             }
         }
     }
             }
         }
     }
@@ -417,16 +460,30 @@ bool wxMapiSession::Send(wxMailMessage& message)
     }
     else
     {
     }
     else
     {
-        wxLogDebug(_T("Failed to send mail message, Error:%d\n"), nError);
+        wxLogDebug(_T("Failed to send mail message, Error:%ld\n"), nError);
         m_data->m_nLastError = nError;
     }
     
     //Tidy up the Attachements
     if (nAttachmentSize)
         m_data->m_nLastError = nError;
     }
     
     //Tidy up the Attachements
     if (nAttachmentSize)
+    {
+#ifdef UNICODE
+        for (i = 0;i < nAttachmentSize;i++)
+        {
+            free(mapiMessage.lpFiles[i].lpszPathName);
+            free(mapiMessage.lpFiles[i].lpszFileName);
+        }
+#endif
         delete [] mapiMessage.lpFiles;
         delete [] mapiMessage.lpFiles;
+    }
     
     //Free up the Recipients and Originator memory
     
     //Free up the Recipients and Originator memory
+#ifdef UNICODE
+    for (i = 0;i < nRecipIndex;i++)
+        free(mapiMessage.lpRecips[i].lpszName);
+#endif
     delete [] mapiMessage.lpRecips;
     delete [] mapiMessage.lpRecips;
+
     delete mapiMessage.lpOriginator;
     
     return bSuccess;
     delete mapiMessage.lpOriginator;
     
     return bSuccess;
@@ -437,3 +494,4 @@ long wxMapiSession::GetLastError() const
     return m_data->m_nLastError;
 }
 
     return m_data->m_nLastError;
 }
 
+#endif // __WXMSW__