home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / AP / JED / JED097-1.TAR / jed / src / vmsmail.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  2.3 KB  |  123 lines

  1. /*
  2.  *  Copyright (c) 1992, 1994 John E. Davis  (davis@amy.tch.harvard.edu)
  3.  *  All Rights Reserved.
  4.  */
  5. #include <stdio.h>
  6. #include <ssdef.h>
  7.  
  8. #include "config.h"
  9. #include "buffer.h"
  10. #include "vmsmail.h"
  11.  
  12. void fill_struct(Mail_Type *m, int act, char *s)
  13. {
  14.    m->code = act;
  15.    m->buflen = strlen(s);
  16.    m->addr = (long) s;
  17.    m->junk = m->ret = 0;
  18. }
  19.  
  20. int vms_send_buffer(int *context, Mail_Type *mt0, Buffer *b)
  21. {
  22.    Mail_Type m;
  23.    Line *l = b->beg;
  24.    int n = 0, len;
  25.    unsigned char *p;
  26.    
  27.    while (l != NULL)
  28.      {
  29.     m.code = MAIL$_SEND_RECORD;
  30.     len = l->len;
  31.     p = l->data;
  32.     if (len && ('\n' == *(p + (int)(len - 1)))) len--;
  33.     m.buflen = len;
  34.     m.addr = (long) p;
  35.     m.junk = m.ret = 0;
  36.     if (SS$_NORMAL != mail$send_add_bodypart(context, &m, mt0)) return(0);
  37.     l = l->next;
  38.     n++;
  39.      }
  40.    return(n);
  41. }
  42.  
  43.  
  44.  
  45. /* to might be a comma separated list--- parse it too */
  46. int vms_send_mail(char *to, char *subj)
  47. {
  48.    Mail_Type mt0, mt;
  49.    int context = 0;
  50.    char *p;
  51.    
  52.    mt0.code = mt0.buflen = mt0.addr = mt0.ret = mt0.junk = 0;
  53.    
  54.    if (SS$_NORMAL != mail$send_begin(&context, &mt0, &mt0))
  55.      {
  56.     return(0);
  57.      }
  58. #if 0   
  59.    fill_struct(&mt, MAIL$_SEND_TO_LINE, to);
  60.    if (SS$_NORMAL != mail$send_add_attribute(&context, &mt, &mt0))
  61.      {
  62.     return(0);
  63.      }
  64.    
  65.    fill_struct(&mt, MAIL$_SEND_USERNAME, to);
  66.    if (SS$_NORMAL != mail$send_add_address(&context, &mt, &mt0))
  67.      {
  68.     return(0);
  69.      } 
  70. #endif
  71.    while (1)
  72.      {
  73.     while (*to && ((*to <= ' ') || (*to == ','))) to++;
  74.     if (*to == 0) break;
  75.     p = to;
  76.     while ((*p > ' ') && (*p != ',')) p++;
  77.     
  78.         mt.code = MAIL$_SEND_TO_LINE;
  79.     mt.buflen = p - to;
  80.     mt.ret = mt.junk = 0;
  81.     mt.addr = (long) to;
  82.     
  83.     if (SS$_NORMAL != mail$send_add_attribute(&context, &mt, &mt0))
  84.       {
  85.          return(0);
  86.       }
  87.     
  88.     mt.code = MAIL$_SEND_USERNAME;
  89.     mt.buflen = p - to;
  90.     mt.ret = mt.junk = 0;
  91.     mt.addr = (long) to;
  92.     
  93.     if (SS$_NORMAL != mail$send_add_address(&context, &mt, &mt0))
  94.       {
  95.          return(0);
  96.       }
  97.     to = p;
  98.      }
  99.    
  100.    fill_struct(&mt, MAIL$_SEND_SUBJECT, subj);
  101.    if (SS$_NORMAL != mail$send_add_attribute(&context, &mt, &mt0))
  102.      {
  103.     return(0);
  104.      }
  105.    
  106.    if (!vms_send_buffer(&context, &mt0, CBuf))
  107.      {
  108.     return(0);
  109.      }
  110.    
  111.    if (SS$_NORMAL != mail$send_message(&context, &mt0, &mt0))
  112.      {
  113.     return(0);
  114.      }
  115.    
  116.    if (SS$_NORMAL != mail$send_end(&context, &mt0, &mt0))
  117.      {
  118.     return(0);
  119.      }
  120.    return(1);
  121. }
  122.  
  123.