home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / xbase / library / fox / workgrp / mapilib.prg < prev    next >
Text File  |  1993-08-27  |  16KB  |  517 lines

  1.  
  2. * MAPILIB.PRG
  3. * **************************************************
  4. * The MAPILIB.PRG file is a reusable FoxPro file
  5. * containing generic function calls to the functions
  6. * included in the FOXMAPI.FLL library.
  7. *
  8. * The MAPILIB library is actually just a set of
  9. * functions to which you can add, edit or delete.
  10. * The MAPILIB.PRG file works in conjunction with
  11. * the MAPIERR.PRG error handling file.
  12. * **************************************************
  13. * Calling Protocols:
  14. *   ex. =MAPILIB(fname,p1,p2,...)
  15. *   fname -- is the function name
  16. *   p1,p2,etc. -- parameters passed to function
  17. * **************************************************
  18. * Notes: This file is distributed solely to provide
  19. * sample guidelines for using the FOXMAPI library
  20. * calls. Microsoft is not responsible for the code
  21. * contained in any of its sample files and does
  22. * not provide support for these sample files. See
  23. * the included Help file for further assistance
  24. * regarding technical or other support.
  25. * **************************************************
  26.  
  27.  
  28. **************Compiler Directives*************
  29.  
  30. *Misc directives
  31. #DEFINE ok                RETURN .T.
  32. #DEFINE fail            RETURN .F.
  33. #DEFINE w_title          "FoxPro Mail"
  34. #DEFINE mapihelpfile     "FOXMAPI.HLP"
  35.  
  36. * Message Box Definitions
  37. #DEFINE mb_ok                0
  38. #DEFINE mb_yesno            4
  39. #DEFINE is_yes              6
  40. #DEFINE mb_iconhand            16
  41. #DEFINE mb_iconquestion        32
  42. #DEFINE mb_iconexcl         48
  43. #DEFINE mb_iconasterisk     64
  44. #DEFINE mb_title            "Microsoft FoxPro"
  45.  
  46. *MAPI FLAGS
  47. *Note: not all are used in these libraries
  48. #DEFINE mp_logon_ui                       1
  49. #DEFINE mp_new_session                    2
  50. #DEFINE mp_dialog                         8
  51. #DEFINE mp_unread_only                    32
  52. #DEFINE mp_envelope_only                  64
  53. #DEFINE mp_peek                           128
  54. #DEFINE mp_guarantee_fifo                256
  55. #DEFINE    mp_body_as_file                    512
  56. #DEFINE mp_ab_nomodify                    1024
  57. #DEFINE    mp_suppress_attach                2048
  58. #DEFINE    mp_force_download                4096
  59.  
  60. #DEFINE    mp_ole                            1
  61. #DEFINE    mp_ole_static                    2
  62.  
  63. #DEFINE mp_orig                           0
  64. #DEFINE mp_to                             1
  65. #DEFINE mp_cc                             2
  66. #DEFINE mp_bcc                            3
  67.  
  68. #DEFINE mp_unread                         1
  69. #DEFINE mp_receipt_requested              2
  70. #DEFINE mp_sent                           4
  71.  
  72.  
  73. *SCHEDULE+ FLAGS
  74. *Note: these are here for future use
  75. #DEFINE    sp_no_request_sent                0
  76. #DEFINE    sp_no_response                    1
  77. #DEFINE    sp_positive_response            2
  78. #DEFINE    sp_negative_response            3
  79. #DEFINE    sp_ambiguous_response            4
  80. #DEFINE    sp_response_requested            65536
  81. #DEFINE    sp_private                        1
  82. #DEFINE    sp_tentative                    4
  83. #DEFINE    sp_prv_project                    2
  84. #DEFINE    sp_boss_wants_copy                1
  85. #DEFINE    sp_default_alarm                4096
  86. #DEFINE    sp_mod_flags                    65536
  87. #DEFINE    sp_mod_assoc                    131072
  88. #DEFINE    sp_mod_attendees                262144
  89. #DEFINE    sp_mod_text                        524288
  90. #DEFINE    sp_mod_times                    4194304
  91. #DEFINE    sp_mod_project_name                8388608
  92. #DEFINE    sp_mod_priority                    16777216
  93. #DEFINE    sp_mod_all                        33488896
  94. #DEFINE    sp_suppress_recipients            4096
  95.  
  96.  
  97. PARAMETER fname,p1,p2,p3,p4,p5,p6
  98.  
  99. IF EMPTY(m.fname)
  100.     fail
  101. ENDIF
  102. RETURN &fname()
  103.  
  104.  
  105.  
  106. *!*********************************************************************
  107. *!
  108. *!      FUNCTION: setlib
  109. *!
  110. *!*********************************************************************
  111. * Function checks to see if library provided in
  112. * in P1 is active. If not, it tries to set library.
  113. * Note: this function is used quite extensively
  114. * since most FOXMAPI calls can be made without
  115. * explicitly calling the MPLogon function.
  116. FUNCTION setlib
  117.     PARAMETER libname
  118.     IF ! UPPER(m.libname) $ SET('LIBRARY')
  119.         ON ERROR *      &&traps for cancel button
  120.         SET LIBRARY TO LOCFILE(m.libname,'FLL','Locate file '+UPPER(m.libname)) ADDITIVE
  121.         ON ERROR
  122.         IF !UPPER(m.libname) $ SET('LIBRARY')
  123.             *wrong library entered or cancel button pressed
  124.             WAIT WINDOW 'Operation cancelled or incorrect library selected.'
  125.             fail
  126.         ENDIF
  127.     ENDIF
  128.     ok
  129.  
  130.  
  131.     *!*********************************************************************
  132.     *!
  133.     *!      FUNCTION: logon
  134.     *!
  135.     *!*********************************************************************
  136.     * Function logs onto MS Mail and returns
  137.     * the session channel (integer). You should
  138.     * keep track of the channel returned for
  139.     * additional calls.
  140. FUNCTION logon
  141.     PRIVATE hsession,retval
  142.     hsession=0
  143.     IF !setlib('foxmapi.fll')
  144.         fail
  145.     ENDIF
  146.     retval=mplogon(0,"","",mp_logon_ui+mp_new_session,0,@hsession)
  147.     RETURN IIF(mapierr(m.retval),m.hsession,0)
  148.  
  149.  
  150.     *!*********************************************************************
  151.     *!
  152.     *!      FUNCTION: logoff
  153.     *!
  154.     *!*********************************************************************
  155.     * Program logs off MS Mail
  156.     * Note: if you choose, you can add code
  157.     * to release library at the end here.
  158.     * P1 - optional session channel returned
  159.     *   from MPLogon above.
  160. FUNCTION logoff
  161.     PRIVATE retval
  162.     IF EMPTY(m.p1) OR TYPE('p1')#'N'
  163.         fail
  164.     ENDIF
  165.     retval=mplogoff(m.p1,0,0,0)
  166.     RETURN mapierr(m.retval)
  167.  
  168.  
  169.     *!*********************************************************************
  170.     *!
  171.     *!      FUNCTION: sendnote
  172.     *!
  173.     *!*********************************************************************
  174.     * Sends a new message without files.
  175.     * Since no FOXMAPI cursors are used, a dialog is
  176.     * always presented to allow input and recipient names.
  177.     * Note: you can optionally attach files by modifying
  178.     * this function. See the help file for more details.
  179. FUNCTION sendnote
  180.     PRIVATE retval
  181.     IF !setlib('foxmapi.fll')
  182.         fail
  183.     ENDIF
  184.     retval=mpsenddocs(0,";","","",0)
  185.     RETURN mapierr(m.retval)
  186.  
  187.  
  188.     *!*********************************************************************
  189.     *!
  190.     *!      FUNCTION: savenote
  191.     *!
  192.     *!*********************************************************************
  193.     * Saves a mail message and returns a valid
  194.     * message id number or empty string if failed.
  195.     * Note: this only saves the message to your
  196.     * in box. You must use MPSendMail to actually
  197.     * send it (see sendmail function).
  198.     * P1 - session channel (optional)
  199.     * P2 - mapiMesg cursor name (optional)
  200.     * P3 - mapiRecip cursor name (optional)
  201.     * P4 - mapiFile cursor name (optional)
  202. FUNCTION savenote
  203.     PRIVATE hsession,messcurs,recicurs,filecurs,retval
  204.     IF !setlib('foxmapi.fll')
  205.         fail
  206.     ENDIF
  207.     hsession=IIF(TYPE('P1')#'N',0,m.p1)
  208.     messid=''
  209.     messcurs=IIF(!EMPTY(m.p2) AND TYPE('P2')='C',m.p2,'mapiMesg')
  210.     recicurs=IIF(!EMPTY(m.p3) AND TYPE('P3')='C',m.p3,'mapiRecip')
  211.     filecurs=IIF(!EMPTY(m.p4) AND TYPE('P4')='C',m.p4,'mapiFile')
  212.     retval=mpsavemail(m.hsession,0,m.messcurs,m.recicurs,;
  213.         m.filecurs,0,0,@messid)
  214.     RETURN IIF(mapierr(m.retval),m.messid,'')
  215.  
  216.  
  217.     *!*********************************************************************
  218.     *!
  219.     *!      FUNCTION: resolve
  220.     *!
  221.     *!*********************************************************************
  222.     * This function calls the resolve dialog to
  223.     * resolve ambiguous names. If the mail
  224.     * name or address can be resolved no
  225.     * dialog is presented. This function creates
  226.     * a mapiRecip cursor containing the address
  227.     * information of the selected recipient.
  228.     * P1 - session channel (optional)
  229.     * P2 - name to resolve (required)
  230.     * P3 - mapiRecip cursor name (optional)
  231. FUNCTION resolve
  232.     IF !setlib('foxmapi.fll') OR EMPTY(p2)
  233.         fail
  234.     ENDIF
  235.     PRIVATE hsession,recicurs,retval
  236.     hsession=IIF(TYPE('P1')#'N',0,m.p1)
  237.     recicurs=IIF(!EMPTY(m.p3) AND TYPE('P3')='C',m.p3,'mapiRecip')
  238.     retval=mpresolve(m.hsession,0,m.p2,;
  239.         mp_logon_ui+mp_dialog,0,m.recicurs)
  240.     RETURN mapierr(m.retval)
  241.  
  242.  
  243.     *!*********************************************************************
  244.     *!
  245.     *!      FUNCTION: addbook
  246.     *!
  247.     *!*********************************************************************
  248.     * This function opens MS MAIL address book
  249.     * for the user to select recipients. It is
  250.     * more flexibile than MPResolve in that, you
  251.     * can specifiy more than one recipient and
  252.     * the type of message (e.g., To: or Cc:). As
  253.     * with MPResolve, a mapiRecip cursor is created
  254.     * with all the names selected.
  255. FUNCTION addbook
  256.     IF !setlib('foxmapi.fll')
  257.         fail
  258.     ENDIF
  259.     PRIVATE hsession,hlevel,recicurs,retval
  260.     hsession=IIF(TYPE('P1')#'N',0,m.p1)
  261.     hlevel = IIF(TYPE('P2')#'N',4,m.p2)
  262.     recicurs=IIF(!EMPTY(m.p3) AND TYPE('P3')='C',m.p3,'mapiRecip')
  263.     nrecips=0
  264.     retval=mpaddress(m.hsession,0,w_title,m.hlevel,"",;
  265.         @nrecips,m.recicurs,mp_logon_ui,0)
  266.     RETURN mapierr(m.retval)
  267.  
  268.  
  269.     *!*********************************************************************
  270.     *!
  271.     *!      FUNCTION: getnextnote
  272.     *!
  273.     *!*********************************************************************
  274.     * Gets the next message given a starting
  275.     * position. This call uses two of the
  276.     * FOXMAPI function. The first locates the
  277.     * next available message. The second reads
  278.     * it into the cursors, which in this case
  279.     * are simply the default ones. The messageid
  280.     * is returned if successful read. If not successful
  281.     * such as after last message, then null string returned.
  282.     * P1 - session channel (optional)
  283.     * P2 - message id starting position (optional)
  284.     * P3 - message type (IPC or IPM <default>)
  285. FUNCTION getnextnote
  286.     PRIVATE hsession,messid,mespos,retval,mtype
  287.     hsession=IIF(TYPE('P1')#'N',0,m.p1)
  288.     mespos=IIF(EMPTY(m.p2),"",m.p2)
  289.     mtype=IIF(EMPTY(m.p3),"",m.p3)
  290.     messid=SPACE(100)
  291.     retval=mpfindnext(m.hsession,0,m.mtype,m.mespos,0,0,@messid)
  292.     IF retval#0
  293.         RETURN ''
  294.     ENDIF
  295.     messid=ALLTRIM(m.messid)
  296.     retval=mpreadmail(m.hsession,0,m.messid,0,0,;
  297.         "mapiMesg","mapiOrig","mapiRecip","mapiFile")
  298.     RETURN IIF(mapierr(m.retval),m.messid,'')
  299.  
  300.  
  301.     *!*********************************************************************
  302.     *!
  303.     *!      FUNCTION: deleteall
  304.     *!
  305.     *!*********************************************************************
  306.     * Deletes all messages in mail box
  307.     * P1 - session channel (optional)
  308. FUNCTION deleteall
  309.     PRIVATE hsession,messid,oldmess,retval
  310.     hsession=IIF(TYPE('P1')#'N',0,m.p1)
  311.     oldmess=''
  312.     DO WHILE .T.
  313.         messid=SPACE(100)
  314.         retval=mpfindnext(m.hsession,0,"",m.oldmess,0,0,@messid)
  315.         IF EMPTY(m.messid) OR !EMPTY(m.retval)
  316.             EXIT
  317.         ENDIF
  318.         messid=ALLTRIM(m.messid)
  319.         retval=mpdelete(m.hsession,0,m.messid,0,0)
  320.         oldmess=m.messid
  321.     ENDDO
  322.     RETURN mapierr(m.retval)
  323.  
  324.  
  325.     *!*********************************************************************
  326.     *!
  327.     *!      FUNCTION: readnote
  328.     *!
  329.     *!*********************************************************************
  330.     * Reads a message given a message id. This is the
  331.     * main routine to use for retrieving new messages
  332.     * P1 - session channel (optional)
  333.     * P2 - message id (required)
  334.     * P3 - mapiMesg cursor name (optional)
  335.     * P4 - mapiOrig cursor name (optional)
  336.     * P5 - mapiRecip cursor name (optional)
  337.     * P6 - mapiFile cursor name (optional)
  338. FUNCTION readnote
  339.     IF !setlib('foxmapi.fll') OR EMPTY(m.p2)
  340.         fail
  341.     ENDIF
  342.     PRIVATE hsession,messid,messcurs,recicurs,filecurs,origcurs,retval
  343.     hsession=IIF(TYPE('P1')#'N',0,m.p1)
  344.     messid=ALLTRIM(m.p2)
  345.     messcurs=IIF(!EMPTY(m.p3) AND TYPE('P3')='C',m.p3,'mapiMesg')
  346.     origcurs=IIF(!EMPTY(m.p4) AND TYPE('P4')='C',m.p4,'mapiOrig')
  347.     recicurs=IIF(!EMPTY(m.p5) AND TYPE('P5')='C',m.p5,'mapiRecip')
  348.     filecurs=IIF(!EMPTY(m.p6) AND TYPE('P6')='C',m.p6,'mapiFile')
  349.     retval=mpreadmail(m.hsession,0,m.messid,0,0,;
  350.         m.messcurs,m.origcurs,m.recicurs,m.filecurs)
  351.     RETURN mapierr(m.retval)
  352.  
  353.  
  354.     *!*********************************************************************
  355.     *!
  356.     *!      FUNCTION: sendmail
  357.     *!
  358.     *!*********************************************************************
  359.     * Edits/Sends a message. This function will bring up a
  360.     * dialog if the no flags (P5) specified to allow for
  361.     * editing.
  362.     * P1 - session channel (optional)
  363.     * P2 - mapiMesg cursor name (optional)
  364.     * P3 - mapiRecip cursor name (optional)
  365.     * P4 - mapiFile cursor name (optional)
  366.     * P5 - flags for sending message
  367. FUNCTION sendmail
  368.     IF !setlib('foxmapi.fll')
  369.         fail
  370.     ENDIF
  371.     PRIVATE hsession,messcurs,recicurs,filecurs,mpflags,retval
  372.     hsession=IIF(TYPE('P1')#'N',0,m.p1)
  373.     messcurs=IIF(!EMPTY(m.p2) AND TYPE('P2')='C',m.p2,'mapiMesg')
  374.     recicurs=IIF(!EMPTY(m.p3) AND TYPE('P3')='C',m.p3,'mapiRecip')
  375.     filecurs=IIF(!EMPTY(m.p4) AND TYPE('P4')='C',m.p4,'mapiFile')
  376.     mpflags =IIF(TYPE('P5')='N',m.p5,;
  377.         mp_logon_ui+mp_dialog)
  378.     retval=mpsendmail(m.hsession,0,m.messcurs,m.recicurs,;
  379.         m.filecurs,m.mpflags,0)
  380.     RETURN mapierr(m.retval)
  381.  
  382.  
  383.     *!*********************************************************************
  384.     *!
  385.     *!      FUNCTION: deletenote
  386.     *!
  387.     *!*********************************************************************
  388.     * Deletes a message given a specific message id.
  389.     * P1 - session channel (optional)
  390.     * P2 - message id (required)
  391. FUNCTION deletenote
  392.     IF !setlib('foxmapi.fll') OR EMPTY(m.p2)
  393.         fail
  394.     ENDIF
  395.     PRIVATE hsession,retval
  396.     hsession=IIF(TYPE('P1')#'N',0,m.p1)
  397.     retval=mpdelete(m.hsession,0,m.p2,0,0)
  398.     RETURN mapierr(m.retval)
  399.  
  400.  
  401.     *!*********************************************************************
  402.     *!
  403.     *!      FUNCTION: details
  404.     *!
  405.     *!*********************************************************************
  406.     * Brings up the Mail details dialog
  407.     * P1 - session channel (optional)
  408.     * P2 - mapiRecip cursor name (optional)
  409. FUNCTION details
  410.     IF !setlib('foxmapi.fll')
  411.         fail
  412.     ENDIF
  413.     PRIVATE hsession,retval,recicurs
  414.     hsession=IIF(TYPE('P1')#'N',0,m.p1)
  415.     recicurs=IIF(!EMPTY(m.p2) AND TYPE('P2')='C',m.p2,'mapiRecip')
  416.     retval=mpdetails(m.hsession,0,m.recicurs,mp_logon_ui,0)
  417.     RETURN mapierr(m.retval)
  418.  
  419.  
  420.     *!*********************************************************************
  421.     *!
  422.     *!      FUNCTION: newcursor
  423.     *!
  424.     *!*********************************************************************
  425.     * Creates a cursor of one of the MAPI data structures.
  426.     * The following are valid types:
  427.     *   mapiMesg mapiFile mapiRecip
  428.     * Since MPCursor will not do anything if the
  429.     * cursor already exists, we want to close it
  430.     * and open a new one just in case the cursor
  431.     * was of a different type.
  432.     * P1 - cursor type
  433.     * P2 - cursor name (optional)
  434. FUNCTION newcursor
  435.     PRIVATE getalias
  436.     DO CASE
  437.         CASE !setlib('foxmapi.fll')
  438.             fail
  439.         CASE !INLIST(UPPER(m.p1),'MAPIMESG','MAPIFILE','MAPIRECIP')
  440.             fail
  441.     ENDCASE
  442.     getalias=IIF(EMPTY(m.p2) OR TYPE('P2')#'C',m.p1,m.p2)
  443.     IF USED(m.getalias)
  444.         USE IN (getalias)
  445.     ENDIF
  446.     retval=mpcursor(m.p1,m.getalias)
  447.     ok
  448.  
  449.  
  450.     *!*********************************************************************
  451.     *!
  452.     *!      FUNCTION: mailhelp
  453.     *!
  454.     *!*********************************************************************
  455.     *Displays the FOXMAPI Help file
  456. FUNCTION mailhelp
  457.     PRIVATE getmapihelp
  458.     ON ERROR *      &&traps for cancel button
  459.     getmapihelp = LOCFILE(mapihelpfile ,'HLP','Locate '+mapihelpfile)
  460.     ON ERROR
  461.     IF mapihelpfile $ getmapihelp
  462.         RUN /N winhelp &getmapihelp
  463.     ENDIF
  464.  
  465.  
  466.     *!*********************************************************************
  467.     *!
  468.     *!      FUNCTION: mpalert
  469.     *!
  470.     *!*********************************************************************
  471.     * Brings up a Yes/No alert dialog
  472. FUNCTION mpalert
  473.     PRIVATE waitvar
  474.     IF setlib(SYS(2004)+'foxtools.fll')
  475.         RETURN msgbox(p1,mb_title,mb_yesno+mb_iconquestion)=is_yes
  476.     ELSE
  477.         WAIT WINDOW p1+'(Y/N)' TO waitvar
  478.         RETURN waitvar$'Yy'
  479.     ENDIF
  480.  
  481.  
  482.     *!*********************************************************************
  483.     *!
  484.     *!      FUNCTION: mpinfo
  485.     *!
  486.     *!*********************************************************************
  487.     * Brings up an OK info alert
  488. FUNCTION mpinfo
  489.     PRIVATE waitvar
  490.     IF setlib(SYS(2004)+'foxtools.fll')
  491.         =msgbox(p1,mb_title,mb_ok + mb_iconexcl)
  492.     ELSE
  493.         WAIT WINDOW p1
  494.     ENDIF
  495.  
  496.  
  497.     *!*********************************************************************
  498.     *!
  499.     *!      FUNCTION: getdate
  500.     *!
  501.     *!*********************************************************************
  502.     * Date/Time stamp used for DateReceived field of
  503.     * mapiMesg cursor.
  504. FUNCTION getdate
  505.     PRIVATE getdate,olddate,oldcentury,oldhours
  506.     olddate=SET('date')
  507.     oldcentury=SET('century')
  508.     oldhours=SET('HOURS')
  509.     SET DATE TO YMD
  510.     SET CENTURY ON
  511.     SET HOURS TO 24
  512.     getdate=DTOC(DATE())+' '+LEFT(TIME(),5)
  513.     SET DATE TO &olddate
  514.     SET CENTURY &oldcentury
  515.     SET HOURS TO &oldhours
  516.     RETURN getdate
  517.