Back to index

lightning-sunbird  0.9+nobinonly
mapimail.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 //
00038 #include <windows.h>
00039 #include <windowsx.h>   
00040 #include <string.h>
00041 #include <mapi.h>         
00042 #include <stdlib.h>
00043 
00044 #include "port.h"
00045 #include "resource.h"
00046 
00047 //
00048 // Variables...
00049 // 
00050 extern HINSTANCE   m_hInstMapi;
00051 extern LHANDLE     mapiSession;
00052 
00053 // 
00054 // Forward declarations...
00055 //
00056 void          DoMAPIFreeBuffer(HWND hWnd, LPVOID buf, BOOL alert);
00057 extern void   ShowMessage(HWND hWnd, LPSTR msg);
00058 void          DoMAPISendMail(HWND hWnd);
00059 void          DoMAPISendDocuments(HWND hWnd);
00060 void          DoMAPISaveMail(HWND hWnd);
00061 void          DoMAPIAddress(HWND hWnd);
00062 extern void   SetFooter(LPSTR msg);
00063 extern LPSTR  GetMAPIError(LONG errorCode);
00064 
00065 void 
00066 ProcessMailCommand(HWND hWnd, int id, HWND hCtl, UINT codeNotify) 
00067 { 
00068   switch (id) 
00069   {
00070   case IDCANCEL:
00071     EndDialog(hWnd, 0);
00072     break;
00073 
00074   case ID_BUTTON_MAPISENDMAIL:
00075     DoMAPISendMail(hWnd);
00076     break;
00077 
00078   case ID_BUTTON_MAPISENDDOCUMENTS:
00079     DoMAPISendDocuments(hWnd);
00080     break;
00081 
00082   case ID_BUTTON_MAPISAVEMAIL:
00083     DoMAPISaveMail(hWnd);
00084     break;
00085 
00086   case ID_BUTTON_MAPIADDRESS:
00087     DoMAPIAddress(hWnd);
00088     break;
00089 
00090   default:
00091     break;
00092   }
00093 }
00094 
00095 BOOL CALLBACK LOADDS 
00096 MailDlgProc(HWND hWndMain, UINT wMsg, WPARAM wParam, LPARAM lParam) 
00097 {
00098   switch (wMsg) 
00099   {
00100   case WM_INITDIALOG: 
00101     break;
00102 
00103   case WM_COMMAND:
00104     HANDLE_WM_COMMAND(hWndMain, wParam, lParam, ProcessMailCommand);
00105     break;
00106 
00107   default:
00108     return FALSE;
00109   }
00110   
00111   return TRUE;
00112 }
00113 
00114 static LPSTR lpszDelimChar = ";";
00115 
00116 void
00117 TackItOn(LPSTR fileBuf, LPSTR nameBuf, LPSTR addOn)
00118 {
00119   if (addOn[0] != '\0')
00120   {
00121     lstrcat(fileBuf, addOn);
00122     lstrcat(fileBuf, lpszDelimChar);
00123 
00124     lstrcat(nameBuf, "NAMEOF.FILE");
00125     lstrcat(nameBuf, lpszDelimChar);
00126   }
00127 }
00128 
00129 void
00130 DoMAPISendDocuments(HWND hWnd)
00131 {
00132   ULONG (FAR PASCAL *lpfnMAPISendDocuments) (ULONG ulUIParam, 
00133           LPTSTR lpszDelimChar, LPTSTR lpszFullPaths, 
00134           LPTSTR lpszFileNames, ULONG ulReserved);
00135 
00136 #ifdef WIN16         
00137   (FARPROC&) lpfnMAPISendDocuments = GetProcAddress(m_hInstMapi, "MAPISENDDOCUMENTS"); 
00138 #else
00139   (FARPROC&) lpfnMAPISendDocuments = GetProcAddress(m_hInstMapi, "MAPISendDocuments"); 
00140 #endif
00141   
00142   if (!lpfnMAPISendDocuments)
00143   {
00144     ShowMessage(hWnd, "Unable to locate MAPI function.");
00145     return;
00146   }
00147 
00148   char  msg[1024];
00149   char  tempFileName[_MAX_PATH] = "";
00150   char  lpszFullPaths[(_MAX_PATH + 1) * 4] = "";
00151   char  lpszFileNames[(_MAX_PATH + 1) * 4] = "";
00152 
00153   // Now get the names of the files to attach...
00154   GetDlgItemText(hWnd, ID_EDIT_ATTACH1, tempFileName, sizeof(tempFileName));
00155   TackItOn(lpszFullPaths, lpszFileNames, tempFileName); 
00156 
00157   GetDlgItemText(hWnd, ID_EDIT_ATTACH2, tempFileName, sizeof(tempFileName));
00158   TackItOn(lpszFullPaths, lpszFileNames, tempFileName); 
00159 
00160   GetDlgItemText(hWnd, ID_EDIT_ATTACH3, tempFileName, sizeof(tempFileName));
00161   TackItOn(lpszFullPaths, lpszFileNames, tempFileName); 
00162 
00163   GetDlgItemText(hWnd, ID_EDIT_ATTACH4, tempFileName, sizeof(tempFileName));
00164   TackItOn(lpszFullPaths, lpszFileNames, tempFileName); 
00165 
00166   LONG  rc = (*lpfnMAPISendDocuments)
00167         ( (ULONG) hWnd,        
00168           lpszDelimChar, 
00169           lpszFullPaths, 
00170           lpszFileNames, 
00171           0);
00172 
00173   if (rc == SUCCESS_SUCCESS)
00174   {
00175     ShowMessage(hWnd, "Success with MAPISendDocuments");
00176     SetFooter("MAPISendDocuments success");
00177   }
00178   else
00179   {
00180     wsprintf(msg, "FAILURE: Return code %d from MAPISendDocuments\nError=[%s]", 
00181                       rc, GetMAPIError(rc));
00182     ShowMessage(hWnd, msg);
00183     SetFooter("MAPISendDocuments failed");
00184   }
00185 }
00186 
00187 void
00188 FreeMAPIFile(lpMapiFileDesc pv)
00189 {
00190   if (!pv)
00191     return;
00192 
00193   if (pv->lpszPathName != NULL)   
00194     free(pv->lpszPathName);
00195 
00196   if (pv->lpszFileName != NULL)   
00197     free(pv->lpszFileName);
00198 }
00199 
00200 void
00201 FreeMAPIRecipient(lpMapiRecipDesc pv)
00202 {
00203   if (!pv)
00204     return;
00205 
00206   if (pv->lpszName != NULL)   
00207     free(pv->lpszName);
00208 
00209   if (pv->lpszAddress != NULL)
00210     free(pv->lpszAddress);
00211 
00212   if (pv->lpEntryID != NULL)
00213     free(pv->lpEntryID);  
00214 }
00215 
00216 void
00217 FreeMAPIMessage(lpMapiMessage pv)
00218 {
00219   ULONG i;
00220 
00221   if (!pv)
00222     return;
00223 
00224   if (pv->lpszSubject != NULL)
00225     free(pv->lpszSubject);
00226 
00227   if (pv->lpszNoteText)
00228       free(pv->lpszNoteText);
00229   
00230   if (pv->lpszMessageType)
00231     free(pv->lpszMessageType);
00232   
00233   if (pv->lpszDateReceived)
00234     free(pv->lpszDateReceived);
00235   
00236   if (pv->lpszConversationID)
00237     free(pv->lpszConversationID);
00238   
00239   if (pv->lpOriginator)
00240     FreeMAPIRecipient(pv->lpOriginator);
00241   
00242   for (i=0; i<pv->nRecipCount; i++)
00243   {
00244     if (&(pv->lpRecips[i]) != NULL)
00245     {
00246       FreeMAPIRecipient(&(pv->lpRecips[i]));
00247     }
00248   }
00249 
00250   if (pv->lpRecips != NULL)
00251   {
00252     free(pv->lpRecips);
00253   }
00254 
00255   for (i=0; i<pv->nFileCount; i++)
00256   {
00257     if (&(pv->lpFiles[i]) != NULL)
00258     {
00259       FreeMAPIFile(&(pv->lpFiles[i]));
00260     }
00261   }
00262 
00263   if (pv->lpFiles != NULL)
00264   {
00265     free(pv->lpFiles);
00266   }
00267   
00268   free(pv);
00269   pv = NULL;
00270 }
00271 
00272 void
00273 DoMAPISendMail(HWND hWnd)
00274 {
00275   ULONG (FAR PASCAL *lpfnMAPISendMail) (LHANDLE lhSession, ULONG ulUIParam, 
00276                   lpMapiMessage lpMessage, FLAGS flFlags, ULONG ulReserved);
00277 
00278 #ifdef WIN16         
00279   (FARPROC&) lpfnMAPISendMail = GetProcAddress(m_hInstMapi, "MAPISENDMAIL"); 
00280 #else
00281   (FARPROC&) lpfnMAPISendMail = GetProcAddress(m_hInstMapi, "MAPISendMail"); 
00282 #endif
00283   
00284   if (!lpfnMAPISendMail)
00285   {
00286     ShowMessage(hWnd, "Unable to locate MAPI function.");
00287     return;
00288   }          
00289 
00290   FLAGS   flFlags = 0;
00291   char    msg[512];
00292   char    file1[_MAX_PATH] = "";
00293   char    file2[_MAX_PATH] = "";
00294   char    file3[_MAX_PATH] = "";
00295   char    file4[_MAX_PATH] = "";
00296   char    toAddr[128];
00297   char    ccAddr[128];
00298   char    bccAddr[128];
00299   char    subject[128];
00300   char    noteText[4096];
00301   char    dateReceived[128] = "N/A";
00302   char    threadID[128] = "N/A";
00303   char    origName[128] = "N/A";
00304   char    origAddress[128] = "N/A";
00305 
00306   GetDlgItemText(hWnd, ID_EDIT_TOADDRESS, toAddr, sizeof(toAddr));
00307   GetDlgItemText(hWnd, ID_EDIT_CCADDRESS, ccAddr, sizeof(ccAddr));
00308   GetDlgItemText(hWnd, ID_EDIT_BCCADDRESS, bccAddr, sizeof(bccAddr));
00309   GetDlgItemText(hWnd, ID_EDIT_SUBJECT, subject, sizeof(subject));
00310   GetDlgItemText(hWnd, ID_EDIT_NOTETEXT, noteText, sizeof(noteText));
00311 
00312   // Do the one flag we support for this call...
00313   if (BST_CHECKED == Button_GetCheck(GetDlgItem(hWnd, ID_CHECK_SHOWDIALOG)))
00314   {
00315     flFlags |= MAPI_DIALOG;
00316   }
00317 
00318   // Build the message to send off...
00319   lpMapiMessage  msgPtr = (MapiMessage *)malloc(sizeof(MapiMessage));
00320   if (msgPtr == NULL)
00321   {
00322     return;
00323   }
00324   
00325   memset(msgPtr, 0, sizeof(MapiMessage)); 
00326 
00327   //
00328   // At this point, we need to populate the structure of information
00329   // we are passing in via the *lppMessage
00330   //
00331 
00332   // Set all of the general information first!
00333   msgPtr->lpszSubject = strdup(subject);
00334   msgPtr->lpszNoteText = strdup(noteText);
00335   msgPtr->lpszDateReceived = strdup(dateReceived);
00336   msgPtr->lpszConversationID = strdup(threadID);
00337   msgPtr->flFlags = flFlags;
00338 
00339   // Now deal with the recipients of this message
00340   DWORD       realRecips = 0;
00341   if (toAddr[0] != '\0')    ++realRecips;
00342   if (ccAddr[0] != '\0')    ++realRecips;
00343   if (bccAddr[0] != '\0')   ++realRecips;
00344 
00345   msgPtr->lpRecips = (lpMapiRecipDesc) malloc((size_t) (sizeof(MapiRecipDesc) * realRecips));
00346   if (!msgPtr->lpRecips)
00347   {
00348     FreeMAPIMessage(msgPtr);
00349     return;
00350   }
00351 
00352   msgPtr->nRecipCount = realRecips;
00353   memset(msgPtr->lpRecips, 0, (size_t) (sizeof(MapiRecipDesc) * msgPtr->nRecipCount));
00354 
00355   DWORD       rCount = 0;
00356   if (toAddr[0] != '\0')
00357   {
00358     msgPtr->lpRecips[rCount].lpszName = strdup(toAddr);
00359     msgPtr->lpRecips[rCount].lpszAddress = strdup(toAddr);
00360     msgPtr->lpRecips[rCount].ulRecipClass = MAPI_TO;
00361     rCount++;
00362   }
00363 
00364   if (ccAddr[0] != '\0')
00365   {
00366     msgPtr->lpRecips[rCount].lpszName = strdup(ccAddr);
00367     msgPtr->lpRecips[rCount].lpszAddress = strdup(ccAddr);
00368     msgPtr->lpRecips[rCount].ulRecipClass = MAPI_CC;    
00369     rCount++;
00370   }
00371 
00372   if (bccAddr[0] != '\0')
00373   {
00374     msgPtr->lpRecips[rCount].lpszName = strdup(bccAddr);
00375     msgPtr->lpRecips[rCount].lpszAddress = strdup(bccAddr);
00376     msgPtr->lpRecips[rCount].ulRecipClass = MAPI_BCC;
00377     rCount++;
00378   }
00379 
00380   // Now get the names of the files to attach...
00381   GetDlgItemText(hWnd, ID_EDIT_ATTACH1, file1, sizeof(file1));
00382   GetDlgItemText(hWnd, ID_EDIT_ATTACH2, file2, sizeof(file2));
00383   GetDlgItemText(hWnd, ID_EDIT_ATTACH3, file3, sizeof(file3));
00384   GetDlgItemText(hWnd, ID_EDIT_ATTACH4, file4, sizeof(file4));
00385 
00386   DWORD       realFiles = 0;
00387   if (file1[0] != '\0')    ++realFiles;
00388   if (file2[0] != '\0')    ++realFiles;
00389   if (file3[0] != '\0')    ++realFiles;
00390   if (file4[0] != '\0')    ++realFiles;
00391 
00392   // Now deal with the list of attachments! Since the nFileCount should be set
00393   // correctly, this loop will automagically be correct
00394   //
00395   msgPtr->nFileCount = realFiles;
00396   if (realFiles > 0)
00397   {
00398     msgPtr->lpFiles = (lpMapiFileDesc) malloc((size_t) (sizeof(MapiFileDesc) * realFiles));
00399     if (!msgPtr->lpFiles)
00400     {
00401       FreeMAPIMessage(msgPtr);
00402       return;
00403     }
00404 
00405     memset(msgPtr->lpFiles, 0, (size_t) (sizeof(MapiFileDesc) * msgPtr->nFileCount));
00406   }
00407 
00408   rCount = 0;
00409   if (file1[0] != '\0')
00410   {
00411     msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file1);
00412     msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file1);
00413     ++rCount;
00414   }
00415 
00416   if (file2[0] != '\0')
00417   {
00418     msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file2);
00419     msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file2);
00420     ++rCount;
00421   }
00422 
00423   if (file3[0] != '\0')
00424   {
00425     msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file3);
00426     msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file3);
00427     ++rCount;
00428   }
00429 
00430   if (file4[0] != '\0')
00431   {
00432     msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file4);
00433     msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file4);
00434     ++rCount;
00435   }
00436 
00437   // Finally, make the call...
00438   LONG  rc = (*lpfnMAPISendMail)
00439            (mapiSession, 
00440            (ULONG) hWnd, 
00441            msgPtr, 
00442            flFlags, 
00443            0);
00444 
00445   if (rc == SUCCESS_SUCCESS)
00446   {
00447     ShowMessage(hWnd, "Success with MAPISendMail");
00448     SetFooter("MAPISendMail success");
00449   }
00450   else
00451   {
00452     wsprintf(msg, "FAILURE: Return code %d from MAPISendMail\nError=[%s]", 
00453                       rc, GetMAPIError(rc));
00454     ShowMessage(hWnd, msg);
00455     SetFooter("MAPISendMail failed");
00456   }
00457 
00458   // Now cleanup and move on...
00459   FreeMAPIMessage(msgPtr);
00460 }
00461 
00462 void
00463 DoMAPISaveMail(HWND hWnd)
00464 {
00465   ULONG (FAR PASCAL *lpfnMAPISaveMail) (LHANDLE lhSession, ULONG ulUIParam, 
00466                   lpMapiMessage lpMessage, FLAGS flFlags, ULONG ulReserved,
00467                   LPTSTR lpszMessageID);
00468 
00469 #ifdef WIN16         
00470   (FARPROC&) lpfnMAPISaveMail = GetProcAddress(m_hInstMapi, "MAPISAVEMAIL"); 
00471 #else
00472   (FARPROC&) lpfnMAPISaveMail = GetProcAddress(m_hInstMapi, "MAPISaveMail"); 
00473 #endif
00474   
00475   if (!lpfnMAPISaveMail)
00476   {
00477     ShowMessage(hWnd, "Unable to locate MAPI function.");
00478     return;
00479   }          
00480 
00481   FLAGS   flFlags = 0;
00482   char    msg[512];
00483   char    file1[_MAX_PATH] = "";
00484   char    file2[_MAX_PATH] = "";
00485   char    file3[_MAX_PATH] = "";
00486   char    file4[_MAX_PATH] = "";
00487   char    toAddr[128];
00488   char    ccAddr[128];
00489   char    bccAddr[128];
00490   char    subject[128];
00491   char    noteText[4096];
00492   char    dateReceived[128] = "N/A";
00493   char    threadID[128] = "N/A";
00494   char    origName[128] = "N/A";
00495   char    origAddress[128] = "N/A";
00496 
00497   GetDlgItemText(hWnd, ID_EDIT_TOADDRESS, toAddr, sizeof(toAddr));
00498   GetDlgItemText(hWnd, ID_EDIT_CCADDRESS, ccAddr, sizeof(ccAddr));
00499   GetDlgItemText(hWnd, ID_EDIT_BCCADDRESS, bccAddr, sizeof(bccAddr));
00500   GetDlgItemText(hWnd, ID_EDIT_SUBJECT, subject, sizeof(subject));
00501   GetDlgItemText(hWnd, ID_EDIT_NOTETEXT, noteText, sizeof(noteText));
00502 
00503   // Build the message to send off...
00504   lpMapiMessage  msgPtr = (MapiMessage *)malloc(sizeof(MapiMessage));
00505   if (msgPtr == NULL)
00506   {
00507     return;
00508   }
00509   
00510   memset(msgPtr, 0, sizeof(MapiMessage)); 
00511 
00512   //
00513   // At this point, we need to populate the structure of information
00514   // we are passing in via the *lppMessage
00515   //
00516 
00517   // Set all of the general information first!
00518   msgPtr->lpszSubject = strdup(subject);
00519   msgPtr->lpszNoteText = strdup(noteText);
00520   msgPtr->lpszDateReceived = strdup(dateReceived);
00521   msgPtr->lpszConversationID = strdup(threadID);
00522   msgPtr->flFlags = flFlags;
00523 
00524   // Now deal with the recipients of this message
00525   DWORD       realRecips = 0;
00526   if (toAddr[0] != '\0')    ++realRecips;
00527   if (ccAddr[0] != '\0')    ++realRecips;
00528   if (bccAddr[0] != '\0')   ++realRecips;
00529 
00530   msgPtr->lpRecips = (lpMapiRecipDesc) malloc((size_t) (sizeof(MapiRecipDesc) * realRecips));
00531   if (!msgPtr->lpRecips)
00532   {
00533     FreeMAPIMessage(msgPtr);
00534     return;
00535   }
00536 
00537   msgPtr->nRecipCount = realRecips;
00538   memset(msgPtr->lpRecips, 0, (size_t) (sizeof(MapiRecipDesc) * msgPtr->nRecipCount));
00539 
00540   DWORD       rCount = 0;
00541   if (toAddr[0] != '\0')
00542   {
00543     msgPtr->lpRecips[rCount].lpszName = strdup(toAddr);
00544     msgPtr->lpRecips[rCount].lpszAddress = strdup(toAddr);
00545     msgPtr->lpRecips[rCount].ulRecipClass = MAPI_TO;
00546     rCount++;
00547   }
00548 
00549   if (ccAddr[0] != '\0')
00550   {
00551     msgPtr->lpRecips[rCount].lpszName = strdup(ccAddr);
00552     msgPtr->lpRecips[rCount].lpszAddress = strdup(ccAddr);
00553     msgPtr->lpRecips[rCount].ulRecipClass = MAPI_CC;    
00554     rCount++;
00555   }
00556 
00557   if (bccAddr[0] != '\0')
00558   {
00559     msgPtr->lpRecips[rCount].lpszName = strdup(bccAddr);
00560     msgPtr->lpRecips[rCount].lpszAddress = strdup(bccAddr);
00561     msgPtr->lpRecips[rCount].ulRecipClass = MAPI_BCC;
00562     rCount++;
00563   }
00564 
00565   // Now get the names of the files to attach...
00566   GetDlgItemText(hWnd, ID_EDIT_ATTACH1, file1, sizeof(file1));
00567   GetDlgItemText(hWnd, ID_EDIT_ATTACH2, file2, sizeof(file2));
00568   GetDlgItemText(hWnd, ID_EDIT_ATTACH3, file3, sizeof(file3));
00569   GetDlgItemText(hWnd, ID_EDIT_ATTACH4, file4, sizeof(file4));
00570 
00571   DWORD       realFiles = 0;
00572   if (file1[0] != '\0')    ++realFiles;
00573   if (file2[0] != '\0')    ++realFiles;
00574   if (file3[0] != '\0')    ++realFiles;
00575   if (file4[0] != '\0')    ++realFiles;
00576 
00577   // Now deal with the list of attachments! Since the nFileCount should be set
00578   // correctly, this loop will automagically be correct
00579   //
00580   msgPtr->nFileCount = realFiles;
00581   if (realFiles > 0)
00582   {
00583     msgPtr->lpFiles = (lpMapiFileDesc) malloc((size_t) (sizeof(MapiFileDesc) * realFiles));
00584     if (!msgPtr->lpFiles)
00585     {
00586       FreeMAPIMessage(msgPtr);
00587       return;
00588     }
00589 
00590     memset(msgPtr->lpFiles, 0, (size_t) (sizeof(MapiFileDesc) * msgPtr->nFileCount));
00591   }
00592 
00593   rCount = 0;
00594   if (file1[0] != '\0')
00595   {
00596     msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file1);
00597     msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file1);
00598     ++rCount;
00599   }
00600 
00601   if (file2[0] != '\0')
00602   {
00603     msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file2);
00604     msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file2);
00605     ++rCount;
00606   }
00607 
00608   if (file3[0] != '\0')
00609   {
00610     msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file3);
00611     msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file3);
00612     ++rCount;
00613   }
00614 
00615   if (file4[0] != '\0')
00616   {
00617     msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file4);
00618     msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file4);
00619     ++rCount;
00620   }
00621 
00622   // Finally, make the call...
00623   LONG  rc = (*lpfnMAPISaveMail)
00624            (mapiSession, 
00625            (ULONG) hWnd, 
00626            msgPtr, 
00627            flFlags, 
00628            0, NULL);
00629 
00630   if (rc == SUCCESS_SUCCESS)
00631   {
00632     ShowMessage(hWnd, "Success with MAPISaveMail");
00633     SetFooter("MAPISaveMail success");
00634   }
00635   else
00636   {
00637     wsprintf(msg, "FAILURE: Return code %d from MAPISaveMail\nError=[%s]", 
00638                       rc, GetMAPIError(rc));
00639     ShowMessage(hWnd, msg);
00640     SetFooter("MAPISaveMail failed");
00641   }
00642 
00643   // Now cleanup and move on...
00644   FreeMAPIMessage(msgPtr);
00645 }
00646 
00647 void          
00648 DoMAPIAddress(HWND hWnd)
00649 {
00650   ULONG (FAR PASCAL *lpfnMAPIAddress) 
00651                             (LHANDLE lhSession,
00652                             ULONG ulUIParam,
00653                             LPSTR lpszCaption,
00654                             ULONG nEditFields,
00655                             LPSTR lpszLabels,
00656                             ULONG nRecips,
00657                             lpMapiRecipDesc lpRecips,
00658                             FLAGS flFlags,
00659                             ULONG ulReserved,
00660                             LPULONG lpnNewRecips,
00661                             lpMapiRecipDesc FAR *lppNewRecips);
00662 
00663 
00664 #ifdef WIN16         
00665   (FARPROC&) lpfnMAPIAddress = GetProcAddress(m_hInstMapi, "MAPIADDRESS"); 
00666 #else
00667   (FARPROC&) lpfnMAPIAddress = GetProcAddress(m_hInstMapi, "MAPIAddress"); 
00668 #endif
00669   
00670   if (!lpfnMAPIAddress)
00671   {
00672     ShowMessage(hWnd, "Unable to locate MAPI function.");
00673     return;
00674   }          
00675 
00676   DWORD   i;
00677   FLAGS   flFlags = 0;
00678   DWORD   addrCount = 0;
00679   char    msg[512];
00680   char    toAddr[128];
00681   char    ccAddr[128];
00682   char    bccAddr[128];
00683 
00684   GetDlgItemText(hWnd, ID_EDIT_TOADDRESS, toAddr, sizeof(toAddr));
00685   GetDlgItemText(hWnd, ID_EDIT_CCADDRESS, ccAddr, sizeof(ccAddr));
00686   GetDlgItemText(hWnd, ID_EDIT_BCCADDRESS, bccAddr, sizeof(bccAddr));
00687 
00688   if (toAddr[0]) ++addrCount;
00689   if (ccAddr[0]) ++addrCount;
00690   if (bccAddr[0]) ++addrCount;
00691 
00692   lpMapiRecipDesc lpRecips = (lpMapiRecipDesc) malloc((size_t) (sizeof(MapiRecipDesc) * addrCount));
00693   if (!lpRecips)
00694   {
00695     return;
00696   }
00697 
00698   memset(lpRecips, 0, (size_t) (sizeof(MapiRecipDesc) * addrCount));
00699 
00700   DWORD       rCount = 0;
00701   if (toAddr[0] != '\0')
00702   {
00703     lpRecips[rCount].lpszName = strdup("To Address Name");
00704     lpRecips[rCount].lpszAddress = strdup(toAddr);
00705     lpRecips[rCount].ulRecipClass = MAPI_TO;
00706     rCount++;
00707   }
00708 
00709   if (ccAddr[0] != '\0')
00710   {
00711     lpRecips[rCount].lpszName = strdup("CC Address Name");
00712     lpRecips[rCount].lpszAddress = strdup(ccAddr);
00713     lpRecips[rCount].ulRecipClass = MAPI_CC;    
00714     rCount++;
00715   }
00716 
00717   if (bccAddr[0] != '\0')
00718   {
00719     lpRecips[rCount].lpszName = strdup("BCC Address Name");
00720     lpRecips[rCount].lpszAddress = strdup(bccAddr);
00721     lpRecips[rCount].ulRecipClass = MAPI_BCC;
00722     rCount++;
00723   }
00724   
00725   ULONG             newRecips;
00726   lpMapiRecipDesc   lpNewRecips;
00727 
00728   // Finally, make the call...
00729   LONG  rc = (*lpfnMAPIAddress)
00730                      (mapiSession,
00731                       0,
00732                       "MAPI Test Address Picker",
00733                       0,
00734                       NULL,
00735                       rCount,
00736                       lpRecips,
00737                       0,
00738                       0,
00739                       &newRecips,
00740                       &lpNewRecips);
00741   if (rc == SUCCESS_SUCCESS)
00742   {
00743     for (i=0; i<newRecips; i++)
00744     {
00745       char  tMsg[512];
00746 
00747       wsprintf(tMsg, "User %d\nName=[%s]\nEmail=[%s]\nType=[%d]", 
00748             i, 
00749             lpNewRecips[i].lpszName, 
00750             lpNewRecips[i].lpszAddress, 
00751             lpNewRecips[i].ulRecipClass);
00752       ShowMessage(hWnd, tMsg);
00753     }
00754 
00755     SetFooter("MAPIAddress success");
00756 
00757     DoMAPIFreeBuffer(hWnd, lpNewRecips, TRUE);
00758   }
00759   else
00760   {
00761     wsprintf(msg, "FAILURE: Return code %d from MAPIAddress\nError=[%s]", 
00762                       rc, GetMAPIError(rc));
00763     ShowMessage(hWnd, msg);
00764     SetFooter("MAPIAddress failed");
00765   }
00766 
00767   // Now cleanup and move on...
00768   for (i=0; i<rCount; i++)
00769   {
00770     FreeMAPIRecipient(&(lpRecips[i]));
00771   }
00772 }