home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 25 / amigaformatcd25.iso / websites / f1_gp / ftp / rexx / returnreceipt.lha / ReturnReceipt.br next >
Text File  |  1997-09-19  |  4KB  |  133 lines

  1. /* $VER: ReturnReceipt.br 1.1 (19.9.97)
  2. **
  3. ** Author: Oliver Roberts
  4. ** E-Mail: Oliver@poboxes.com
  5. **    WWW: http://www.nanunanu.org/~oliver/
  6. **
  7. ** Brief Description:
  8. **
  9. ** Processes messages with a "Return-Receipt-To: <address>" header line
  10. ** and creates an event to the sender confirming the message has been
  11. ** received successfully
  12. **
  13. ** Should be called via SortMail
  14. */
  15.  
  16. /********************* DO NOT MODIFY BELOW HERE *************************/
  17. Usage = 'Usage: ReturnReceipt.br BBSName Conference MessageNo'
  18. options results
  19.  
  20. /* Strip "'s from arg string and parse into variables */
  21. parse arg CmdLine
  22. CmdLine = compress(CmdLine,'"')
  23. parse var CmdLine bbs conf msgnum
  24. if bbs = '?' | conf = '' | msgnum = '' then do
  25.     say 'ReturnReceipt.br: ' || Usage
  26.     exit
  27. end
  28.  
  29. if ~show('p', 'BBSREAD') then do
  30.     address command
  31.         "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  32.         "WaitForPort BBSREAD"
  33. end
  34.  
  35. address(bbsread)
  36.  
  37. /* Read the data on the message that is to be forwarded */
  38.  
  39. READBRMESSAGE bbsname '"'bbs'"' confname '"'conf'"' msgnr msgnum headstem HEADTAGS textstem TEXTTAGS  datastem DATATAGS
  40. if(rc ~= 0) then goto quit
  41.  
  42. /* Find "Return-Receipt-To:" header line */
  43.  
  44. rrt = ''
  45. do n=1 to TEXTTAGS.COMMENT.COUNT
  46.     if (upper(left(TEXTTAGS.COMMENT.n,18)) = upper('Return-Receipt-To:')) then
  47.         rrt = SUBSTR(TEXTTAGS.COMMENT.n,19)
  48. end
  49.  
  50. if (rrt = '') then exit
  51.  
  52. /* Parse return address */
  53.  
  54. addresspos = lastpos(' ',rrt,pos('@',rrt))
  55. addresspart = word(substr(rrt,addresspos),1)
  56. toaddress = strip(addresspart,B,' <>')
  57. tofullname = ''
  58.  
  59. if (words(rrt) > 1) then do
  60.     if (addresspos = 1) then do
  61.         namepart = substr(rrt,length(addresspart)+1)
  62.     end
  63.     else do
  64.         namepart = substr(rrt,1,addresspos)
  65.     end
  66.     tofullname = strip(namepart,B,'()" ')
  67. end
  68.  
  69. /* Get a unique message for the event */
  70.  
  71. UNIQUEMSGFILE bbsname '"'bbs'"' stem UNIQUEFILE
  72. if(rc ~= 0) then goto quit
  73.  
  74. /* Create message file */
  75.  
  76. if(~open(fh, UNIQUEFILE.NAME, W)) then ExitMsg '"Unable to open file:' UNIQUEFILE.NAME
  77.  
  78. /* Build the message */
  79.  
  80. TB_WDAYS = 'Monday Tuesday Wednesday Thursday Friday Saturday Sunday'
  81. TB_MONTH = 'January February March April May June July August September October November December'
  82.  
  83. AMIGA2DATE HEADTAGS.CREATIONDATE stem '"'date'"'
  84.  
  85. if(date.WDAY == '0') then
  86.     WKDays = 'Sunday'
  87. else
  88.     WKDays = word(TB_WDAYS, date.WDAY)
  89.  
  90. MODays = word(TB_MONTH, date.MONTH)
  91.  
  92. call writeln(fh,'Machine-generated automatic response:')
  93. call writeln(fh,'')
  94. call writeln(fh,'Your message to ' || HEADTAGS.TONAME || ' (' || HEADTAGS.TOADDR || ')')
  95. call writeln(fh,'dated' WKDays date.MDAY MODays date.YEAR 'at' right('0' || date.HOUR,2) || ':' || right('0' || date.MIN,2) || ':' || right('0' || date.SEC,2))
  96. call writeln(fh,'with message-id ' || HEADTAGS.MSGID)
  97. call writeln(fh,'and subject "' || HEADTAGS.SUBJECT || '"')
  98. call writeln(fh,'has been received successfully.')
  99. call writeln(fh,'')
  100. call writeln(fh,'Note: This receipt doesn''t imply that the message has been read.')
  101. call writeln(fh,'')
  102. call writeln(fh,'--')
  103. if ~(open(tv,'ENV:THOR/THORVERSION',R)) then do
  104.     call writeln(fh,'THOR - Amiga TCP/IP')
  105. end
  106. else do
  107.     call writeln(fh,readln(tv) || ' - Amiga TCP/IP')
  108.     call close(tv)
  109. end
  110. call close(fh)
  111.  
  112. /* Post it */
  113.  
  114. drop EVENT.
  115.  
  116. EVENT.SUBJECT = 'RECEIPT: ' || HEADTAGS.SUBJECT
  117. EVENT.TONAME = tofullname
  118. EVENT.TOADDR = toaddress
  119. EVENT.CONFERENCE = conf
  120. EVENT.MSGFILE = UNIQUEFILE.FILEPART
  121.  
  122. WRITEBREVENT bbsname '"'bbs'"' event 0 stem EVENT
  123. if(rc ~= 0) then goto quit
  124.  
  125. exit
  126.  
  127. ExitMsg:
  128.     parse arg msgstr
  129.     say ''
  130.     say 'ReturnReceipt.br:' msgstr
  131.     say ''
  132.     exit
  133.