home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / FOXMAIL.ZIP / FOXMAIL.PRG next >
Encoding:
Text File  |  1994-01-26  |  10.3 KB  |  291 lines

  1. *************************************************************
  2. *
  3. * Copyright (C) 1994,   Tom Snell
  4. *                       (408) 475-8667
  5. *                                               860 Pine Tree Lane
  6. *                                               Aptos, CA 95003
  7. *                                               tcs@netcom.com
  8. *
  9. * Not for commercial use.
  10. * You may modify this code for your own use as desired.
  11. * !!! WARNING:  YOU MUST READ THIS FIRST.  THIS WILL NOT RUN 
  12. * WITHOUT FIRST CREATING THE TWO .DBF FILES DESCRIBED BELOW !!!
  13. *
  14. * This has not been broadly tested, especially with other email systems.
  15. * Therefore It would be appreciated that, if others find that they have to make
  16. * changes for it to work in their environments, that they please send me
  17. * well commented code changes.  This should include a discussion of the
  18. * nature of the environment within which the change(s) were made.
  19. * Data samples for such changes would also be important for testing purposes.
  20. * If I get good code correcting common difficulties,
  21. * I will consider making at least one revision in a month or two.
  22. *
  23. * Thanks!  
  24. *
  25. * FOXMAIL.PRG
  26. *
  27. * This .PRG reads in a text file containing email items from
  28. * FOXPRO-L@polarbear.rankin-inlet.nt.ca .  What I do is save 
  29. * all fox email
  30. * messages for a single day in one text file.  If I am using
  31. * the Unix "mail" program, and messages 12 thru 28 were foxPro
  32. * messages I would do something like:
  33. *     &   s 12-28 foxpro.txt
  34. * I then download that file to my PC, in my case, 
  35. *     sz foxpro.txt
  36. *
  37. * Then, run FOXMAIL.PRG.  
  38. *
  39. * Note:  You may have to modify FOXMAIL to fit your needs.  What
  40. * I am giving you is VERY simple with no error checks, no network
  41. * capability, etc.  At the very least you may have to modify the
  42. * code that specifies which files are being USEd.
  43. *
  44. * I have tried to clearly mark the areas that you will want to recode
  45. * for yourselves.  (I'm just too lazy on this little project
  46. * to do the fancy stuff).
  47.  
  48. * FOXMAIL will ask you where the file is that you downloaded from
  49. * your email system.  It then loads the file into a line by line
  50. * dbf file (one field only of 120 characters, so that each line
  51. * of text is one record). 
  52.  
  53. * This is then processed to produce Foxmail.DBF which is where
  54. * all your information is kept.
  55.  
  56.  
  57.  
  58. * Two tables are required for this program, as shown below
  59.  
  60. * FOXMAIL.DBF
  61. * Structure for table:    d:\foxwork\software\dbfs\foxmail.dbf
  62. * Number of data records: 234     
  63. * Date of last update:    01/20/94
  64. * Memo file block size:   64
  65. * Field  Field Name  Type       Width    Dec    Index
  66. *     1  FROM        Character     80            Asc
  67. *     2  REPLY_TO    Character     10            
  68. *     3  REFERENCES  Character     80            Asc
  69. *     4  MESS_ID     Character     80            
  70. *     5  DATE        Character     20            
  71. *     6  SOURCE      Character     10            
  72. *     7  SUBJECT     Character     80            Asc
  73. *     8  X_MAILSERV  Character     10            
  74. *     9  X_ARTICLE   Character      6            
  75. *    10  MESSAGE     Memo          10            
  76. *    11  INPUT_DT    Date           8            
  77. * ** Total **                     395
  78.  
  79. * INDEXES:
  80. * first index tag is called SUBJECT and is coded as follows:
  81. *     IIF(UPPER(subject)="RE:",LTRIM(SUBSTR(subject,5)),subject)
  82. *
  83. * this index is very important because it keeps things organized
  84. * by subject, even if you have "Re: " in front of the subject
  85. * description.
  86.  
  87. * other useful index tags are the following fields:
  88. *     REFERENCES
  89. *     FROM
  90. * with no special coding.
  91.  
  92. * TEST120.DBF
  93. * Structure for table:    d:\foxwork\software\dbfs\text120.dbf
  94. * Number of data records: 740     
  95. * Date of last update:    01/20/94
  96. * Field  Field Name  Type       Width    Dec    Index
  97. *     1  TEXT        Character    120            
  98. * ** Total **                     121
  99. *
  100. ********************************************************************
  101.  
  102.  
  103.  
  104. PRIVATE FIRST_TIME, FILENAME, MY_TEXT, THE_TEXT, M.MESS, REC_FLAG, ;
  105.    MY_SAFETY, DBF_FILE
  106. REC_FLAG = .F.
  107. FIRST_TIME = .T.
  108. M.MESS = ""
  109.  
  110.  
  111. *****************************************************************
  112. * change the DEFAULT and PATH to where you have stored the .DBF files
  113. *****************************************************************
  114.  
  115. SET DEFAULT TO d:\foxwork\software\dbfs
  116. SET PATH TO d:\foxwork\software\dbfs
  117. CLEAR
  118.  
  119.  
  120. MY_SAFETY = SET('SAFETY')
  121. SET SAFETY OFF
  122. SELECT 0
  123. dbf_file = GETFILE('DBF', 'Please select FOXMAIL.DBF')
  124. DO CASE
  125.         CASE EMPTY(dbf_file)
  126.                 RETURN
  127.         OTHERWISE
  128.                 USE (dbf_file) ALIAS FOXMAIL EXCLUSIVE
  129. ENDCASE
  130.  
  131. INDEX ON IIF(UPPER(subject)="RE:",LTRIM(SUBSTR(subject,5)),subject) TAG Subject ADDITIVE
  132. SET ORDER TO
  133.  
  134. SELECT 0
  135. dbf_file = GETFILE('DBF', 'Please select TEXT120.DBF')
  136. DO CASE
  137.         CASE EMPTY(dbf_file)
  138.                 RETURN
  139.         OTHERWISE
  140.                 USE (dbf_file) ALIAS TEXT EXCLUSIVE
  141. ENDCASE
  142. ZAP
  143. SET SAFETY &MY_SAFETY
  144.  
  145.  
  146. FILENAME = LOCFILE('ANYFILE', 'TXT', 'Select email file to import')
  147. APPEND FROM (FILENAME) TYPE SDF
  148.  
  149.  
  150. SET EXACT OFF
  151. SELECT TEXT
  152. GO TOP
  153. DO WHILE .NOT. EOF()
  154.  
  155.    THE_TEXT = ALLTRIM(TEXT)
  156.    MY_TEXT  = UPPER(THE_TEXT)
  157.    
  158.    * throw away all the preliminary header stuff.
  159.    * when you get to the first real 'from:', start
  160.    * a new record in foxmail to hold the data for
  161.    * this email message.
  162.       
  163.    * start storing data in foxmail.
  164. ***   DO WHILE .NOT. EOF() .AND. MY_TEXT != "STATUS:"
  165.       DO CASE
  166.          CASE MY_TEXT = "FROM OWNER-FOXPRO"
  167.          CASE MY_TEXT = "RETURN-PATH:"
  168.          CASE MY_TEXT = "RECEIVED:"
  169.               * received lines may have additional lines after
  170.               * them to discard.  To check for this below, we
  171.               * must flag that a "Received: " line has just been
  172.               * processed.
  173.               REC_FLAG = .T.
  174.          CASE MY_TEXT = "SENDER:"
  175.          CASE MY_TEXT = "TO:"
  176.          CASE MY_TEXT = "STATUS:"
  177.          CASE MY_TEXT = "FROM:"
  178.               IF .NOT. ("NAME: " $ MY_TEXT)
  179.                  IF !FIRST_TIME
  180.                     REPLACE FOXMAIL.MESSAGE WITH M.MESS
  181.                  ELSE
  182.                     FIRST_TIME = .F.
  183.                  ENDIF
  184.                  SELECT FOXMAIL
  185.                  APPEND BLANK
  186.                  M.MESS = ""
  187.                  SELECT TEXT
  188.                  THE_TEXT = RIGHT(THE_TEXT, LEN(THE_TEXT)-6)
  189.                  REPLACE FOXMAIL.FROM WITH ALLTRIM(THE_TEXT), ;
  190.                     FOXMAIL.INPUT_DT WITH DATE()
  191.               ENDIF
  192.          CASE MY_TEXT = "NAME:"
  193.               THE_TEXT = RIGHT(THE_TEXT, LEN(THE_TEXT)-12)
  194.               REPLACE FOXMAIL.REFERENCES WITH ALLTRIM(THE_TEXT)
  195.          CASE MY_TEXT = "REPLY-TO:"
  196.               DO CASE
  197.                  CASE '"The FoxPro (tm) Mailing List"' $ THE_TEXT
  198.                      THE_TEXT = "FML" 
  199.                  OTHERWISE
  200.                      THE_TEXT = "???" 
  201.               ENDCASE
  202.               REPLACE FOXMAIL.REPLY_TO WITH ALLTRIM(THE_TEXT)
  203.          CASE MY_TEXT = "REFERENCES:"
  204.               THE_TEXT = RIGHT(THE_TEXT, LEN(THE_TEXT)-12)
  205.               REPLACE FOXMAIL.REFERENCES WITH ALLTRIM(THE_TEXT)
  206.          CASE MY_TEXT = "MESSAGE-ID:"
  207.               THE_TEXT = RIGHT(THE_TEXT, LEN(THE_TEXT)-12)
  208.               REPLACE FOXMAIL.MESS_ID WITH ALLTRIM(THE_TEXT)
  209.          CASE MY_TEXT = "DATE:"
  210.               THE_TEXT = RIGHT(THE_TEXT, LEN(THE_TEXT)-6)
  211.               THE_TEXT = LEFT(THE_TEXT, AT(':',THE_TEXT)-3)
  212.               REPLACE FOXMAIL.DATE WITH ALLTRIM(THE_TEXT)
  213.          CASE MY_TEXT = "ORGANIZATION:"
  214.               DO CASE
  215.                  CASE 'Polar Bear Heaven BBS' $ THE_TEXT
  216.                      THE_TEXT = "PBH" 
  217.                  OTHERWISE
  218.                      THE_TEXT = "???" 
  219.               ENDCASE
  220.               REPLACE FOXMAIL.SOURCE WITH ALLTRIM(THE_TEXT)
  221.          CASE MY_TEXT = "SUBJECT:"
  222.               THE_TEXT = ALLTRIM(RIGHT(THE_TEXT, LEN(THE_TEXT)-9))
  223.               * get rid of any extra RE:s in this line - 
  224.               * leave only one, if one exists.  For sorting
  225.               * purposes to keep subject messages together.
  226.               DO WHILE ATC("RE:", THE_TEXT, 2) > 0
  227.                  THE_TEXT = ALLTRIM(RIGHT(THE_TEXT, LEN(THE_TEXT)-3))
  228.               ENDDO
  229.               REPLACE FOXMAIL.SUBJECT WITH ALLTRIM(THE_TEXT)
  230.          CASE MY_TEXT = "X-MAILSERVER:"
  231.               DO CASE
  232.                  CASE 'Waffle File Server' $ THE_TEXT
  233.                      THE_TEXT = "WFS" 
  234.                  OTHERWISE
  235.                      THE_TEXT = "???" 
  236.               ENDCASE
  237.               REPLACE FOXMAIL.X_MAILSERV WITH ALLTRIM(THE_TEXT)
  238.          CASE MY_TEXT = "X-ARTICLE:"
  239.               THE_TEXT = RIGHT(THE_TEXT, LEN(THE_TEXT)-11)
  240.               REPLACE FOXMAIL.X_ARTICLE WITH ALLTRIM(THE_TEXT)
  241.          OTHERWISE
  242.               * "Received" lines sometimes have additional lines
  243.               * after them that should not appear in the output
  244.               * text.  This checks for those lines and by passes
  245.               * them.  They all start with either a tab or a space
  246.               * and come immediately after a "Received:".
  247.               IF REC_FLAG .AND. (LEFT(TEXT, 1) = " " ;
  248.                         .OR. LEFT(TEXT, 1) = CHR(9))
  249.                  REC_FLAG = .F.
  250.                  * check for a possible second line.
  251.                  SKIP
  252.                  IF !(LEFT(TEXT, 1) = " " ;
  253.                         .OR. LEFT(TEXT, 1) = CHR(9))
  254.                     SKIP -1     && no 2nd line, go back one.
  255.                  ENDIF
  256.               ELSE
  257.                  * now process the message itself
  258.                  M.MESS = M.MESS + THE_TEXT + CHR(13) + CHR(10)
  259.               ENDIF
  260.       ENDCASE
  261.       SKIP
  262. ENDDO
  263.  
  264. * don't forget to catch the last message!
  265. SKIP -1
  266. REPLACE FOXMAIL.MESSAGE WITH M.MESS
  267.  
  268.  
  269.  
  270. WAIT WINDOW 'scan the most recent items at the bottom of the file.'
  271. SELECT FOXMAIL
  272. SET ORDER TO 
  273. BROWSE LAST
  274.  
  275. WAIT WINDOW 'look at the list in SUBJECT index order.'
  276. SELECT FOXMAIL
  277. SET ORDER TO TAG SUBJECT
  278. BROWSE LAST
  279.  
  280. ***************************************************************************
  281. * you may want to change this so that your file stays open.
  282. ***************************************************************************
  283. * SELECT FOXMAIL
  284. * USE
  285. * SELECT TEXT
  286. * USE
  287.  
  288. RETURN
  289.  
  290.