Bug 244222 - add MAPI ResolveName to improve interoperability with other mail clients. Based on a patch by Frans-Jan v. Steenbeek. r=bienvenu
authoraceman <acelists@atlas.sk>
Tue, 21 Feb 2012 14:45:53 +0000
changeset 10890 0f7e5afbe6508e39d2feb0004daae37a24c31215
parent 10889 d7c6f47e41e1cf714de9161355ff48e90d1799db
child 10891 cf85b487f53c04158575758678ed9846f2adf49c
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbienvenu
bugs244222
Bug 244222 - add MAPI ResolveName to improve interoperability with other mail clients. Based on a patch by Frans-Jan v. Steenbeek. r=bienvenu
mailnews/mapi/mapiDll/MapiDll.cpp
--- a/mailnews/mapi/mapiDll/MapiDll.cpp
+++ b/mailnews/mapi/mapiDll/MapiDll.cpp
@@ -317,108 +317,127 @@ ULONG FAR PASCAL MAPIFindNext(LHANDLE lh
                               unsigned char lpszMessageID[64])
 {
   nsIMapi *pNsMapi = NULL;
 
   if (!InitMozillaReference(&pNsMapi))
     return MAPI_E_FAILURE;
 
   if (lhSession == 0)
-    return(MAPI_E_INVALID_SESSION);
+    return MAPI_E_INVALID_SESSION;
 
   if (!lpszMessageType)
     lpszMessageType = L"";
 
   if (!lpszSeedMessageID)
     lpszSeedMessageID = L"";
 
   return pNsMapi->FindNext(lhSession, ulUIParam, lpszMessageType,
                               lpszSeedMessageID, flFlags, ulReserved,
                               lpszMessageID) ;
-
-
 }
 
 
 ULONG FAR PASCAL MAPIReadMail(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageID,
                               FLAGS flFlags, ULONG ulReserved, nsMapiMessage **lppMessage)
 {
   nsIMapi *pNsMapi = NULL;
 
   if (!InitMozillaReference(&pNsMapi))
     return MAPI_E_FAILURE;
 
   if (lhSession == 0)
-    return(MAPI_E_INVALID_SESSION);
+    return MAPI_E_INVALID_SESSION;
 
   return pNsMapi->ReadMail(lhSession, ulUIParam,
                               lpszMessageID, flFlags, ulReserved,
                               lppMessage) ;
 
 }
 
 ULONG FAR PASCAL MAPISaveMail(LHANDLE lhSession, ULONG ulUIParam, lpnsMapiMessage lpMessage,
                               FLAGS flFlags, ULONG ulReserved, LPTSTR lpszMessageID)
 {
-    nsIMapi *pNsMapi = NULL;
+  nsIMapi *pNsMapi = NULL;
 
   if (lhSession == 0)
-    return(MAPI_E_INVALID_SESSION);
+    return MAPI_E_INVALID_SESSION;
 
   if (!InitMozillaReference(&pNsMapi))
-      return MAPI_E_FAILURE;
+    return MAPI_E_FAILURE;
 
   return MAPI_E_FAILURE;
 }
 
 ULONG FAR PASCAL MAPIDeleteMail(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageID,
                                 FLAGS flFlags, ULONG ulReserved)
 {
   nsIMapi *pNsMapi = NULL;
 
   if (lhSession == 0)
-    return(MAPI_E_INVALID_SESSION);
+    return MAPI_E_INVALID_SESSION;
 
   if (!InitMozillaReference(&pNsMapi))
-      return MAPI_E_FAILURE;
+    return MAPI_E_FAILURE;
 
   return pNsMapi->DeleteMail(lhSession, ulUIParam,
                               lpszMessageID, flFlags, ulReserved) ;
 }
 
 ULONG FAR PASCAL MAPIAddress(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszCaption,
                              ULONG nEditFields, LPTSTR lpszLabels, ULONG nRecips,
                              lpMapiRecipDesc lpRecips, FLAGS flFlags,
                              ULONG ulReserved, LPULONG lpnNewRecips,
                              lpMapiRecipDesc FAR *lppNewRecips)
 {
-    return MAPI_E_FAILURE;
+    return MAPI_E_NOT_SUPPORTED;
 }
 
 ULONG FAR PASCAL MAPIDetails(LHANDLE lhSession, ULONG ulUIParam, lpMapiRecipDesc lpRecip,
                              FLAGS flFlags, ULONG ulReserved)
 {
-    return MAPI_E_FAILURE;
+    return MAPI_E_NOT_SUPPORTED;
 }
 
 ULONG FAR PASCAL MAPIResolveName(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszName,
                                  FLAGS flFlags, ULONG ulReserved, lpMapiRecipDesc FAR *lppRecip)
 {
-    return MAPI_E_FAILURE;
+  char* lpszRecipName = new char[(strlen((const char*)lpszName) + 1)];
+  if (lpszRecipName == NULL)
+    return MAPI_E_INSUFFICIENT_MEMORY;
+  char* lpszRecipAddress = new char[(strlen((const char*)lpszName) + 6)];
+  if (!lpszRecipAddress) {
+    delete[] lpszRecipName;
+    return MAPI_E_INSUFFICIENT_MEMORY;
+  }
+  strcpy(lpszRecipName, (const char*)lpszName);
+  strcpy(lpszRecipAddress, (const char*)lpszName);
+  (*lppRecip) = (lpMapiRecipDesc FAR)malloc(sizeof(MapiRecipDesc));
+  if (!(*lppRecip)) {
+    delete[] lpszRecipName;
+    delete[] lpszRecipAddress;
+    return MAPI_E_INSUFFICIENT_MEMORY;
+  }
+  (*lppRecip)->ulRecipClass = 1;
+  (*lppRecip)->lpszName = lpszRecipName;
+  (*lppRecip)->lpszAddress = lpszRecipAddress;
+  (*lppRecip)->ulEIDSize = 0;
+  (*lppRecip)->lpEntryID = 0;
+  return SUCCESS_SUCCESS;
 }
 
 void FreeMAPIRecipient(lpMapiRecipDesc pv);
 void FreeMAPIMessage(lpMapiMessage pv);
 
 ULONG FAR PASCAL MAPIFreeBuffer(LPVOID pv)
 {
   int   i;
 
   if (!pv)
-  	return(S_OK);
+    return S_OK;
 
   for (i=0; i<MAX_POINTERS; i++)
   {
     if (pv == memArray[i].lpMem)
     {
       if (memArray[i].memType == MAPI_MESSAGE_TYPE)
       {
         FreeMAPIMessage((MapiMessage *)pv);
@@ -428,64 +447,63 @@ ULONG FAR PASCAL MAPIFreeBuffer(LPVOID p
       {
         FreeMAPIRecipient((MapiRecipDesc *)pv);
         memArray[i].lpMem = NULL;
       }
     }
   }
 
   pv = NULL;
-  return(S_OK);
+  return S_OK;
 }
 
 ULONG FAR PASCAL GetMapiDllVersion()
 {
-    return 94;
+  return 94;
 }
 
 void
 FreeMAPIFile(lpMapiFileDesc pv)
 {
   if (!pv)
     return;
 
-  if (pv->lpszPathName != NULL)   
+  if (pv->lpszPathName != NULL)
     free(pv->lpszPathName);
 
-  if (pv->lpszFileName != NULL)   
+  if (pv->lpszFileName != NULL)
     free(pv->lpszFileName);
 }
 
-
 void
 FreeMAPIMessage(lpMapiMessage pv)
 {
   ULONG i;
 
   if (!pv)
     return;
 
   if (pv->lpszSubject != NULL)
     free(pv->lpszSubject);
 
   if (pv->lpszNoteText)
       free(pv->lpszNoteText);
-  
+
   if (pv->lpszMessageType)
     free(pv->lpszMessageType);
-  
+
   if (pv->lpszDateReceived)
     free(pv->lpszDateReceived);
-  
+
   if (pv->lpszConversationID)
     free(pv->lpszConversationID);
-  
+
   if (pv->lpOriginator)
     FreeMAPIRecipient(pv->lpOriginator);
-  
+
   for (i=0; i<pv->nRecipCount; i++)
   {
     if (&(pv->lpRecips[i]) != NULL)
     {
       FreeMAPIRecipient(&(pv->lpRecips[i]));
     }
   }
 
@@ -501,32 +519,28 @@ FreeMAPIMessage(lpMapiMessage pv)
       FreeMAPIFile(&(pv->lpFiles[i]));
     }
   }
 
   if (pv->lpFiles != NULL)
   {
     free(pv->lpFiles);
   }
-  
+
   free(pv);
   pv = NULL;
 }
 
 void
 FreeMAPIRecipient(lpMapiRecipDesc pv)
 {
   if (!pv)
     return;
 
-  if (pv->lpszName != NULL)   
+  if (pv->lpszName != NULL)
     free(pv->lpszName);
 
   if (pv->lpszAddress != NULL)
     free(pv->lpszAddress);
 
   if (pv->lpEntryID != NULL)
-    free(pv->lpEntryID);  
+    free(pv->lpEntryID);
 }
-
-
-
-