home *** CD-ROM | disk | FTP | other *** search
-
- * MAPILIB.PRG
- * **************************************************
- * The MAPILIB.PRG file is a reusable FoxPro file
- * containing generic function calls to the functions
- * included in the FOXMAPI.FLL library.
- *
- * The MAPILIB library is actually just a set of
- * functions to which you can add, edit or delete.
- * The MAPILIB.PRG file works in conjunction with
- * the MAPIERR.PRG error handling file.
- * **************************************************
- * Calling Protocols:
- * ex. =MAPILIB(fname,p1,p2,...)
- * fname -- is the function name
- * p1,p2,etc. -- parameters passed to function
- * **************************************************
- * Notes: This file is distributed solely to provide
- * sample guidelines for using the FOXMAPI library
- * calls. Microsoft is not responsible for the code
- * contained in any of its sample files and does
- * not provide support for these sample files. See
- * the included Help file for further assistance
- * regarding technical or other support.
- * **************************************************
-
-
- **************Compiler Directives*************
-
- *Misc directives
- #DEFINE ok RETURN .T.
- #DEFINE fail RETURN .F.
- #DEFINE w_title "FoxPro Mail"
- #DEFINE mapihelpfile "FOXMAPI.HLP"
-
- * Message Box Definitions
- #DEFINE mb_ok 0
- #DEFINE mb_yesno 4
- #DEFINE is_yes 6
- #DEFINE mb_iconhand 16
- #DEFINE mb_iconquestion 32
- #DEFINE mb_iconexcl 48
- #DEFINE mb_iconasterisk 64
- #DEFINE mb_title "Microsoft FoxPro"
-
- *MAPI FLAGS
- *Note: not all are used in these libraries
- #DEFINE mp_logon_ui 1
- #DEFINE mp_new_session 2
- #DEFINE mp_dialog 8
- #DEFINE mp_unread_only 32
- #DEFINE mp_envelope_only 64
- #DEFINE mp_peek 128
- #DEFINE mp_guarantee_fifo 256
- #DEFINE mp_body_as_file 512
- #DEFINE mp_ab_nomodify 1024
- #DEFINE mp_suppress_attach 2048
- #DEFINE mp_force_download 4096
-
- #DEFINE mp_ole 1
- #DEFINE mp_ole_static 2
-
- #DEFINE mp_orig 0
- #DEFINE mp_to 1
- #DEFINE mp_cc 2
- #DEFINE mp_bcc 3
-
- #DEFINE mp_unread 1
- #DEFINE mp_receipt_requested 2
- #DEFINE mp_sent 4
-
-
- *SCHEDULE+ FLAGS
- *Note: these are here for future use
- #DEFINE sp_no_request_sent 0
- #DEFINE sp_no_response 1
- #DEFINE sp_positive_response 2
- #DEFINE sp_negative_response 3
- #DEFINE sp_ambiguous_response 4
- #DEFINE sp_response_requested 65536
- #DEFINE sp_private 1
- #DEFINE sp_tentative 4
- #DEFINE sp_prv_project 2
- #DEFINE sp_boss_wants_copy 1
- #DEFINE sp_default_alarm 4096
- #DEFINE sp_mod_flags 65536
- #DEFINE sp_mod_assoc 131072
- #DEFINE sp_mod_attendees 262144
- #DEFINE sp_mod_text 524288
- #DEFINE sp_mod_times 4194304
- #DEFINE sp_mod_project_name 8388608
- #DEFINE sp_mod_priority 16777216
- #DEFINE sp_mod_all 33488896
- #DEFINE sp_suppress_recipients 4096
-
-
- PARAMETER fname,p1,p2,p3,p4,p5,p6
-
- IF EMPTY(m.fname)
- fail
- ENDIF
- RETURN &fname()
-
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: setlib
- *!
- *!*********************************************************************
- * Function checks to see if library provided in
- * in P1 is active. If not, it tries to set library.
- * Note: this function is used quite extensively
- * since most FOXMAPI calls can be made without
- * explicitly calling the MPLogon function.
- FUNCTION setlib
- PARAMETER libname
- IF ! UPPER(m.libname) $ SET('LIBRARY')
- ON ERROR * &&traps for cancel button
- SET LIBRARY TO LOCFILE(m.libname,'FLL','Locate file '+UPPER(m.libname)) ADDITIVE
- ON ERROR
- IF !UPPER(m.libname) $ SET('LIBRARY')
- *wrong library entered or cancel button pressed
- WAIT WINDOW 'Operation cancelled or incorrect library selected.'
- fail
- ENDIF
- ENDIF
- ok
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: logon
- *!
- *!*********************************************************************
- * Function logs onto MS Mail and returns
- * the session channel (integer). You should
- * keep track of the channel returned for
- * additional calls.
- FUNCTION logon
- PRIVATE hsession,retval
- hsession=0
- IF !setlib('foxmapi.fll')
- fail
- ENDIF
- retval=mplogon(0,"","",mp_logon_ui+mp_new_session,0,@hsession)
- RETURN IIF(mapierr(m.retval),m.hsession,0)
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: logoff
- *!
- *!*********************************************************************
- * Program logs off MS Mail
- * Note: if you choose, you can add code
- * to release library at the end here.
- * P1 - optional session channel returned
- * from MPLogon above.
- FUNCTION logoff
- PRIVATE retval
- IF EMPTY(m.p1) OR TYPE('p1')#'N'
- fail
- ENDIF
- retval=mplogoff(m.p1,0,0,0)
- RETURN mapierr(m.retval)
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: sendnote
- *!
- *!*********************************************************************
- * Sends a new message without files.
- * Since no FOXMAPI cursors are used, a dialog is
- * always presented to allow input and recipient names.
- * Note: you can optionally attach files by modifying
- * this function. See the help file for more details.
- FUNCTION sendnote
- PRIVATE retval
- IF !setlib('foxmapi.fll')
- fail
- ENDIF
- retval=mpsenddocs(0,";","","",0)
- RETURN mapierr(m.retval)
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: savenote
- *!
- *!*********************************************************************
- * Saves a mail message and returns a valid
- * message id number or empty string if failed.
- * Note: this only saves the message to your
- * in box. You must use MPSendMail to actually
- * send it (see sendmail function).
- * P1 - session channel (optional)
- * P2 - mapiMesg cursor name (optional)
- * P3 - mapiRecip cursor name (optional)
- * P4 - mapiFile cursor name (optional)
- FUNCTION savenote
- PRIVATE hsession,messcurs,recicurs,filecurs,retval
- IF !setlib('foxmapi.fll')
- fail
- ENDIF
- hsession=IIF(TYPE('P1')#'N',0,m.p1)
- messid=''
- messcurs=IIF(!EMPTY(m.p2) AND TYPE('P2')='C',m.p2,'mapiMesg')
- recicurs=IIF(!EMPTY(m.p3) AND TYPE('P3')='C',m.p3,'mapiRecip')
- filecurs=IIF(!EMPTY(m.p4) AND TYPE('P4')='C',m.p4,'mapiFile')
- retval=mpsavemail(m.hsession,0,m.messcurs,m.recicurs,;
- m.filecurs,0,0,@messid)
- RETURN IIF(mapierr(m.retval),m.messid,'')
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: resolve
- *!
- *!*********************************************************************
- * This function calls the resolve dialog to
- * resolve ambiguous names. If the mail
- * name or address can be resolved no
- * dialog is presented. This function creates
- * a mapiRecip cursor containing the address
- * information of the selected recipient.
- * P1 - session channel (optional)
- * P2 - name to resolve (required)
- * P3 - mapiRecip cursor name (optional)
- FUNCTION resolve
- IF !setlib('foxmapi.fll') OR EMPTY(p2)
- fail
- ENDIF
- PRIVATE hsession,recicurs,retval
- hsession=IIF(TYPE('P1')#'N',0,m.p1)
- recicurs=IIF(!EMPTY(m.p3) AND TYPE('P3')='C',m.p3,'mapiRecip')
- retval=mpresolve(m.hsession,0,m.p2,;
- mp_logon_ui+mp_dialog,0,m.recicurs)
- RETURN mapierr(m.retval)
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: addbook
- *!
- *!*********************************************************************
- * This function opens MS MAIL address book
- * for the user to select recipients. It is
- * more flexibile than MPResolve in that, you
- * can specifiy more than one recipient and
- * the type of message (e.g., To: or Cc:). As
- * with MPResolve, a mapiRecip cursor is created
- * with all the names selected.
- FUNCTION addbook
- IF !setlib('foxmapi.fll')
- fail
- ENDIF
- PRIVATE hsession,hlevel,recicurs,retval
- hsession=IIF(TYPE('P1')#'N',0,m.p1)
- hlevel = IIF(TYPE('P2')#'N',4,m.p2)
- recicurs=IIF(!EMPTY(m.p3) AND TYPE('P3')='C',m.p3,'mapiRecip')
- nrecips=0
- retval=mpaddress(m.hsession,0,w_title,m.hlevel,"",;
- @nrecips,m.recicurs,mp_logon_ui,0)
- RETURN mapierr(m.retval)
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: getnextnote
- *!
- *!*********************************************************************
- * Gets the next message given a starting
- * position. This call uses two of the
- * FOXMAPI function. The first locates the
- * next available message. The second reads
- * it into the cursors, which in this case
- * are simply the default ones. The messageid
- * is returned if successful read. If not successful
- * such as after last message, then null string returned.
- * P1 - session channel (optional)
- * P2 - message id starting position (optional)
- * P3 - message type (IPC or IPM <default>)
- FUNCTION getnextnote
- PRIVATE hsession,messid,mespos,retval,mtype
- hsession=IIF(TYPE('P1')#'N',0,m.p1)
- mespos=IIF(EMPTY(m.p2),"",m.p2)
- mtype=IIF(EMPTY(m.p3),"",m.p3)
- messid=SPACE(100)
- retval=mpfindnext(m.hsession,0,m.mtype,m.mespos,0,0,@messid)
- IF retval#0
- RETURN ''
- ENDIF
- messid=ALLTRIM(m.messid)
- retval=mpreadmail(m.hsession,0,m.messid,0,0,;
- "mapiMesg","mapiOrig","mapiRecip","mapiFile")
- RETURN IIF(mapierr(m.retval),m.messid,'')
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: deleteall
- *!
- *!*********************************************************************
- * Deletes all messages in mail box
- * P1 - session channel (optional)
- FUNCTION deleteall
- PRIVATE hsession,messid,oldmess,retval
- hsession=IIF(TYPE('P1')#'N',0,m.p1)
- oldmess=''
- DO WHILE .T.
- messid=SPACE(100)
- retval=mpfindnext(m.hsession,0,"",m.oldmess,0,0,@messid)
- IF EMPTY(m.messid) OR !EMPTY(m.retval)
- EXIT
- ENDIF
- messid=ALLTRIM(m.messid)
- retval=mpdelete(m.hsession,0,m.messid,0,0)
- oldmess=m.messid
- ENDDO
- RETURN mapierr(m.retval)
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: readnote
- *!
- *!*********************************************************************
- * Reads a message given a message id. This is the
- * main routine to use for retrieving new messages
- * P1 - session channel (optional)
- * P2 - message id (required)
- * P3 - mapiMesg cursor name (optional)
- * P4 - mapiOrig cursor name (optional)
- * P5 - mapiRecip cursor name (optional)
- * P6 - mapiFile cursor name (optional)
- FUNCTION readnote
- IF !setlib('foxmapi.fll') OR EMPTY(m.p2)
- fail
- ENDIF
- PRIVATE hsession,messid,messcurs,recicurs,filecurs,origcurs,retval
- hsession=IIF(TYPE('P1')#'N',0,m.p1)
- messid=ALLTRIM(m.p2)
- messcurs=IIF(!EMPTY(m.p3) AND TYPE('P3')='C',m.p3,'mapiMesg')
- origcurs=IIF(!EMPTY(m.p4) AND TYPE('P4')='C',m.p4,'mapiOrig')
- recicurs=IIF(!EMPTY(m.p5) AND TYPE('P5')='C',m.p5,'mapiRecip')
- filecurs=IIF(!EMPTY(m.p6) AND TYPE('P6')='C',m.p6,'mapiFile')
- retval=mpreadmail(m.hsession,0,m.messid,0,0,;
- m.messcurs,m.origcurs,m.recicurs,m.filecurs)
- RETURN mapierr(m.retval)
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: sendmail
- *!
- *!*********************************************************************
- * Edits/Sends a message. This function will bring up a
- * dialog if the no flags (P5) specified to allow for
- * editing.
- * P1 - session channel (optional)
- * P2 - mapiMesg cursor name (optional)
- * P3 - mapiRecip cursor name (optional)
- * P4 - mapiFile cursor name (optional)
- * P5 - flags for sending message
- FUNCTION sendmail
- IF !setlib('foxmapi.fll')
- fail
- ENDIF
- PRIVATE hsession,messcurs,recicurs,filecurs,mpflags,retval
- hsession=IIF(TYPE('P1')#'N',0,m.p1)
- messcurs=IIF(!EMPTY(m.p2) AND TYPE('P2')='C',m.p2,'mapiMesg')
- recicurs=IIF(!EMPTY(m.p3) AND TYPE('P3')='C',m.p3,'mapiRecip')
- filecurs=IIF(!EMPTY(m.p4) AND TYPE('P4')='C',m.p4,'mapiFile')
- mpflags =IIF(TYPE('P5')='N',m.p5,;
- mp_logon_ui+mp_dialog)
- retval=mpsendmail(m.hsession,0,m.messcurs,m.recicurs,;
- m.filecurs,m.mpflags,0)
- RETURN mapierr(m.retval)
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: deletenote
- *!
- *!*********************************************************************
- * Deletes a message given a specific message id.
- * P1 - session channel (optional)
- * P2 - message id (required)
- FUNCTION deletenote
- IF !setlib('foxmapi.fll') OR EMPTY(m.p2)
- fail
- ENDIF
- PRIVATE hsession,retval
- hsession=IIF(TYPE('P1')#'N',0,m.p1)
- retval=mpdelete(m.hsession,0,m.p2,0,0)
- RETURN mapierr(m.retval)
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: details
- *!
- *!*********************************************************************
- * Brings up the Mail details dialog
- * P1 - session channel (optional)
- * P2 - mapiRecip cursor name (optional)
- FUNCTION details
- IF !setlib('foxmapi.fll')
- fail
- ENDIF
- PRIVATE hsession,retval,recicurs
- hsession=IIF(TYPE('P1')#'N',0,m.p1)
- recicurs=IIF(!EMPTY(m.p2) AND TYPE('P2')='C',m.p2,'mapiRecip')
- retval=mpdetails(m.hsession,0,m.recicurs,mp_logon_ui,0)
- RETURN mapierr(m.retval)
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: newcursor
- *!
- *!*********************************************************************
- * Creates a cursor of one of the MAPI data structures.
- * The following are valid types:
- * mapiMesg mapiFile mapiRecip
- * Since MPCursor will not do anything if the
- * cursor already exists, we want to close it
- * and open a new one just in case the cursor
- * was of a different type.
- * P1 - cursor type
- * P2 - cursor name (optional)
- FUNCTION newcursor
- PRIVATE getalias
- DO CASE
- CASE !setlib('foxmapi.fll')
- fail
- CASE !INLIST(UPPER(m.p1),'MAPIMESG','MAPIFILE','MAPIRECIP')
- fail
- ENDCASE
- getalias=IIF(EMPTY(m.p2) OR TYPE('P2')#'C',m.p1,m.p2)
- IF USED(m.getalias)
- USE IN (getalias)
- ENDIF
- retval=mpcursor(m.p1,m.getalias)
- ok
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: mailhelp
- *!
- *!*********************************************************************
- *Displays the FOXMAPI Help file
- FUNCTION mailhelp
- PRIVATE getmapihelp
- ON ERROR * &&traps for cancel button
- getmapihelp = LOCFILE(mapihelpfile ,'HLP','Locate '+mapihelpfile)
- ON ERROR
- IF mapihelpfile $ getmapihelp
- RUN /N winhelp &getmapihelp
- ENDIF
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: mpalert
- *!
- *!*********************************************************************
- * Brings up a Yes/No alert dialog
- FUNCTION mpalert
- PRIVATE waitvar
- IF setlib(SYS(2004)+'foxtools.fll')
- RETURN msgbox(p1,mb_title,mb_yesno+mb_iconquestion)=is_yes
- ELSE
- WAIT WINDOW p1+'(Y/N)' TO waitvar
- RETURN waitvar$'Yy'
- ENDIF
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: mpinfo
- *!
- *!*********************************************************************
- * Brings up an OK info alert
- FUNCTION mpinfo
- PRIVATE waitvar
- IF setlib(SYS(2004)+'foxtools.fll')
- =msgbox(p1,mb_title,mb_ok + mb_iconexcl)
- ELSE
- WAIT WINDOW p1
- ENDIF
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: getdate
- *!
- *!*********************************************************************
- * Date/Time stamp used for DateReceived field of
- * mapiMesg cursor.
- FUNCTION getdate
- PRIVATE getdate,olddate,oldcentury,oldhours
- olddate=SET('date')
- oldcentury=SET('century')
- oldhours=SET('HOURS')
- SET DATE TO YMD
- SET CENTURY ON
- SET HOURS TO 24
- getdate=DTOC(DATE())+' '+LEFT(TIME(),5)
- SET DATE TO &olddate
- SET CENTURY &oldcentury
- SET HOURS TO &oldhours
- RETURN getdate
-