home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / virus / ddj0491.zip / MSMAIL.ASC < prev    next >
Text File  |  1991-03-15  |  5KB  |  184 lines

  1. _EXAMINING THE MICROSOFT MAIL SDK_
  2. by Bruce D. Schatzman
  3.  
  4. [LISTING ONE]
  5.  
  6. #include <MacHeaders>
  7. #include "MAPILib.h"
  8. #include "MAPIErrs.h"
  9. #include "stuffit.h"
  10.  
  11. extern char string[256];
  12. extern arcRecord *myArc;
  13. extern WindowPtr windows[8];
  14. extern EventRecord pss;
  15. extern HParamBlockRec HRec;
  16.  
  17. SendMail()
  18. {
  19.     int i, j;
  20.     MessHdl messh;
  21.     Handle datah;
  22.     SFReply myReply;
  23.  
  24.     i = msmSessionEstablished ();
  25.     if ( i )
  26.     {
  27.         MSMError ( i );
  28.         return;
  29.     }
  30.  
  31.     i = msmCreateMess ( &messh, 'Mess' );
  32.     
  33.     /*  the message was successfully created */
  34.     if ( i == 0 )
  35.     {
  36.         i=PtrToHand ( &myArc->arcName[1], &datah, myArc->arcName[0] );
  37.                     /* Add archive name as subject */
  38.         if ( i == 0 )
  39.         {
  40.             i = msmAddMessSubject ( messh, datah );
  41.             DisposHandle ( datah );
  42.         }
  43.         if( i== 0)     /*add default body */
  44.         {
  45.            GetIndString ( string, 260, 1 ); 
  46.            i = PtrToHand ( &string[1], &datah, string[0] );
  47.            if ( i == 0 )  i = msmAddMessBody( messh, datah );
  48.            DisposHandle ( datah );
  49.         }
  50.  
  51.         /*  Now add the archive as an enclosure */
  52.         HRec.wdParam.ioNamePtr = 0L;
  53.         HRec.wdParam.ioVRefNum = myArc->arcVol;
  54.         HRec.wdParam.ioWDProcID = 'SIT! ';
  55.         HRec.wdParam.ioWDDirID = myArc->arcDir;
  56.  
  57.         PBOpenWD ( &HRec, FALSE );
  58.  
  59.         i = msmAddMessEnclosure ( messh, myArc->arcName, 
  60.                          j = HRec.wdParam.ioVRefNum, 0L );
  61.  
  62.         /*  Now find out where to send it */
  63.         if ( i == 0 )
  64.         {
  65.             i = msmDisplaySendDocScreen ( messh );
  66.             /*  this now disposes of messh.. */
  67.         }
  68.         else
  69.         {
  70.         /*  we're done with it  */
  71.         msmDisposeMess ( messh );
  72.         }
  73.         HRec.wdParam.ioVRefNum = j;
  74.         PBCloseWD ( &HRec, FALSE );
  75.     }
  76.     if ( i == msmTErrCancelled )  i = 0;
  77.     if ( i )  MSError ( i );
  78. }
  79.  
  80. OpenMail ()
  81. {
  82.     int i, numItems, j, vol;
  83.     long dir;
  84.     SFTypeList myList;
  85.     Handle resh;
  86.     SFReply myReply;
  87.     char str[32];
  88.     int numOpen = 0;
  89.     Point startPt;
  90.  
  91.     i = msmSessionEstablished ();
  92.     if ( i )
  93.         MSMError ( i );
  94.         return;
  95.     }
  96.  
  97. /*  How many archives are open now ? */
  98.     for ( i = 0; i < 8 ; i++)
  99.     {
  100.         if ( windows[i] ) numOpen++;
  101.     }
  102.     myList[0] = 'SIT! ';
  103.     myList[1] = 'SIT2 ';
  104.     myList[2] = 'SITD ';
  105.  
  106.     i = msmDisplayMessageCenter (3, myList, 0L, 0, &resh);
  107.     
  108.     if ( i == 0)
  109.     {
  110.         EventAvail ( 0, &pss );
  111.         numItems = msmGetListNumEnclosures ( resh );
  112.         for ( j = 0; j < numItems && i == 0; ++j )
  113.             {
  114.                 i = msmGetListEnclosureName (resh, j , 
  115.                             (StringPtr) string );
  116.                 if ( i == 0 )
  117.                 {
  118.             GetIndString (str, 260, 2); /* "Save enclosure as :" */
  119.             startPt.h = (screenBits.bounds.right - 
  120.                         screenBits.bounds.left) / 2 - 158;
  121.             startPt.v = 80;
  122.             SFPutFile ( startPt, (StringPtr) str, (StringPtr) 
  123.                          string, (ProcPtr) oL, &myReply );
  124.             if ( myReply.good )
  125.             {
  126.             if ( i == 0 )
  127.             i = msmGetListEnclosure ( resh, j, TRUE, 
  128.                      myReply.fName, myReply.vRefNum, &myReply);
  129.             if (( i == 0 ) && ( numOpen < 8 )) 
  130.                        /* open archive if room permits */
  131.               {
  132.             StartSpinCursor ();
  133.             GetWDVolDir ( myReply.vRefNum, &vol, &dir );
  134.             if ( !ActualOpen (vol, dir, myReply.fName, 0L, 0, 
  135.                               0L, pss.modifiers ))
  136.             break;
  137.             if ( pss.modifiers & shiftKey )
  138.             DoAutoUnsit ( FALSE );
  139.             AutoView ();
  140.             numOpen++;
  141.             StopSpinCursor ();
  142.                }
  143.                if ( i == 0)
  144.                 i = msmGetListEnclosureComments ( resh, j );
  145.                 }
  146.               }
  147.             }
  148.             StopSpinCursor ();
  149.                 DisposHandle ( resh );
  150.             }
  151.  
  152.             if ( i == msmTErrCancelled )  i = 0;
  153.             if ( i )  MSMError ( i );
  154. }
  155.  
  156. MSMError ( i )
  157. {
  158.     char str2[256];
  159.     NumToString ( i, (StringPtr) string );
  160.     switch ( i )
  161.     {
  162.         case msmNoDriver:
  163.             GetIndString ( str2, 259, 3 );
  164.             /*  "MS Mail was not loaded at startup. " */
  165.             break;
  166.         case msmNoServer:
  167.             GetIndString (str2, 259, 1 );
  168.             /*  "You are not connected to a MS Mail server. "  */
  169.             break;
  170.         case msmDErrNotLoggedOn:
  171.             GetIndString (str2, 259, 13 );
  172.             /*  "You are not logged onto the MS Mail server. " */
  173.             break;
  174.         default:
  175.             GetIndString ( str2, 259, 2 );
  176.             /* " Miscellaneous MS Mail Error. "  */
  177.             break;
  178.     }
  179.     ParamText (str2, string, 0, 0 );
  180.     StopCAlert ( 296, 0L );
  181. }
  182.  
  183.  
  184.