home *** CD-ROM | disk | FTP | other *** search
- * Readmail.prg
- *
- * This program controls the Read Mail menu option.
- * FoxPro uses MAPI calls to retrieve all messages
- * in the inbox. They are then displayed in a FoxPro
- * dialog for further editing.
-
- PRIVATE oldsafe,oldexact,origin,messnum,messageid,;
- oldmessid,islogon,filepick,getid,oldtalk,morigin,retval
-
- IF SET("TALK") = "ON"
- SET TALK OFF
- m.oldtalk= "ON"
- ELSE
- m.oldtalk= "OFF"
- ENDIF
-
- * Mailsession variable is a FoxPro defined
- * public variable used to store the MS MAIL
- * session channel for use with subsequent mail
- * calls. The Islogon variable is set TRUE if a
- * session (saved in Mailsession) is already running
- islogon=.F.
- DO CASE
- CASE TYPE('mailsession')#'N'
- PUBLIC mailsession
- mailsession = 0
- mailsession=mapilib('LOGON')
- CASE m.mailsession=0
- mailsession=mapilib('LOGON')
- OTHERWISE
- islogon=.T.
- ENDCASE
-
- IF m.mailsession=0 &&failed to logon, so return
- SET TALK &oldtalk
- RETURN
- ENDIF
-
- * Now setup variables for program
- DIMENSION filearr[1]
- DIMENSION reciparr[1]
- reciparr=''
- recippick=''
- origin = ''
- oldmessid = ""
- messageid = ""
- morigin = ""
- messnum = 1
- oldsafe = SET('SAFETY')
- oldexact = SET('EXACT')
- olddelete = SET('DELETE')
- SET SAFETY OFF
- SET EXACT ON
- SET DELETE ON
-
- * This is a database cursor used to
- * save all the messages from the mapiMesg
- * cursor. Three add'l fields are added at
- * the end. The origin is used to store address
- * of message originator. The messnum is unique
- * key used in relations with other databases below.
- CREATE CURSOR MESSAGES ;
- (reserved N(10),;
- subject C(254),;
- notetext m,;
- messagtype C(254),;
- daterecved C(16),;
- convertnid C(254),;
- flags N(10),;
- recipcount N(10),;
- filecount N(10),;
- origin C(254),;
- messnum N(4),;
- messageid C(100))
-
- * This cursor stores recipients associated
- * with each message. This is a 1-Many child
- * file with messages.
- CREATE CURSOR recips;
- (messnum N(4),;
- recipclass N (1),;
- address C(254))
-
- * The files database store file attachments
- * for each message. This is also 1-Many file.
- CREATE CURSOR FILES ;
- (reserved N(10),;
- flags N(10),;
- position N(10),;
- pathname C(254),;
- filename C(254),;
- filetype C(254),;
- messnum N(4))
-
- * Create a cursor to store each unique
- * address in messages.
- =mapilib('newcursor','mapirecip','addresses')
- INDEX ON address TAG address
-
- * This is core program which continues to
- * loop through messages until all are read.
- * The getnextnote function basically calls
- * the MPFindNext and MPReadMail functions
- * to retrieve and then read mail. Note that
- * oldmessid is initially set to null string.
- WAIT WINDOW 'Reading mail...' NOWAIT
- DO WHILE .T.
- messageid = mapilib('getnextnote',m.mailsession,m.oldmessid)
- IF EMPTY(m.messageid)
- EXIT
- ENDIF
- DO process_message
- oldmessid = m.messageid
- messnum = m.messnum+1
- ENDDO
- WAIT CLEAR
-
- IF RECCOUNT('messages')=0
- WAIT WINDOW 'No messages were available.'
- ELSE
- SELECT MESSAGES
- GO TOP
- DO fileselect && this routine sets arrays
- DO readmail.spr && call screen
- DO cleanup
- ENDIF
-
- *Finished with screen, now cleanup
- IF !islogon
- =mapilib('LOGOFF',m.mailsession)
- mailsession = 0
- ENDIF
- SET SAFETY &oldsafe
- SET EXACT &oldexact
- SET DELETE &olddelete
- SET TALK &oldtalk
-
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: cleanup
- *!
- *!*********************************************************************
- * clean up here at the end
- * IMPORTANT!!! The MPReadMail function creates temp
- * files for all mail attachments. You must dispose of them
- * when done reading the mail. If you don't, each time you
- * reread mail, a new temp file is created which could be a
- * duplicate of one already there.
- PROCEDURE cleanup
- SELECT FILES
- SCAN
- DELETE FILE (pathname)
- ENDSCAN
- USE IN addresses
- USE IN FILES
- USE IN recips
- USE IN MESSAGES
- USE IN mapimesg
- USE IN mapirecip
- USE IN mapiorig
- USE IN mapifile
- IF USED('detailreci')
- USE IN detailreci
- ENDIF
- RETURN
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: btnval
- *!
- *!*********************************************************************
- * This procedure handles the VALID statement for
- * the navigational buttons.
- PROCEDURE btnval
- DO CASE
- CASE m.btn1 = 1 &&Previous Message
- SKIP -1
- IF BOF()
- WAIT WINDOW 'Top of file.' NOWAIT
- GO TOP
- ENDIF
- CASE m.btn1 = 2 &&Browse locate
- DEFINE WINDOW messwind FROM 1,1 TO 15,35;
- SYSTEM GROW CLOSE ZOOM FLOAT
- MOVE WINDOW messwind CENTER
- BROWSE WINDOW messwind NOEDIT NODELETE NOMENU ;
- FONT 'ms sans serif',10 ;
- FIELD subject TITLE 'Select Message'
- RELEASE WINDOW messwind
- CASE m.btn1 = 3 &&Next Message
- SKIP 1
- IF EOF()
- WAIT WINDOW 'Bottom of file.' NOWAIT
- GO BOTTOM
- ENDIF
- ENDCASE
- DO fileselect
- SHOW GETS
- RETURN
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: btn2val
- *!
- *!*********************************************************************
- * This procedure handles the Mail function
- * buttons
- PROCEDURE btn2val
- DO CASE
- CASE m.btn2 = 1
- =mapilib('sendnote')
- CASE m.btn2 = 2
- DO reply_message
- CASE m.btn2 = 3
- DO delete_message
- ENDCASE
- SHOW GETS
- RETURN
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: fileselect
- *!
- *!*********************************************************************
- * This routine refreshes the arrays when the record pointer
- * in the message database is moved. These arrays are used in
- * the recipients and files lists.
- PROCEDURE fileselect
- PRIVATE getmessnum
- getmessnum=messages.messnum
- morigin=LOOKUP(addresses.name,ALLT(messages.origin),addresses.address,'address')
- SELECT DISTINCT filename FROM FILES;
- WHERE files.messnum = m.getmessnum;
- INTO ARRAY filearr
- IF _TALLY=0
- DIMENSION filearr[1]
- filearr=''
- ENDIF
- filepick=0
- SELECT DISTINCT a.name FROM addresses A,recips B;
- WHERE a.address=ALLT(b.address) AND b.messnum = m.getmessnum;
- INTO ARRAY reciparr
- IF _TALLY=0
- DIMENSION reciparr[1]
- reciparr=''
- ENDIF
- recippick=IIF(_TALLY=0,'',reciparr[1])
- RETURN
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: getstatus
- *!
- *!*********************************************************************
- * This function displays the status of a particular message
- * which is determined by the flags fields in the message cursor.
- PROCEDURE getstatus
- PRIVATE getstatus
- DO CASE
- CASE flags=1
- getstatus = '(Unread)'
- CASE flags=2
- getstatus = '(Receipt Requested)'
- CASE flags=3
- getstatus = '(Unread, Receipt Requested)'
- CASE flags=4
- getstatus = '(Sent)'
- CASE flags=5
- getstatus = '(Unread, Sent)'
- CASE flags=6
- getstatus = '(Receipt Requested, Sent)'
- CASE flags=7
- getstatus = '(Unread, Receipt Requested, Sent)'
- OTHERWISE
- getstatus = ''
- ENDCASE
- RETURN getstatus
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: getdetail
- *!
- *!*********************************************************************
- * This calls the MAPI function which displays the mail
- * name details dialog. This is triggered either thru the
- * button next to the origin or the recipient list box.
- PROCEDURE getdetail
- PARAMETER maddress
- IF EMPTY(m.maddress)
- RETURN
- ENDIF
- SELECT addresses
- LOCATE FOR name=ALLTRIM(m.maddress)
- SCATTER MEMVAR MEMO
- IF USED('detailreci')
- SELECT detailreci
- GATHER MEMVAR MEMO
- ELSE
- =mapilib('newcursor','mapirecip','detailreci')
- INSERT INTO detailreci FROM MEMVAR
- ENDIF
- =mapilib('details',m.mailsession,'detailreci')
- SELECT MESSAGES
- RETURN
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: process_message
- *!
- *!*********************************************************************
- * This function is called in the main processing loop
- * which repeated polls for the next message.
- PROCEDURE process_message
- * Check to see if new address in address database,
- * else add it. Do this for both origin and recipient
- * databases.
- SELECT mapiorig
- IF !SEEK(ALLT(address),'addresses')
- SCATTER MEMVAR MEMO
- INSERT INTO addresses FROM MEMVAR
- ENDIF
- m.origin = address
- SELECT mapirecip
- SCAN
- SCATTER MEMVAR MEMO
- IF !SEEK(ALLT(address),'addresses')
- INSERT INTO addresses FROM MEMVAR
- ENDIF
- INSERT INTO recips FROM MEMVAR
- ENDSCAN
- * Now check for files. If files were
- * associated with message add them to
- * files cursor.
- IF mapimesg.filecount#0
- *add file attachments
- SELECT mapifile
- SCAN
- SCATTER MEMVAR MEMO
- INSERT INTO FILES FROM MEMVAR
- ENDSCAN
- ENDIF
- *add new message to messages database
- SELECT mapimesg
- SCATTER MEMVAR MEMO
- INSERT INTO MESSAGES FROM MEMVAR
- RETURN
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: delete_message
- *!
- *!*********************************************************************
- * This function deletes a message (both from Inbox and screen).
- PROCEDURE delete_message
- PRIVATE getnum
- IF !mapilib('mpalert','Delete message?')
- RETURN
- ENDIF
- =mapilib('deletenote',m.mailsession,ALLT(messageid))
- getnum=messnum
- DELETE
- SELECT recips
- DELETE ALL FOR messnum=m.getnum
- * Don't forget to delete temp files.
- SELECT FILES
- SCAN FOR messnum=m.getnum
- DELETE FILE (pathname)
- DELETE
- ENDSCAN
- * Now refresh screen with next record
- SELECT MESSAGES
- SKIP
- IF EOF()
- GO BOTTOM
- ENDIF
- DO fileselect
- RETURN
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: reply_message
- *!
- *!*********************************************************************
- * The reply function opens a selected message in the standard
- * MAPI SendNote dialog for replying to sender. Note: we don't
- * update FoxPro screen here to show change. This would involve
- * deleting current message and then polling for new one.
- PROCEDURE reply_message
- PRIVATE getnum,getorigin
- SELECT MESSAGES
- getnum=messages.messnum
- getorigin=messages.origin
- SCATTER MEMVAR MEMO
- * add a little extra space for replying
- m.notetext=CHR(13)+CHR(13)+CHR(13)+m.notetext
- m.recipcount = 1
- * Add "RE:" as is done with MS Mail when replying
- m.subject = 'RE: '+m.subject
- SELECT mapimesg
- GATHER MEMVAR MEMO
- SELECT mapirecip
- ZAP
- SELECT addresses
- LOCATE FOR address=ALLT(m.getorigin)
- SCATTER MEMVAR MEMO
- * reset class to 1 -- To: class
- m.recipclass = 1 &&set To flag
- INSERT INTO mapirecip FROM MEMVAR
- SELECT mapifile
- ZAP
- IF mapimesg.filecount=0
- APPEND BLANK
- ELSE
- SELECT FILES
- SCAN FOR messnum=m.getnum
- SCATTER MEMVAR MEMO
- INSERT INTO mapifile FROM MEMVAR
- ENDSCAN
- ENDIF
- retval=mapilib("sendmail",m.mailsession,"mapiMesg","mapiRecip","mapiFile")
- SELECT MESSAGES
- RETURN
-