home *** CD-ROM | disk | FTP | other *** search
- *************************************************************
- *
- * Copyright (C) 1994, Tom Snell
- * (408) 475-8667
- * 860 Pine Tree Lane
- * Aptos, CA 95003
- * tcs@netcom.com
- *
- * Not for commercial use.
- * You may modify this code for your own use as desired.
- *
- * !!! WARNING: YOU MUST READ THIS FIRST. THIS WILL NOT RUN
- * WITHOUT FIRST CREATING THE TWO .DBF FILES DESCRIBED BELOW !!!
- *
- * This has not been broadly tested, especially with other email systems.
- * Therefore It would be appreciated that, if others find that they have to make
- * changes for it to work in their environments, that they please send me
- * well commented code changes. This should include a discussion of the
- * nature of the environment within which the change(s) were made.
- * Data samples for such changes would also be important for testing purposes.
- * If I get good code correcting common difficulties,
- * I will consider making at least one revision in a month or two.
- *
- * Thanks!
- *
- * FOXMAIL.PRG
- *
- * This .PRG reads in a text file containing email items from
- * FOXPRO-L@polarbear.rankin-inlet.nt.ca . What I do is save
- * all fox email
- * messages for a single day in one text file. If I am using
- * the Unix "mail" program, and messages 12 thru 28 were foxPro
- * messages I would do something like:
- * & s 12-28 foxpro.txt
- * I then download that file to my PC, in my case,
- * sz foxpro.txt
- *
- * Then, run FOXMAIL.PRG.
- *
- * Note: You may have to modify FOXMAIL to fit your needs. What
- * I am giving you is VERY simple with no error checks, no network
- * capability, etc. At the very least you may have to modify the
- * code that specifies which files are being USEd.
- *
- * I have tried to clearly mark the areas that you will want to recode
- * for yourselves. (I'm just too lazy on this little project
- * to do the fancy stuff).
-
- * FOXMAIL will ask you where the file is that you downloaded from
- * your email system. It then loads the file into a line by line
- * dbf file (one field only of 120 characters, so that each line
- * of text is one record).
-
- * This is then processed to produce Foxmail.DBF which is where
- * all your information is kept.
-
-
-
- * Two tables are required for this program, as shown below
-
- * FOXMAIL.DBF
- * Structure for table: d:\foxwork\software\dbfs\foxmail.dbf
- * Number of data records: 234
- * Date of last update: 01/20/94
- * Memo file block size: 64
- * Field Field Name Type Width Dec Index
- * 1 FROM Character 80 Asc
- * 2 REPLY_TO Character 10
- * 3 REFERENCES Character 80 Asc
- * 4 MESS_ID Character 80
- * 5 DATE Character 20
- * 6 SOURCE Character 10
- * 7 SUBJECT Character 80 Asc
- * 8 X_MAILSERV Character 10
- * 9 X_ARTICLE Character 6
- * 10 MESSAGE Memo 10
- * 11 INPUT_DT Date 8
- * ** Total ** 395
-
- * INDEXES:
- * first index tag is called SUBJECT and is coded as follows:
- * IIF(UPPER(subject)="RE:",LTRIM(SUBSTR(subject,5)),subject)
- *
- * this index is very important because it keeps things organized
- * by subject, even if you have "Re: " in front of the subject
- * description.
-
- * other useful index tags are the following fields:
- * REFERENCES
- * FROM
- * with no special coding.
-
- * TEST120.DBF
- * Structure for table: d:\foxwork\software\dbfs\text120.dbf
- * Number of data records: 740
- * Date of last update: 01/20/94
- * Field Field Name Type Width Dec Index
- * 1 TEXT Character 120
- * ** Total ** 121
- *
- ********************************************************************
-
-
-
- PRIVATE FIRST_TIME, FILENAME, MY_TEXT, THE_TEXT, M.MESS, REC_FLAG, ;
- MY_SAFETY, DBF_FILE
- REC_FLAG = .F.
- FIRST_TIME = .T.
- M.MESS = ""
-
-
- *****************************************************************
- * change the DEFAULT and PATH to where you have stored the .DBF files
- *****************************************************************
-
- SET DEFAULT TO d:\foxwork\software\dbfs
- SET PATH TO d:\foxwork\software\dbfs
- CLEAR
-
-
- MY_SAFETY = SET('SAFETY')
- SET SAFETY OFF
- SELECT 0
- dbf_file = GETFILE('DBF', 'Please select FOXMAIL.DBF')
- DO CASE
- CASE EMPTY(dbf_file)
- RETURN
- OTHERWISE
- USE (dbf_file) ALIAS FOXMAIL EXCLUSIVE
- ENDCASE
-
- INDEX ON IIF(UPPER(subject)="RE:",LTRIM(SUBSTR(subject,5)),subject) TAG Subject ADDITIVE
- SET ORDER TO
-
- SELECT 0
- dbf_file = GETFILE('DBF', 'Please select TEXT120.DBF')
- DO CASE
- CASE EMPTY(dbf_file)
- RETURN
- OTHERWISE
- USE (dbf_file) ALIAS TEXT EXCLUSIVE
- ENDCASE
- ZAP
- SET SAFETY &MY_SAFETY
-
-
- FILENAME = LOCFILE('ANYFILE', 'TXT', 'Select email file to import')
- APPEND FROM (FILENAME) TYPE SDF
-
-
- SET EXACT OFF
- SELECT TEXT
- GO TOP
- DO WHILE .NOT. EOF()
-
- THE_TEXT = ALLTRIM(TEXT)
- MY_TEXT = UPPER(THE_TEXT)
-
- * throw away all the preliminary header stuff.
- * when you get to the first real 'from:', start
- * a new record in foxmail to hold the data for
- * this email message.
-
- * start storing data in foxmail.
- *** DO WHILE .NOT. EOF() .AND. MY_TEXT != "STATUS:"
- DO CASE
- CASE MY_TEXT = "FROM OWNER-FOXPRO"
- CASE MY_TEXT = "RETURN-PATH:"
- CASE MY_TEXT = "RECEIVED:"
- * received lines may have additional lines after
- * them to discard. To check for this below, we
- * must flag that a "Received: " line has just been
- * processed.
- REC_FLAG = .T.
- CASE MY_TEXT = "SENDER:"
- CASE MY_TEXT = "TO:"
- CASE MY_TEXT = "STATUS:"
- CASE MY_TEXT = "FROM:"
- IF .NOT. ("NAME: " $ MY_TEXT)
- IF !FIRST_TIME
- REPLACE FOXMAIL.MESSAGE WITH M.MESS
- ELSE
- FIRST_TIME = .F.
- ENDIF
- SELECT FOXMAIL
- APPEND BLANK
- M.MESS = ""
- SELECT TEXT
- THE_TEXT = RIGHT(THE_TEXT, LEN(THE_TEXT)-6)
- REPLACE FOXMAIL.FROM WITH ALLTRIM(THE_TEXT), ;
- FOXMAIL.INPUT_DT WITH DATE()
- ENDIF
- CASE MY_TEXT = "NAME:"
- THE_TEXT = RIGHT(THE_TEXT, LEN(THE_TEXT)-12)
- REPLACE FOXMAIL.REFERENCES WITH ALLTRIM(THE_TEXT)
- CASE MY_TEXT = "REPLY-TO:"
- DO CASE
- CASE '"The FoxPro (tm) Mailing List"' $ THE_TEXT
- THE_TEXT = "FML"
- OTHERWISE
- THE_TEXT = "???"
- ENDCASE
- REPLACE FOXMAIL.REPLY_TO WITH ALLTRIM(THE_TEXT)
- CASE MY_TEXT = "REFERENCES:"
- THE_TEXT = RIGHT(THE_TEXT, LEN(THE_TEXT)-12)
- REPLACE FOXMAIL.REFERENCES WITH ALLTRIM(THE_TEXT)
- CASE MY_TEXT = "MESSAGE-ID:"
- THE_TEXT = RIGHT(THE_TEXT, LEN(THE_TEXT)-12)
- REPLACE FOXMAIL.MESS_ID WITH ALLTRIM(THE_TEXT)
- CASE MY_TEXT = "DATE:"
- THE_TEXT = RIGHT(THE_TEXT, LEN(THE_TEXT)-6)
- THE_TEXT = LEFT(THE_TEXT, AT(':',THE_TEXT)-3)
- REPLACE FOXMAIL.DATE WITH ALLTRIM(THE_TEXT)
- CASE MY_TEXT = "ORGANIZATION:"
- DO CASE
- CASE 'Polar Bear Heaven BBS' $ THE_TEXT
- THE_TEXT = "PBH"
- OTHERWISE
- THE_TEXT = "???"
- ENDCASE
- REPLACE FOXMAIL.SOURCE WITH ALLTRIM(THE_TEXT)
- CASE MY_TEXT = "SUBJECT:"
- THE_TEXT = ALLTRIM(RIGHT(THE_TEXT, LEN(THE_TEXT)-9))
- * get rid of any extra RE:s in this line -
- * leave only one, if one exists. For sorting
- * purposes to keep subject messages together.
- DO WHILE ATC("RE:", THE_TEXT, 2) > 0
- THE_TEXT = ALLTRIM(RIGHT(THE_TEXT, LEN(THE_TEXT)-3))
- ENDDO
- REPLACE FOXMAIL.SUBJECT WITH ALLTRIM(THE_TEXT)
- CASE MY_TEXT = "X-MAILSERVER:"
- DO CASE
- CASE 'Waffle File Server' $ THE_TEXT
- THE_TEXT = "WFS"
- OTHERWISE
- THE_TEXT = "???"
- ENDCASE
- REPLACE FOXMAIL.X_MAILSERV WITH ALLTRIM(THE_TEXT)
- CASE MY_TEXT = "X-ARTICLE:"
- THE_TEXT = RIGHT(THE_TEXT, LEN(THE_TEXT)-11)
- REPLACE FOXMAIL.X_ARTICLE WITH ALLTRIM(THE_TEXT)
- OTHERWISE
- * "Received" lines sometimes have additional lines
- * after them that should not appear in the output
- * text. This checks for those lines and by passes
- * them. They all start with either a tab or a space
- * and come immediately after a "Received:".
- IF REC_FLAG .AND. (LEFT(TEXT, 1) = " " ;
- .OR. LEFT(TEXT, 1) = CHR(9))
- REC_FLAG = .F.
- * check for a possible second line.
- SKIP
- IF !(LEFT(TEXT, 1) = " " ;
- .OR. LEFT(TEXT, 1) = CHR(9))
- SKIP -1 && no 2nd line, go back one.
- ENDIF
- ELSE
- * now process the message itself
- M.MESS = M.MESS + THE_TEXT + CHR(13) + CHR(10)
- ENDIF
- ENDCASE
- SKIP
- ENDDO
-
- * don't forget to catch the last message!
- SKIP -1
- REPLACE FOXMAIL.MESSAGE WITH M.MESS
-
-
-
- WAIT WINDOW 'scan the most recent items at the bottom of the file.'
- SELECT FOXMAIL
- SET ORDER TO
- BROWSE LAST
-
- WAIT WINDOW 'look at the list in SUBJECT index order.'
- SELECT FOXMAIL
- SET ORDER TO TAG SUBJECT
- BROWSE LAST
-
- ***************************************************************************
- * you may want to change this so that your file stays open.
- ***************************************************************************
- * SELECT FOXMAIL
- * USE
- * SELECT TEXT
- * USE
-
- RETURN
-
-