home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / APOP3D12 / APOP3D / MAILPROC.CMD < prev    next >
OS/2 REXX Batch file  |  1997-02-02  |  11KB  |  463 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*         REXX Mail processor for use with aPOP3d                      */
  4. /*                                                                      */
  5. /* (C) 1996,1997 Axel Mueller (amueller@stargate.rz.fh-offenburg.de)    */
  6. /*     Version 1.20                                                     */
  7. /************************************************************************/
  8.  
  9. /* Note that the functions of RxPRF.DLL have to be already registered!  */
  10.  
  11. parse arg MailInFile
  12.  
  13. call on NOTREADY name eof_reached
  14.  
  15.  
  16. /*#################################################*/
  17. /*#              set up                           #*/
  18. /*#################################################*/
  19.  
  20. True                    = 1
  21. False                = 0
  22.  
  23. ETCPath                = value('ETC',,'OS2ENVIRONMENT')
  24. MAILPath                = value('MAILDIR',,'OS2ENVIRONMENT')
  25. MailOutFile            = left(MailInFile, (length(MailInFile)-4))'.rsp'
  26. LogFile                = ETCPath'\mailproc.log'
  27. ContactAddress        = 'amueller@stargate.rz.fh-offenburg.de'
  28. Hostname                = value('HOSTNAME',,'OS2ENVIRONMENT')
  29. Domain                = RxPrfGetDomain()
  30.  
  31. if pos(Hostname, ".") == 0 then
  32.     HostDomain = Hostname'.'Domain
  33. else
  34.     HostDomain = Hostname
  35.  
  36.  
  37.  
  38. /*#################################################*/
  39. /*#              main routine                     #*/
  40. /*#################################################*/
  41.  
  42. ReturnPath = ''
  43.  
  44. Line = linein(MailInFile)
  45. do while length(Line) > 0
  46.  
  47.     if left(Line,8) == 'Subject:' then
  48.      do
  49.         parse value Line with Subject User Password CommandArguments
  50.         parse value CommandArguments with Command Arguments
  51.         parse value Arguments with Argument1 Argument2
  52.         if User=="HELP" | User=="help" then
  53.             Command = "HELP"
  54.         parse upper value Command with Command
  55.      end
  56.  
  57.     if left(Line,12) == 'Return-Path:' then
  58.         do
  59.          parse value Line with . ReturnPath
  60.          if left(ReturnPath, 1) == '<' then
  61.             ReturnPath = substr(ReturnPath, 2, length(ReturnPath)-2)
  62.         end
  63.  
  64.     if left(Line,5) <> 'From:' then
  65.         do
  66.          parse value Line with . NameOrAddress1 NameOrAddress2
  67.          if(pos(NameOrAddress1, "@") > 0) then
  68.             do
  69.              FromName = NameOrAddress2
  70.              FromAddress = NameOrAddress1
  71.             end
  72.          else
  73.             do
  74.              FromName = NameOrAddress1
  75.              FromAddress = NameOrAddress2
  76.             end
  77.         end
  78.  
  79.     Line = linein(MailInFile)
  80.  
  81. end
  82.  
  83. if length(ReturnPath) > 0 then
  84.     FromAddress = ReturnPath
  85.  
  86. call log('Received mail from 'FromAddress)
  87.  
  88.  
  89. select
  90.     when (Command='CHANGE_PASSWORD') & (Argument2=="") then
  91.         call change_password
  92.     when (Command='FORWARD_MAIL') & (Argument2=="") then
  93.         call forward_mail('0')
  94.     when (Command='FORWARD_COPY') & (Argument2=="") then
  95.         call forward_mail('1')
  96.     when (Command='STOP_FORWARD') & (Arguments=="") then
  97.         call stop_forward
  98.     when (Command='SEND_NOTIFICATION') then
  99.         call send_notification
  100.     when (Command='STOP_NOTIFICATION') & (Argument2=="") then
  101.         call stop_notification
  102.     when (Command='GET_STATUS') & (Arguments=="") then
  103.         call get_status
  104.     when Command='HELP' then
  105.         call help
  106.     otherwise
  107.         call unknown_command
  108. end
  109.  
  110. rc = lineout(MailInFile)
  111.  
  112. call log('Finished mail processing')
  113.  
  114.  
  115. exit
  116.  
  117.  
  118. /*#################################################*/
  119. /*#          mail processor commands              #*/
  120. /*#################################################*/
  121.  
  122.  
  123. /*****************************/
  124. /* change_password           */
  125. /*****************************/
  126.  
  127. change_password:
  128.  
  129.     call log('... password change request')
  130.     if (RxPrfCheckPassword(User, Password)) then
  131.         do
  132.          rc = RxPrfSetPassword(User, Argument1)
  133.          call write_robot_header
  134.          rc = lineout(MailOutFile, '*** Password has been successfully changed.')
  135.          call write_contact
  136.          rc = lineout(MailOutFile)
  137.          call log('... password has been changed')
  138.         end
  139.     else
  140.         do
  141.          call refuse_action
  142.          call write_contact
  143.          rc = lineout(MailOutFile)
  144.         end
  145.  
  146.     return
  147.  
  148.  
  149. /*****************************/
  150. /* get_status                */
  151. /*****************************/
  152.  
  153. get_status:
  154.  
  155.     call log('... status requested')
  156.     if (RxPrfCheckPassword(User, Password)) then
  157.         do
  158.          call write_robot_header
  159.          rc = lineout(MailOutFile)
  160.          'accounts -d 'User' >>'MailOutFile
  161.          call write_contact
  162.          rc = lineout(MailOutFile)
  163.          call log('... user status displayed')
  164.         end
  165.     else
  166.         do
  167.          call refuse_action
  168.          call write_contact
  169.          rc = lineout(MailOutFile)
  170.         end
  171.  
  172.     return
  173.  
  174.  
  175.  
  176. /*****************************/
  177. /* forward_mail              */
  178. /*****************************/
  179.  
  180. forward_mail:
  181.  
  182.     parse arg ForwardCopy
  183.  
  184.     call log('... mail forward request')
  185.     if (RxPrfCheckPassword(User, Password)) then
  186.         do
  187.          call write_robot_header
  188.          OwnAddress = User'@'HostDomain
  189.          if(Argument1 <> OwnAddress) then
  190.              do
  191.               rc = RxPrfSetForwardAddress(User, Argument1, ForwardCopy)
  192.               rc = lineout(MailOutFile, '*** Mail forwarding has been activated.')
  193.               if (ForwardCopy == 1) then
  194.                 do
  195.                   rc = lineout(MailOutFile, '*** A copy of every incoming mail will be forwarded to 'Argument1 )
  196.                   rc = lineout(MailOutFile, '*** The original mails will be keep for POP3 retrieval on this system.' )
  197.                   call log('... copy forward has been activated')
  198.                 end
  199.               else
  200.                 do
  201.                   rc = lineout(MailOutFile, '*** Every incoming mail will be forwarded to 'Argument1 )
  202.                   rc = lineout(MailOutFile, '*** No incoming mail be kept on this system.' )
  203.                   call log('... mail forward has been activated')
  204.                 end
  205.               call write_contact
  206.               rc = lineout(MailOutFile)
  207.              end
  208.          else
  209.              do
  210.               rc = lineout(MailOutFile, '*** Mail forwarding has NOT been activated.')
  211.               rc = lineout(MailOutFile, '*** The forward address specified would create a loop.')
  212.               call write_contact
  213.               rc = lineout(MailOutFile)
  214.               call log('... forward has not been activated in order to avoid loop')
  215.              end
  216.         end
  217.     else
  218.         do
  219.          call refuse_action
  220.          call write_contact
  221.          rc = lineout(MailOutFile)
  222.         end
  223.  
  224.     return
  225.  
  226.  
  227.  
  228. /*****************************/
  229. /* stop_forward              */
  230. /*****************************/
  231.  
  232. stop_forward:
  233.  
  234.     call log('... stop forward request')
  235.     if (RxPrfCheckPassword(User, Password)) then
  236.         do
  237.          rc = RxPrfSetForwardAddress(User, "", '0')
  238.          call write_robot_header
  239.          rc = lineout(MailOutFile, '*** Mail forwarding has been deactivated.')
  240.          call write_contact
  241.          rc = lineout(MailOutFile)
  242.          call log('... mail forward has been deactivated')
  243.         end
  244.     else
  245.         do
  246.          call refuse_action
  247.          call write_contact
  248.          rc = lineout(MailOutFile)
  249.         end
  250.  
  251.     return
  252.  
  253.  
  254.  
  255. /*****************************/
  256. /* send_notification         */
  257. /*****************************/
  258.  
  259. send_notification:
  260.  
  261.     call log('... request: sent_notification')
  262.  
  263.     if RxPrfCheckPassword(User, Password) then
  264.         do
  265.          NotificationFile = MAILPath'\'User'\notify.txt'
  266.          rc = SysFileDelete(NotificationFile)
  267.          eof = FALSE
  268.          do while (\ eof)
  269.             Line = linein(MailInFile)
  270.             rc = lineout(NotificationFile, Line)
  271.          end
  272.  
  273.          call write_robot_header
  274.          rc = RxPrfSetNotification(User, Arguments)
  275.          rc = lineout(MailOutFile, '*** Email sender notification has been activated.')
  276.          rc = lineout(MailOutFile, '*** Everyone sending an email to you will receive')
  277.          rc = lineout(MailOutFile, '*** a notification email from you with subject:')
  278.          rc = lineout(MailOutFile, '*** 'Arguments)
  279.          call write_contact
  280.          rc = lineout(MailOutFile)
  281.          call log('... sender notification is active now')
  282.         end
  283.     else
  284.         do
  285.          call refuse_action
  286.          call write_contact
  287.          rc = lineout(MailOutFile)
  288.         end
  289.  
  290.     return
  291.  
  292.  
  293.  
  294. /*****************************/
  295. /* stop_notification         */
  296. /*****************************/
  297.  
  298. stop_notification:
  299.  
  300.     call log('... request: stop_notification')
  301.     if (RxPrfCheckPassword(User, Password)) then
  302.         do
  303.          NotificationFile = MAILPath'\'User'\notify.txt'
  304.          rc = SysFileDelete(NotificationFile)
  305.          call write_robot_header
  306.          rc = RxPrfSetNotification(User, "")
  307.          rc = lineout(MailOutFile, '*** Email sender notification stopped.')
  308.          call write_contact
  309.          rc = lineout(MailOutFile)
  310.          call log('... sender notification was stopped')
  311.         end
  312.     else
  313.         do
  314.          call refuse_action
  315.          call write_contact
  316.          rc = lineout(MailOutFile)
  317.         end
  318.  
  319.     return
  320.  
  321.  
  322.  
  323. /*****************************/
  324. /* help                      */
  325. /*****************************/
  326.  
  327. help:
  328.  
  329.     call write_robot_header
  330.     call write_help
  331.     call write_contact
  332.     rc = lineout(MailOutFile)
  333.     call log('... help requested has been answered')
  334.  
  335.     return
  336.  
  337.  
  338.  
  339. /*****************************/
  340. /* unknown_command           */
  341. /*****************************/
  342.  
  343. unknown_command:
  344.  
  345.     call write_robot_header
  346.     rc = lineout(MailOutFile, '*** Command/Parameter error: 'CommandArguments)
  347.     rc = lineout(MailOutFile, '')
  348.     call write_help
  349.     call write_contact
  350.     rc = lineout(MailOutFile, '   ----- Original message follows -----')
  351.     rc = lineout(MailOutFile, '')
  352.     call write_original_mail
  353.     rc = lineout(MailOutFile)
  354.     call log('... command/parameter error: 'CommandArguments)
  355.  
  356.     return
  357.  
  358.  
  359.  
  360. /*#################################################*/
  361. /*#              sub procedures                   #*/
  362. /*#################################################*/
  363.  
  364.  
  365. /*****************************/
  366. /* write_robot_header        */
  367. /*****************************/
  368.  
  369. write_robot_header:
  370.  
  371.     rc = lineout(MailOutFile, 'This mail was created by an automatic mail processor.')
  372.     rc = lineout(MailOutFile, 'PLEASE DO NOT REPLY TO THIS MAIL.')
  373.     rc = lineout(MailOutFile, '')
  374.  
  375.     return
  376.  
  377.  
  378. /*****************************/
  379. /* write_contact             */
  380. /*****************************/
  381.  
  382. write_contact:
  383.  
  384.     rc = lineout(MailOutFile, '')
  385.     rc = lineout(MailOutFile, 'If you have any questions, suggestions or problems - please contact:')
  386.     rc = lineout(MailOutFile, ContactAddress)
  387.     rc = lineout(MailOutFile, '')
  388.  
  389.     return
  390.  
  391.  
  392.  
  393. /*****************************/
  394. /* write_help                */
  395. /*****************************/
  396.  
  397. write_help:
  398.  
  399.      HelpFile = ETCPath'\mailproc.hlp'
  400.      eof = FALSE
  401.      do while (\ eof)
  402.         Line = linein(HelpFile)
  403.         rc = lineout(MailOutFile, Line)
  404.      end
  405.     
  406.     return
  407.  
  408.  
  409.  
  410. /*****************************/
  411. /* write_original_mail       */
  412. /*****************************/
  413.  
  414. write_original_mail:
  415.  
  416.     MailInFilePos = 0
  417.     MailInFileSize = stream(MailInFile, 'c', 'query size')
  418.     do while (MailInFilePos<MailInFileSize)
  419.         rc = lineout(MailOutFile, Line)
  420.         Line = linein(MailInFile)
  421.         MailInFilePos=MailInFilePos+length(Line)+1
  422.     end
  423.     rc = lineout(MailInFile)
  424.  
  425.     return
  426.  
  427.  
  428. /*****************************/
  429. /* refuse_action             */
  430. /*****************************/
  431.  
  432. refuse_action:
  433.  
  434.     call write_robot_header
  435.     rc = lineout(MailOutFile, '*** You are not authorized for the requested action!')
  436.     call log('... no authorization for requested action')
  437.  
  438.     return
  439.  
  440.  
  441.  
  442. /*****************************/
  443. /* log                       */
  444. /*****************************/
  445.  
  446. log:
  447.  
  448.     parse arg LogString
  449.  
  450.     rc = lineout( LogFile, date(european)' 'time(normal)'' LogString )
  451.  
  452.     return
  453.  
  454.  
  455. /*****************************/
  456. /* not_ready                 */
  457. /*****************************/
  458.  
  459. eof_reached:
  460.  
  461.     eof = TRUE
  462.     return
  463.