Back to index

lightning-sunbird  0.9+nobinonly
mapiproc.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 
00042 #ifndef MAPI_OLE     // Because MSFT doesn't do this for us :-(
00043 #include <mapi.h>
00044 #endif
00045 
00046 #include "port.h"
00047 #include "resource.h"
00048 
00049 //
00050 // Variables...
00051 // 
00052 extern HINSTANCE  hInst;
00053 HINSTANCE         m_hInstMapi;
00054 LHANDLE           mapiSession = 0;
00055 
00056 // 
00057 // Forward declarations...
00058 //
00059 void    LoadNSCPVersionFunc(HWND hWnd);
00060 void    DoMAPILogon(HWND hWnd);
00061 void    DoMAPILogoff(HWND hWnd);
00062 void    DoMAPIFreeBuffer(HWND hWnd, LPVOID buf, BOOL alert);
00063 void    DoMAPISendMail(HWND hWnd);
00064 void    DoMAPISendDocuments(HWND hWnd);
00065 void    DoMAPIFindNext(HWND hWnd);
00066 void    DoMAPIReadMail(HWND hWnd);
00067 void    DoMAPIDeleteMail(HWND hWnd);
00068 void    DoMAPIDetails(HWND hWnd);
00069 void    DoMAPIResolveName(HWND hWnd);
00070 void    DoMAPIResolveNameFreeBuffer(HWND hWnd);
00071 void    SetFooter(LPSTR msg);
00072 void    DoMAPI_NSCP_Sync(HWND hWnd);
00073 LPSTR   GetMAPIError(LONG errorCode);
00074 extern void DisplayMAPIReadMail(HWND hWnd, lpMapiMessage msgPtr);
00075 lpMapiMessage   GetMessage(HWND hWnd, LPSTR id);
00076 
00077 void
00078 SetFooter(LPSTR msg)
00079 {
00080   extern HWND   hWnd;
00081 
00082   SetDlgItemText(hWnd, ID_STATIC_RESULT, msg);
00083 }
00084 
00085 char FAR *
00086 GetMAPIError(LONG errorCode)
00087 {
00088   static char FAR msg[128];
00089 
00090   switch (errorCode) {                            
00091   case MAPI_E_FAILURE:
00092     lstrcpy(msg, "General MAPI Failure");
00093     break;
00094 
00095   case MAPI_E_INSUFFICIENT_MEMORY:
00096     strcpy(msg, "Insufficient Memory");
00097     break;
00098 
00099   case MAPI_E_LOGIN_FAILURE:
00100     strcpy(msg, "Login Failure");
00101     break;
00102 
00103   case MAPI_E_TOO_MANY_SESSIONS:
00104     strcpy(msg, "Too many MAPI sessions");
00105     break;
00106 
00107   case MAPI_E_INVALID_SESSION:
00108     strcpy(msg, "Invalid Session!");
00109     break;
00110 
00111   case MAPI_E_INVALID_MESSAGE:
00112     strcpy(msg, "Message identifier was bad!");
00113     break;
00114 
00115   case MAPI_E_NO_MESSAGES:
00116     strcpy(msg, "No messages were found!");
00117     break;
00118 
00119   case MAPI_E_ATTACHMENT_WRITE_FAILURE:
00120     strcpy(msg, "Attachment write failure!");
00121     break;
00122 
00123   case MAPI_E_DISK_FULL:
00124     strcpy(msg, "Attachment write failure! DISK FULL");
00125     break;
00126 
00127   case MAPI_E_AMBIGUOUS_RECIPIENT:
00128     strcpy(msg, "Recipient requested is not a unique address list entry.");
00129     break;
00130 
00131   case MAPI_E_UNKNOWN_RECIPIENT:
00132     strcpy(msg, "Recipient requested does not exist.");
00133     break;
00134 
00135   case MAPI_E_NOT_SUPPORTED:
00136     strcpy(msg, "Not supported by messaging system");
00137     break;
00138 
00139   case SUCCESS_SUCCESS:
00140     strcpy(msg, "Success on MAPI operation");
00141     break;
00142 
00143   case MAPI_E_INVALID_RECIPS:
00144     strcpy(msg, "Recipient specified in the lpRecip parameter was\nunknown. No dialog box was displayed.");
00145     break;
00146 
00147   case MAPI_E_ATTACHMENT_OPEN_FAILURE:
00148     strcpy(msg, "One or more files could not be located. No message was sent.");    
00149     break;
00150 
00151   case MAPI_E_ATTACHMENT_NOT_FOUND:
00152     strcpy(msg, "The specified attachment was not found. No message was sent.");
00153     break;
00154 
00155   case MAPI_E_BAD_RECIPTYPE:
00156     strcpy(msg, "The type of a recipient was not MAPI_TO, MAPI_CC, or MAPI_BCC. No message was sent.");
00157     break;
00158 
00159   default:
00160     strcpy(msg, "Unknown MAPI Return Code");
00161     break;
00162   }
00163 
00164   return((LPSTR) &(msg[0]));
00165 }
00166 
00167 void
00168 ShowMessage(HWND hWnd, LPSTR msg)
00169 {
00170   MessageBox(hWnd, msg, "Info Message", MB_ICONINFORMATION);
00171 }
00172 
00173 BOOL
00174 OpenMAPI(void)
00175 {
00176 #ifdef WIN16
00177        m_hInstMapi = LoadLibrary("Y:\\ns\\cmd\\winfe\\mapi\\MAPI.DLL");      
00178 #else
00179   m_hInstMapi = LoadLibrary("..\\..\\..\\..\\mapidll\\mozMAPI32.DLL");
00180 #endif
00181 
00182   if (!m_hInstMapi)
00183   {
00184     ShowMessage(NULL, "Error Loading the MAPI DLL...Probably not found!");
00185     return(FALSE);
00186   }
00187 
00188   return(TRUE);
00189 }
00190 
00191 void
00192 CloseMAPI(void)
00193 {
00194   if(m_hInstMapi)
00195   {
00196     FreeLibrary(m_hInstMapi);
00197   }
00198 }
00199 
00200 void 
00201 ProcessCommand(HWND hWnd, int id, HWND hCtl, UINT codeNotify) 
00202 { 
00203   switch (id) 
00204   {
00205   case ID_BUTTON_SYNC:
00206     DoMAPI_NSCP_Sync(hWnd);
00207     break;
00208 
00209   case ID_BUTTON_NSCPVERSION:
00210     LoadNSCPVersionFunc(hWnd);
00211     break;
00212 
00213   case ID_BUTTON_LOGON:
00214     DoMAPILogon(hWnd);
00215     break;
00216 
00217   case ID_BUTTON_LOGOFF:
00218     DoMAPILogoff(hWnd);
00219     break;
00220 
00221   case ID_BUTTON_FINDNEXT:
00222   case ID_MENU_MAPIFINDNEXT:
00223     DoMAPIFindNext(hWnd);
00224     break;
00225 
00226   case ID_BUTTON_READMAIL:
00227   case ID_MENU_MAPIREADMAIL:
00228     DoMAPIReadMail(hWnd);
00229     break;
00230 
00231   case ID_BUTTON_MAIL:
00232     {
00233     extern CALLBACK LOADDS 
00234            MailDlgProc(HWND hWndMain, UINT wMsg, WPARAM wParam, LPARAM lParam);
00235 
00236     DialogBox(hInst, MAKEINTRESOURCE(ID_DIALOG_MAIL), hWnd, 
00237       (DLGPROC)MailDlgProc);
00238     }
00239     break;
00240 
00241   case ID_BUTTON_DELETEMAIL:
00242   case ID_MENU_MAPIDELETEMAIL:
00243     DoMAPIDeleteMail(hWnd);
00244     break;
00245 
00246   case ID_MENU_MYEXIT:
00247          DestroyWindow(hWnd);
00248          break;
00249 
00250   case ID_BUTTON_CLEAR:
00251   case ID_MENU_CLEARRESULTS:
00252     ListBox_ResetContent(GetDlgItem(hWnd, ID_LIST_RESULT));      
00253          break;
00254 
00255   case ID_BUTTON_FREEBUFFER:
00256     DoMAPIResolveNameFreeBuffer(hWnd);
00257     break;
00258 
00259   case ID_BUTTON_RESOLVENAME:
00260     DoMAPIResolveName(hWnd);
00261     break;
00262 
00263   case ID_BUTTON_DETAILS:
00264     DoMAPIDetails(hWnd);
00265     break;
00266 
00267   case ID_MENU_MYABOUT:
00268          MessageBox(hWnd,   
00269                        "Netscape MAPI Test Harness\nWritten by: Rich Pizzarro (rhp@netscape.com)",       
00270                        "About",
00271                        MB_ICONINFORMATION);
00272          break;
00273   
00274   default:
00275     break;
00276   }
00277 }
00278 
00279 void
00280 DoMAPILogon(HWND hWnd)
00281 {
00282   char  msg[1024];
00283   char  user[128] = "";
00284   char  pw[128] = "";
00285 
00286   // Get Address of MAPI function...
00287   ULONG (FAR PASCAL *lpfnMAPILogon)(ULONG, LPSTR, LPSTR, FLAGS, ULONG, LPLHANDLE);   
00288   
00289 #ifdef WIN16         
00290   (FARPROC&) lpfnMAPILogon = GetProcAddress(m_hInstMapi, "MAPILOGON"); 
00291 #else
00292   (FARPROC&) lpfnMAPILogon = GetProcAddress(m_hInstMapi, "MAPILogon"); 
00293 #endif
00294   
00295   if (!lpfnMAPILogon)
00296   {
00297     ShowMessage(hWnd, "Unable to locate MAPI function.");
00298     return;
00299   }
00300 
00301   GetDlgItemText(hWnd, ID_EDIT_USERNAME, user, sizeof(user));
00302   GetDlgItemText(hWnd, ID_EDIT_PW, pw, sizeof(pw));
00303 
00304   LONG  rc = (*lpfnMAPILogon)((ULONG) hWnd, user, pw, 
00305                   MAPI_FORCE_DOWNLOAD | MAPI_NEW_SESSION, 0, &mapiSession);
00306   if (rc == SUCCESS_SUCCESS)
00307   {
00308     wsprintf(msg, "Success with session = %d", mapiSession);
00309     ShowMessage(hWnd, msg);
00310     SetFooter("Logon success");
00311   }
00312   else
00313   {
00314     wsprintf(msg, "FAILURE: Return code %d from Logon\nError=[%s]", 
00315                       rc, GetMAPIError(rc));
00316     ShowMessage(hWnd, msg);
00317     SetFooter("Logon failed");
00318   }
00319 }
00320 
00321 void
00322 DoMAPILogoff(HWND hWnd)
00323 {
00324   ULONG (FAR PASCAL *lpfnMAPILogoff) ( LHANDLE lhSession, ULONG ulUIParam, 
00325                                 FLAGS flFlags, ULONG ulReserved);
00326 
00327 #ifdef WIN16         
00328   (FARPROC&) lpfnMAPILogoff = GetProcAddress(m_hInstMapi, "MAPILOGOFF"); 
00329 #else
00330   (FARPROC&) lpfnMAPILogoff = GetProcAddress(m_hInstMapi, "MAPILogoff"); 
00331 #endif
00332   
00333   if (!lpfnMAPILogoff)
00334   {
00335     ShowMessage(hWnd, "Unable to locate MAPI function.");
00336     return;
00337   }
00338 
00339   char  msg[1024];
00340   LONG  rc = (*lpfnMAPILogoff)(mapiSession, (ULONG) hWnd, 0, 0);
00341   if (rc == SUCCESS_SUCCESS)
00342   {
00343     wsprintf(msg, "Successful logoff");
00344     ShowMessage(hWnd, msg);
00345     SetFooter(msg);
00346   }
00347   else
00348   {
00349     wsprintf(msg, "FAILURE: Return code %d from Logoff\nError=[%s]", 
00350                       rc, GetMAPIError(rc));
00351 
00352     ShowMessage(hWnd, msg);
00353     SetFooter("Logoff failed");
00354   }
00355 
00356   mapiSession = 0;
00357 }
00358 
00359 void
00360 DoMAPIFreeBuffer(HWND hWnd, LPVOID buf, BOOL alert)
00361 {
00362   ULONG (FAR PASCAL *lpfnMAPIFreeBuffer) (LPVOID lpBuffer);
00363 
00364 #ifdef WIN16         
00365   (FARPROC&) lpfnMAPIFreeBuffer = GetProcAddress(m_hInstMapi, "MAPIFREEBUFFER"); 
00366 #else
00367   (FARPROC&) lpfnMAPIFreeBuffer = GetProcAddress(m_hInstMapi, "MAPIFreeBuffer"); 
00368 #endif
00369   
00370   if (!lpfnMAPIFreeBuffer)
00371   {
00372     ShowMessage(hWnd, "Unable to locate MAPI function.");
00373     return;
00374   }
00375 
00376   char  msg[1024];
00377   LONG  rc = (*lpfnMAPIFreeBuffer)(buf);
00378 #ifdef WIN32
00379   if (rc == S_OK)
00380 #else
00381   if (rc == SUCCESS_SUCCESS)
00382 #endif
00383   {
00384     wsprintf(msg, "Successful Free Buffer Operation");
00385     if (alert)
00386       ShowMessage(hWnd, msg);
00387   }
00388   else
00389   {
00390     wsprintf(msg, "FAILURE: Return code %d from Logoff", rc);
00391     ShowMessage(hWnd, msg);
00392   }
00393 }
00394 
00395 void
00396 DoMAPIFindNext(HWND hWnd)
00397 {
00398   ULONG (FAR PASCAL *lpfnMAPIFindNext) (LHANDLE lhSession, ULONG ulUIParam, 
00399            LPTSTR lpszMessageType, LPTSTR lpszSeedMessageID, FLAGS flFlags, 
00400            ULONG ulReserved, LPTSTR lpszMessageID);
00401 
00402 #ifdef WIN16         
00403   (FARPROC&) lpfnMAPIFindNext = GetProcAddress(m_hInstMapi, "MAPIFINDNEXT"); 
00404 #else
00405   (FARPROC&) lpfnMAPIFindNext = GetProcAddress(m_hInstMapi, "MAPIFindNext"); 
00406 #endif
00407 
00408   if (!lpfnMAPIFindNext)
00409   {
00410     ShowMessage(hWnd, "Unable to locate MAPI function.");
00411     return;
00412   }
00413 
00414   // Clear the list before we start...
00415   ListBox_ResetContent(GetDlgItem(hWnd, ID_LIST_RESULT));
00416 
00417   char  msg[1024];
00418   char  messageID[512];
00419   LONG  rc;                                                               
00420 #ifdef WIN32
00421   FLAGS       flags = MAPI_GUARANTEE_FIFO | MAPI_LONG_MSGID | MAPI_UNREAD_ONLY;
00422 #else                                                                        
00423   FLAGS       flags = MAPI_GUARANTEE_FIFO | MAPI_UNREAD_ONLY;
00424 #endif
00425   
00426   while ( (rc = (*lpfnMAPIFindNext) (mapiSession, 
00427            (ULONG) hWnd, 
00428            NULL, 
00429            NULL, 
00430                  flags,
00431            0,
00432            messageID)) == SUCCESS_SUCCESS)
00433   {
00434       // 
00435 
00436       lpMapiMessage mapiMsg = GetMessage(hWnd, messageID);
00437       if (mapiMsg != NULL)
00438       {
00439         wsprintf(msg, "%s: \"%s\" Sender: %s", 
00440                   messageID, 
00441                   mapiMsg->lpszSubject ? mapiMsg->lpszSubject : "", 
00442                   mapiMsg->lpOriginator->lpszName);
00443         DoMAPIFreeBuffer(hWnd, mapiMsg, FALSE);
00444       }
00445       else
00446       {
00447         lstrcpy(msg, messageID);
00448       }
00449 
00450       ListBox_InsertString(GetDlgItem(hWnd, ID_LIST_RESULT), 0, msg);
00451   }
00452 
00453   wsprintf(msg, "Enumeration ended: Return code %d from MAPIFindNext\nCondition=[%s]", 
00454                     rc, GetMAPIError(rc));
00455   ShowMessage(hWnd, msg);
00456   SetFooter("Enumeration ended");
00457 }
00458 
00459 void
00460 DoMAPIReadMail(HWND hWnd)
00461 {
00462   ULONG (FAR PASCAL *lpfnMAPIReadMail) (LHANDLE lhSession, ULONG ulUIParam, 
00463            LPTSTR lpszMessageID, FLAGS flFlags, ULONG ulReserved, 
00464            lpMapiMessage FAR * lppMessage);
00465 
00466 #ifdef WIN16         
00467   (FARPROC&) lpfnMAPIReadMail = GetProcAddress(m_hInstMapi, "MAPIREADMAIL"); 
00468 #else
00469   (FARPROC&) lpfnMAPIReadMail = GetProcAddress(m_hInstMapi, "MAPIReadMail"); 
00470 #endif
00471   
00472   if (!lpfnMAPIReadMail)
00473   {
00474     ShowMessage(hWnd, "Unable to locate MAPI function.");
00475     return;
00476   }
00477 
00478   char            msg[1024];
00479   char            lpszMessageID[512];
00480   lpMapiMessage   lpMessage = NULL;
00481   FLAGS           flFlags = 0;
00482 
00483   DWORD selected = ListBox_GetCurSel(GetDlgItem(hWnd, ID_LIST_RESULT));
00484   if (selected == LB_ERR)
00485   {
00486     ShowMessage(hWnd, "You need to select a valid message. Make sure\nyou have done a MAPIFindNext and selected\none of the resulting messages.");
00487     return;
00488   }
00489 
00490   ListBox_GetText(GetDlgItem(hWnd, ID_LIST_RESULT), selected, lpszMessageID);
00491 
00492   // Do the various flags for this call...
00493   if (BST_CHECKED == Button_GetCheck(GetDlgItem(hWnd, IDC_CHECK_BODYASFILE)))
00494   {
00495     flFlags |= MAPI_BODY_AS_FILE;
00496   }
00497 
00498   if (BST_CHECKED == Button_GetCheck(GetDlgItem(hWnd, IDC_CHECK_ENVELOPEONLY)))
00499   {
00500     flFlags |= MAPI_ENVELOPE_ONLY;
00501   }
00502 
00503   if (BST_CHECKED == Button_GetCheck(GetDlgItem(hWnd, IDC_CHECK_PEEK)))
00504   {
00505     flFlags |= MAPI_PEEK;
00506   }
00507   
00508   if (BST_CHECKED == Button_GetCheck(GetDlgItem(hWnd, IDC_CHECK_SUPPRESSATTACH)))
00509   {
00510     flFlags |= MAPI_SUPPRESS_ATTACH;
00511   }
00512 
00513   char *ptr = strchr( (const char *) lpszMessageID, ':');
00514   if (ptr) *ptr = '\0';
00515 
00516   LONG  rc = (*lpfnMAPIReadMail)
00517           (mapiSession, 
00518           (ULONG) hWnd, 
00519           lpszMessageID,
00520           flFlags,
00521           0, 
00522           &lpMessage);
00523 
00524   // Deal with error up front and return if need be...
00525   if (rc != SUCCESS_SUCCESS)
00526   {
00527     wsprintf(msg, "FAILURE: Return code %x from MAPIReadMail\nError=[%s]", 
00528                       rc, GetMAPIError(rc));
00529 
00530     ShowMessage(hWnd, msg);
00531     SetFooter("ReadMail failed");
00532     return;
00533   }
00534 
00535   // Now display the message and then return...
00536   DisplayMAPIReadMail(hWnd, lpMessage);
00537   DoMAPIFreeBuffer(hWnd, lpMessage, TRUE);
00538 }
00539 
00540 void
00541 DoMAPIDeleteMail(HWND hWnd)
00542 {
00543   ULONG (FAR PASCAL *lpfnMAPIDeleteMail) (LHANDLE lhSession, ULONG ulUIParam, 
00544             LPTSTR lpszMessageID, FLAGS flFlags, ULONG ulReserved);
00545 
00546 #ifdef WIN16         
00547   (FARPROC&) lpfnMAPIDeleteMail = GetProcAddress(m_hInstMapi, "MAPIDELETEMAIL"); 
00548 #else
00549   (FARPROC&) lpfnMAPIDeleteMail = GetProcAddress(m_hInstMapi, "MAPIDeleteMail"); 
00550 #endif
00551   
00552   if (!lpfnMAPIDeleteMail)
00553   {
00554     ShowMessage(hWnd, "Unable to locate MAPI function.");
00555     return;
00556   }
00557  
00558   char            msg[1024];
00559   char            lpszMessageID[512];
00560   lpMapiMessage   lpMessage = NULL;
00561 
00562   DWORD selected = ListBox_GetCurSel(GetDlgItem(hWnd, ID_LIST_RESULT));
00563   if (selected == LB_ERR)
00564   {
00565     ShowMessage(hWnd, "You need to select a valid message. Make sure\nyou have done a MAPIFindNext and selected\none of the resulting messages.");
00566     return;
00567   }
00568 
00569   ListBox_GetText(GetDlgItem(hWnd, ID_LIST_RESULT), selected, lpszMessageID);
00570 
00571   char *ptr = strchr( (const char *) lpszMessageID, ':');
00572   if (ptr) *ptr = '\0';
00573 
00574   LONG  rc = (*lpfnMAPIDeleteMail)
00575           (mapiSession, 
00576           (ULONG) hWnd,
00577           lpszMessageID, 
00578           0,
00579           0);
00580   
00581   // Deal with the return code...
00582   if (rc == SUCCESS_SUCCESS)
00583   {
00584     wsprintf(msg, "Successful deletion");
00585     ShowMessage(hWnd, msg);
00586     SetFooter(msg);  
00587 
00588     // If it worked, refresh the list...
00589     ShowMessage(hWnd, "The message list will now be refreshed\nsince one message was deleted.");
00590     DoMAPIFindNext(hWnd);
00591   }
00592   else
00593   {
00594     wsprintf(msg, "FAILURE: Return code %d from MAPIDeleteMail\nError=[%s]", 
00595                       rc, GetMAPIError(rc));
00596 
00597     ShowMessage(hWnd, msg);
00598     SetFooter("Logoff failed");
00599   }
00600 }
00601 
00602 // This is for the name lookup stuff...
00603 lpMapiRecipDesc       lpRecip = NULL;
00604 
00605 void
00606 DoMAPIResolveName(HWND hWnd)
00607 {
00608   ULONG (FAR PASCAL *lpfnMAPIResolveName) (LHANDLE lhSession, ULONG ulUIParam, 
00609             LPTSTR lpszName, FLAGS flFlags, ULONG ulReserved, 
00610             lpMapiRecipDesc FAR * lppRecip); 
00611 
00612 #ifdef WIN16         
00613   (FARPROC&) lpfnMAPIResolveName = GetProcAddress(m_hInstMapi, "MAPIRESOLVENAME"); 
00614 #else
00615   (FARPROC&) lpfnMAPIResolveName = GetProcAddress(m_hInstMapi, "MAPIResolveName"); 
00616 #endif
00617   
00618   if (!lpfnMAPIResolveName)
00619   {
00620     ShowMessage(hWnd, "Unable to locate MAPI function.");
00621     return;
00622   }
00623 
00624   if (lpRecip != NULL)
00625   {
00626     ShowMessage(hWnd, "We need to free memory from a previous call...");
00627     DoMAPIFreeBuffer(hWnd, lpRecip, TRUE);
00628     lpRecip = NULL;
00629   }
00630 
00631   char        userName[512];
00632   char        msg[1024];
00633   FLAGS       flFlags = 0;    // We support none...
00634 
00635   GetDlgItemText(hWnd, IDC_EDIT_RESOLVENAME, userName, sizeof(userName));
00636   LONG  rc = (*lpfnMAPIResolveName)
00637                       (mapiSession, 
00638                        (ULONG) hWnd, 
00639                        userName,
00640                        flFlags, 
00641                        0, 
00642                        &lpRecip);
00643 
00644   // Deal with error up front and return if need be...
00645   if (rc != SUCCESS_SUCCESS)
00646   {
00647     wsprintf(msg, "FAILURE: Return code %d from DoMAPIResolveName\nError=[%s]", 
00648                       rc, GetMAPIError(rc));
00649 
00650     ShowMessage(hWnd, msg);
00651     SetFooter("DoMAPIResolveName failed");
00652     return;
00653   }
00654 
00655   // If we get here, we should probably show the information that we
00656   // got back
00657   wsprintf(msg, "Received information for %s\nName=[%s]\nAddress=[%s]\nID=[%s]",
00658     userName, lpRecip->lpszName, lpRecip->lpszAddress, (LPSTR) lpRecip->lpEntryID);
00659   ShowMessage(hWnd, msg);
00660 }
00661 
00662 void    
00663 DoMAPIResolveNameFreeBuffer(HWND hWnd)
00664 {
00665   if (lpRecip == NULL)
00666   {
00667     ShowMessage(hWnd, "There is no memory allocated from MAPIResolveName()\nto be freed. Request ignored.");
00668   }
00669   else
00670   {
00671     DoMAPIFreeBuffer(hWnd, lpRecip, TRUE);
00672     lpRecip = NULL;
00673   }
00674 }
00675 
00676 void
00677 DoMAPIDetails(HWND hWnd)
00678 {
00679   ULONG (FAR PASCAL *lpfnMAPIDetails) (LHANDLE lhSession, ULONG ulUIParam, 
00680             lpMapiRecipDesc lpRecip, FLAGS flFlags, ULONG ulReserved);
00681 
00682 #ifdef WIN16         
00683   (FARPROC&) lpfnMAPIDetails = GetProcAddress(m_hInstMapi, "MAPIDetails"); 
00684 #else
00685   (FARPROC&) lpfnMAPIDetails = GetProcAddress(m_hInstMapi, "MAPIDetails"); 
00686 #endif
00687   
00688   if (!lpfnMAPIDetails)
00689   {
00690     ShowMessage(hWnd, "Unable to locate MAPI function.");
00691     return;
00692   }
00693 
00694   char        msg[1024];
00695   FLAGS       flFlags = 0;    // We really don't support these...
00696 
00697   LONG  rc = (*lpfnMAPIDetails)
00698               (mapiSession, 
00699               (ULONG) hWnd,
00700                lpRecip,
00701                flFlags,
00702                0);
00703 
00704   if (rc == SUCCESS_SUCCESS)
00705   {
00706 
00707     wsprintf(msg, "MAPIDetails call succeeded");
00708     ShowMessage(hWnd, msg);
00709     SetFooter(msg);
00710   }
00711   else
00712   {
00713 
00714     wsprintf(msg, "FAILURE: Return code %d from MAPIDetails\nError=[%s]", 
00715                       rc, GetMAPIError(rc));
00716 
00717     if (lpRecip == NULL)
00718     {
00719       lstrcat(msg, "\nNOTE: There is no valid pointer from a MAPIResolveName()\ncall to show details about.");
00720     }
00721 
00722     ShowMessage(hWnd, msg);
00723     SetFooter("MAPIDetails failed");
00724   }
00725 }
00726 
00727 lpMapiMessage 
00728 GetMessage(HWND hWnd, LPSTR id)
00729 {
00730   ULONG (FAR PASCAL *lpfnMAPIReadMail) (LHANDLE lhSession, ULONG ulUIParam, 
00731            LPTSTR lpszMessageID, FLAGS flFlags, ULONG ulReserved, 
00732            lpMapiMessage FAR * lppMessage);
00733 
00734 #ifdef WIN16         
00735   (FARPROC&) lpfnMAPIReadMail = GetProcAddress(m_hInstMapi, "MAPIREADMAIL"); 
00736 #else
00737   (FARPROC&) lpfnMAPIReadMail = GetProcAddress(m_hInstMapi, "MAPIReadMail"); 
00738 #endif
00739   
00740   if (!lpfnMAPIReadMail)
00741   {
00742     ShowMessage(hWnd, "Unable to locate MAPI function.");
00743     return NULL;
00744   }
00745 
00746   char            msg[1024];
00747   lpMapiMessage   lpMessage = NULL;
00748   FLAGS           flFlags = 0;
00749 
00750   flFlags |= MAPI_ENVELOPE_ONLY;
00751   LONG  rc = (*lpfnMAPIReadMail)
00752           (mapiSession, 
00753           (ULONG) hWnd, 
00754           id,
00755           flFlags,
00756           0, 
00757           &lpMessage);
00758 
00759   // Deal with error up front and return if need be...
00760   if (rc != SUCCESS_SUCCESS)
00761   {
00762     wsprintf(msg, "FAILURE: Return code %x from MAPIReadMail\nError=[%s]", 
00763                       rc, GetMAPIError(rc));
00764 
00765     ShowMessage(hWnd, msg);
00766     SetFooter("ReadMail failed");
00767     return NULL;
00768   }
00769 
00770   return(lpMessage);
00771 }
00772 
00773 void    
00774 LoadNSCPVersionFunc(HWND hWnd)
00775 {
00776   ULONG (FAR PASCAL *lpfnLoadNSCPVersion) ( void );
00777 
00778 #ifdef WIN16         
00779   (FARPROC&) lpfnLoadNSCPVersion = GetProcAddress(m_hInstMapi, "MAPIGETNERSCAPEVERSION"); 
00780 #else
00781   (FARPROC&) lpfnLoadNSCPVersion = GetProcAddress(m_hInstMapi, "MAPIGetNetscapeVersion"); 
00782 #endif
00783   
00784   if (!lpfnLoadNSCPVersion)
00785   {
00786     ShowMessage(hWnd, "Unable to locate MAPIGetNetscapeVersion() function.");
00787   }
00788   else
00789   {
00790     ShowMessage(hWnd, "MAPIGetNetscapeVersion() function was FOUND!");
00791   }
00792   return;
00793 }
00794 
00795 void    
00796 DoMAPI_NSCP_Sync(HWND hWnd)
00797 {
00798 ULONG (FAR PASCAL *lpfnNSCPSync) ( LHANDLE lhSession,
00799                                           ULONG ulReserved );
00800 #ifdef WIN16         
00801   (FARPROC&) lpfnNSCPSync = GetProcAddress(m_hInstMapi, "MAPI_NSCP_SYNCHRONIZECLIENT"); 
00802 #else
00803   (FARPROC&) lpfnNSCPSync = GetProcAddress(m_hInstMapi, "MAPI_NSCP_SynchronizeClient"); 
00804 #endif
00805 
00806   if (!lpfnNSCPSync)
00807   {
00808     ShowMessage(hWnd, "Unable to locate MAPI function.");
00809     return;
00810   }
00811 
00812   LONG  rc = (*lpfnNSCPSync) (mapiSession, 0);
00813 
00814   char    msg[256];
00815 
00816   // Deal with error up front and return if need be...
00817   if (rc != SUCCESS_SUCCESS)
00818   {
00819     wsprintf(msg, "FAILURE: Return code %d from MAPI_NSCP_SynchronizeClient\nError=[%s]", 
00820                       rc, GetMAPIError(rc));
00821 
00822     ShowMessage(hWnd, msg);
00823     SetFooter("MAPI_NSCP_SynchronizeClient failed");
00824     return;
00825   }
00826   else
00827   {
00828     wsprintf(msg, "Success for MAPI_NSCP_SynchronizeClient");    
00829     ShowMessage(hWnd, msg);
00830     SetFooter("MAPI_NSCP_SynchronizeClient success");
00831   }
00832 }