home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 July / PCWorld_2000-07_cd.bin / Komunik / sambar / _SETUP.1 / sendmail.c < prev    next >
C/C++ Source or Header  |  2000-02-24  |  4KB  |  190 lines

  1. /*
  2. ** SENDMAIL
  3. **
  4. **      HTTP Wrapper for the Sendmail Utilities.
  5. **
  6. **        Confidential Property of Tod Sambar
  7. **        (c) Copyright Tod Sambar 1997
  8. **        All rights reserved.
  9. **
  10. **
  11. ** Public Functions:
  12. **
  13. **        sendmail_init
  14. **
  15. **
  16. ** History:
  17. ** Chg#    Date    Description                                                Resp
  18. ** ----    -------    -------------------------------------------------------    ----
  19. **         6APR97    Created                                                    sambar
  20. */
  21.  
  22. #include    <stdio.h>
  23. #include    <memory.h>
  24. #include    <string.h>
  25. #include    <stdlib.h>
  26. #include    <sendmail.h>
  27.  
  28. /*
  29. ** Sendmail parameters.
  30. */
  31. static SA_RPCPARAM        sendmailp [] =
  32. {
  33.     { "recipient",        1,    "Mail recipient." },
  34.     { "message",        1,    "Body of the mail." },
  35.     { "subject",        1,    "Mail subject." },
  36.     { "email",            1,    "Mail address of the sender." },
  37.     { "attachment",        0,    "File to send as an attachment." }
  38. };
  39.  
  40. /*
  41. **  SENDMAIL_INIT
  42. **
  43. **    Initialize the Sendmail RPC utilities.
  44. **
  45. **  Parameters:
  46. **    sactx        Sambar Server context
  47. **
  48. **  Returns:
  49. **    SA_SUCCEED | SA_FAIL
  50. */
  51. SA_RETCODE SA_PUBLIC
  52. sendmail_init(sactx)
  53. SA_CTX        *sactx;
  54. {
  55.     /*
  56.     ** Register the Sendmail form RPC                                 
  57.     ** Note: This can only be called from RCXsendmail, register
  58.     **         sendmail_init2 to allow sendmail to be called via 
  59.     **         /session/sendmail
  60.     */
  61.     if (sa_cmd_init(sactx, "sendmail", sendmailp, 
  62.         sizeof(sendmailp) / sizeof(SA_RPCPARAM), SA_AUTHORIZATION_SCRIPT,
  63.         "Sendmail Form Utility", sendmail_form) != SA_SUCCEED)
  64.     {
  65.         sa_log(sactx, "Unable to initialize Sendmail Form RPC");
  66.         return (SA_FAIL);
  67.     } 
  68.  
  69.     sa_log(sactx, "Sendmail Utilities Initialized");
  70.  
  71.     return (SA_SUCCEED);
  72. }
  73.  
  74. /*
  75. **  SENDMAIL_INITALL2
  76. **
  77. **    Initialize the Sendmail RPC utilities (open to all use).
  78. **
  79. **    WARNING!  Initialzing this interface allows you sendmail
  80. **    script to be used as a SPAM relay point. 
  81. **
  82. **  Parameters:
  83. **    sactx        Sambar Server context
  84. **
  85. **  Returns:
  86. **    SA_SUCCEED | SA_FAIL
  87. */
  88. SA_RETCODE SA_PUBLIC
  89. sendmail_init2(sactx)
  90. SA_CTX        *sactx;
  91. {
  92.     /* Register the Sendmail form RPC                                 */
  93.     if (sa_cmd_init(sactx, "sendmail", sendmailp, 
  94.         sizeof(sendmailp) / sizeof(SA_RPCPARAM), SA_AUTHORIZATION_ALL,
  95.         "Sendmail Form Utility", sendmail_form) != SA_SUCCEED)
  96.     {
  97.         sa_log(sactx, "Unable to initialize Sendmail Form RPC");
  98.         return (SA_FAIL);
  99.     } 
  100.  
  101.     sa_log(sactx, "Sendmail Utilities Initialized");
  102.  
  103.     return (SA_SUCCEED);
  104. }
  105.  
  106. /*
  107. **  SENDMAIL_FORM
  108. **
  109. **    Process a sendmail form and send the appropriate mail.
  110. **
  111. **  Parameters:
  112. **    sactx        Sambar Server context
  113. **    saconn        Sambar Server connection
  114. **    saparams    RPC Parameters
  115. **    infop        Error parameters
  116. **
  117. **  Returns:
  118. **    SA_SUCCEED | SA_FAIL
  119. */
  120. SA_RETCODE SA_PUBLIC
  121. sendmail_form(sactx, saconn, saparams, infop)
  122. SA_CTX        *sactx;
  123. SA_CONN        *saconn;
  124. SA_PARAMS    *saparams;
  125. SA_INT        *infop;
  126. {
  127.     SA_INT        emaillen;
  128.     SA_CHAR        *email;
  129.     SA_INT        tolen;
  130.     SA_CHAR        *to;
  131.     SA_INT        subjlen;
  132.     SA_CHAR        *subj;
  133.     SA_INT        msglen;
  134.     SA_CHAR        *msg;
  135.     SA_INT        attachlen;
  136.     SA_CHAR        *attach;
  137.  
  138.     /* Get the mail recipient                                            */
  139.     if ((sa_param(sactx, saparams, "recipient", &to, &tolen) != SA_SUCCEED) ||
  140.         (tolen == 0))
  141.     {
  142.         *infop = SA_E_INVALIDDATA;
  143.         return (SA_FAIL);
  144.     }
  145.  
  146.     /* Get the mail message                                             */
  147.     if (sa_param(sactx, saparams, "message", &msg, &msglen) != SA_SUCCEED)
  148.     {
  149.         *infop = SA_E_INVALIDDATA;
  150.         return (SA_FAIL);
  151.     }
  152.  
  153.     /* If there is no message, just return                                */
  154.     if (msglen == 0)
  155.         return (SA_SUCCEED);
  156.  
  157.     /* Get the subject (optional)                                        */
  158.     if (sa_param(sactx, saparams, "subject", &subj, &subjlen) != SA_SUCCEED)
  159.     {
  160.         *infop = SA_E_INVALIDDATA;
  161.         return (SA_FAIL);
  162.     }
  163.  
  164.     /* Get the "email"                                                     */
  165.     if ((sa_param(sactx, saparams, "email", &email, &emaillen) != SA_SUCCEED) ||
  166.         (emaillen == 0))
  167.     {
  168.         *infop = SA_E_INVALIDDATA;
  169.         return (SA_FAIL);
  170.     }
  171.  
  172.     /* Get the attachment (optional)                                    */
  173.     if (sa_param(sactx, saparams, "attachment", &attach, &attachlen) 
  174.         != SA_SUCCEED)
  175.     {
  176.         attach = (SA_CHAR *)NULL;
  177.     }
  178.  
  179.     if (attachlen == 0)
  180.         attach = (SA_CHAR *)NULL;
  181.  
  182.     if (sa_smtpmail(sactx, email, to, NULL, NULL, subj, msg, attach) 
  183.         != SA_SUCCEED)
  184.     {
  185.         return (SA_FAIL);
  186.     }
  187.  
  188.     return (SA_SUCCEED);
  189. }
  190.