home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / ean / en_wtmail.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  4.1 KB  |  224 lines

  1. /*
  2.  *  Copyright University College London - 1984
  3.  *
  4.  *  Routines used by the EAN channel to access EAN
  5.  *  Developed from Rick Sample's Sendmail mailer
  6.  *
  7.  *  Steve Kille  - November 1984
  8.  */
  9.  
  10. #include "util/interface.h"
  11. #include "ccitt/interface.h"
  12. #include "mta/rec.h"
  13. #include "mta/p1.h"
  14. #include "mta/P1interf.h"
  15. #include "ua/message.h"
  16. #include "ua/P2.h"
  17. #include "ua/key.h"
  18. #include "ua/or.h"
  19. #include "ua/input.h"
  20. #include "nsg/A822/A822_in.h"
  21. #include <sysexits.h>
  22. #include <stdio.h>
  23.  
  24. #define NOTOK -1
  25. #define CONNECTION ".local"
  26.  
  27.  
  28. EDESC                   P1_desc =
  29.   {
  30.     P1_get,
  31.     P1_getbuff,
  32.     P1_put,
  33.     P1_putbuff,
  34.     0,
  35.     0
  36.   };
  37.  
  38.  
  39. static    char *mydomain;
  40. static    char *ean_sender;
  41. static    int reccount;
  42. static    ENODE*    reclist;
  43.  
  44.  
  45.  
  46.  
  47. en_init (sender, domain)
  48. char *sender;
  49. char *domain;
  50. {
  51.     eanlog ("ean_init ('%s', '%s')", sender, domain);
  52.  
  53.     if (Local_info () != OK)
  54.       {
  55.     eanlog ("Local info unavailable");
  56.     return (NOTOK);
  57.       }
  58.  
  59.     ean_sender = cpystr (sender);
  60.     mydomain = cpystr (domain);
  61.  
  62.     reclist = NULL;
  63.  
  64.     reccount = 0;
  65.  
  66.     return (OK);
  67. }
  68.  
  69.  
  70. en_end ()
  71. {
  72.     eanlog ("en_end()");
  73.  
  74.     free (ean_sender);
  75.     free (mydomain);
  76.     return (OK);
  77. }
  78.  
  79. en_wadr (adr,  rplystr)
  80. char *adr;                              /* address passed down */
  81. char *rplystr;                          /* where to place problem string */
  82. {
  83.     int rc;
  84.     ENODE*    recip;
  85.     ENODE*    orname;
  86.     ENODE*    e;
  87.  
  88.     eanlog ("en_wadr (%s)", adr);
  89.  
  90.     if ((orname = Bld_ORname (adr, &rc)) == NULL)
  91.     {
  92.     eanlog ("bad OR Name '%s' [%d]", adr, rc);
  93.     sprintf (rplystr, "Bad OR Name '%s'", adr);
  94.     return (NOTOK);
  95.     }
  96.  
  97.     recip = NULL;
  98.     Set_add (&recip, orname);
  99.     e = Bit_set ((ENODE*) NULL, P1_RESPONSIBLE);
  100.     Bit_set (e, P1_URQBASIC);
  101.     e->id = CONTEXT + 1L;
  102.     Set_add (&recip, e);
  103.     Set_add (&recip, Bld_int (CONTEXT+0L, ++reccount));
  104.     Seq_add (&reclist, recip);
  105.  
  106.     return (OK);
  107. }
  108.  
  109.  
  110. en_txt (fp, mydomain)
  111. FILE *fp;
  112. char *mydomain;
  113. {
  114.     ENODE*    dsi;
  115.     ENODE*    trace;
  116.     ENODE*    tr_seq;
  117.     ENODE*    e;
  118.     ENODE*    env;
  119.     ENODE*    domain;
  120.     ENODE*    mpdu;
  121.     ENODE*    content;
  122.     FILE*     f;
  123.     P1ID*     p1id;
  124.     long      cont_len;
  125.     TIME      t;
  126.     int       rc;
  127.  
  128.     eanlog ("en_txt ()");
  129.  
  130.     reclist->id = CONTEXT + 2L;
  131.  
  132.     if (P1_open (CONNECTION, NULL, &p1id) != OK)
  133.     {
  134.     eanlog ("P1_open failed");
  135.     return (NOTOK);
  136.     }
  137.  
  138.     P1_desc.id = (char*) p1id;
  139.  
  140.  
  141.     domain = NULL;
  142.     Seq_add (&domain, Bld_cons (P1_COUNTRY, Bld_prim (E_PRINTSTR, "")));
  143.     Seq_add (&domain, Bld_cons (P1_ADMINDOM, Bld_prim (E_PRINTSTR, "")));
  144.     Seq_add (&domain, Bld_prim (E_PRINTSTR, mydomain));;
  145.  
  146.     domain->id = P1_GLOBALID;
  147.  
  148.     if ((content = A822_in (&ean_sender, fp, FALSE, mydomain, &cont_len))
  149.          == NULL)
  150.     {
  151.     eanlog ("Failed to write contents");
  152.     return (NOTOK);
  153.     }
  154.  
  155.     env = NULL;
  156.  
  157.     /* create P1.MPDUIdentifier for message envelope */
  158.     e = NULL;
  159.     Seq_add (&e, Ecpy (domain));
  160.     Seq_add (&e, Bld_prim (E_IA5_STRING, TS_get ()));
  161.     e->id = P1_MPDUID;
  162.     Set_add (&env, e);
  163.  
  164.     if ((e = Bld_recip (ean_sender, &rc)) == NULL
  165.      || (e = Set_find (e, CONTEXT + 0L)) == NULL
  166.      || (e = Set_find (e, P1_ORNAME)) == NULL)
  167.       {
  168.     eanlog ("Didn't like the sender");
  169.     return (NOTOK);
  170.       }
  171.  
  172.     Set_add (&env, e);
  173.  
  174.     Set_add (&env, Bld_int (P1_CONTTYPE, 2L));
  175.  
  176.     if ((e = Find_heading (content, P2_MESSAGEID)) != NULL)
  177.     Set_add (&env, Bld_prim (P1_UACONTID, Unb_MID (e)));
  178.  
  179.     Set_add (&env, reclist);
  180.  
  181.     trace = NULL;
  182.     Seq_add (&trace, Ecpy (domain));
  183.  
  184.     dsi = NULL;
  185.  
  186.     e = Bld_time (TR_get (&t));
  187.     e->id = CONTEXT + 0L;
  188.     Set_add (&dsi, e);
  189.  
  190.     Set_add (&dsi, Bld_int (CONTEXT+2L, 0L));
  191.  
  192.     Seq_add (&trace, dsi);
  193.  
  194.     tr_seq = NULL;
  195.     Seq_add (&tr_seq, trace);
  196.     tr_seq->id = P1_TRACEINFO;
  197.  
  198.     Set_add (&env, tr_seq);
  199.  
  200.     mpdu = NULL;
  201.     Seq_add (&mpdu, env);
  202.  
  203.     mpdu->id = P1_USERMPDU;
  204.  
  205.     if (P1_import (p1id, mpdu) != OK)
  206.     {
  207.     eanlog ("Message transfer failure (P1_import)");
  208.     return (NOTOK);
  209.     }
  210.  
  211.     Ewrite (&P1_desc, content);
  212.  
  213.     if (P1_end (p1id, TRUE) != OK)
  214.     {
  215.     eanlog ("P1_end failure");
  216.     return (NOTOK);
  217.     }
  218.  
  219.     Efree (&content);
  220.     P1_close (&p1id);
  221.  
  222.     return (OK);
  223. }
  224.