_EXAMINING THE MICROSOFT MAIL SDK_ by Bruce D. Schatzman [LISTING ONE] #include #include "MAPILib.h" #include "MAPIErrs.h" #include "stuffit.h" extern char string[256]; extern arcRecord *myArc; extern WindowPtr windows[8]; extern EventRecord pss; extern HParamBlockRec HRec; SendMail() { int i, j; MessHdl messh; Handle datah; SFReply myReply; i = msmSessionEstablished (); if ( i ) { MSMError ( i ); return; } i = msmCreateMess ( &messh, 'Mess' ); /* the message was successfully created */ if ( i == 0 ) { i=PtrToHand ( &myArc->arcName[1], &datah, myArc->arcName[0] ); /* Add archive name as subject */ if ( i == 0 ) { i = msmAddMessSubject ( messh, datah ); DisposHandle ( datah ); } if( i== 0) /*add default body */ { GetIndString ( string, 260, 1 ); i = PtrToHand ( &string[1], &datah, string[0] ); if ( i == 0 ) i = msmAddMessBody( messh, datah ); DisposHandle ( datah ); } /* Now add the archive as an enclosure */ HRec.wdParam.ioNamePtr = 0L; HRec.wdParam.ioVRefNum = myArc->arcVol; HRec.wdParam.ioWDProcID = 'SIT! '; HRec.wdParam.ioWDDirID = myArc->arcDir; PBOpenWD ( &HRec, FALSE ); i = msmAddMessEnclosure ( messh, myArc->arcName, j = HRec.wdParam.ioVRefNum, 0L ); /* Now find out where to send it */ if ( i == 0 ) { i = msmDisplaySendDocScreen ( messh ); /* this now disposes of messh.. */ } else { /* we're done with it */ msmDisposeMess ( messh ); } HRec.wdParam.ioVRefNum = j; PBCloseWD ( &HRec, FALSE ); } if ( i == msmTErrCancelled ) i = 0; if ( i ) MSError ( i ); } OpenMail () { int i, numItems, j, vol; long dir; SFTypeList myList; Handle resh; SFReply myReply; char str[32]; int numOpen = 0; Point startPt; i = msmSessionEstablished (); if ( i ) MSMError ( i ); return; } /* How many archives are open now ? */ for ( i = 0; i < 8 ; i++) { if ( windows[i] ) numOpen++; } myList[0] = 'SIT! '; myList[1] = 'SIT2 '; myList[2] = 'SITD '; i = msmDisplayMessageCenter (3, myList, 0L, 0, &resh); if ( i == 0) { EventAvail ( 0, &pss ); numItems = msmGetListNumEnclosures ( resh ); for ( j = 0; j < numItems && i == 0; ++j ) { i = msmGetListEnclosureName (resh, j , (StringPtr) string ); if ( i == 0 ) { GetIndString (str, 260, 2); /* "Save enclosure as :" */ startPt.h = (screenBits.bounds.right - screenBits.bounds.left) / 2 - 158; startPt.v = 80; SFPutFile ( startPt, (StringPtr) str, (StringPtr) string, (ProcPtr) oL, &myReply ); if ( myReply.good ) { if ( i == 0 ) i = msmGetListEnclosure ( resh, j, TRUE, myReply.fName, myReply.vRefNum, &myReply); if (( i == 0 ) && ( numOpen < 8 )) /* open archive if room permits */ { StartSpinCursor (); GetWDVolDir ( myReply.vRefNum, &vol, &dir ); if ( !ActualOpen (vol, dir, myReply.fName, 0L, 0, 0L, pss.modifiers )) break; if ( pss.modifiers & shiftKey ) DoAutoUnsit ( FALSE ); AutoView (); numOpen++; StopSpinCursor (); } if ( i == 0) i = msmGetListEnclosureComments ( resh, j ); } } } StopSpinCursor (); DisposHandle ( resh ); } if ( i == msmTErrCancelled ) i = 0; if ( i ) MSMError ( i ); } MSMError ( i ) { char str2[256]; NumToString ( i, (StringPtr) string ); switch ( i ) { case msmNoDriver: GetIndString ( str2, 259, 3 ); /* "MS Mail was not loaded at startup. " */ break; case msmNoServer: GetIndString (str2, 259, 1 ); /* "You are not connected to a MS Mail server. " */ break; case msmDErrNotLoggedOn: GetIndString (str2, 259, 13 ); /* "You are not logged onto the MS Mail server. " */ break; default: GetIndString ( str2, 259, 2 ); /* " Miscellaneous MS Mail Error. " */ break; } ParamText (str2, string, 0, 0 ); StopCAlert ( 296, 0L ); }