home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / doc / manual / volume2 / outbound.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-20  |  2.3 KB  |  112 lines

  1. main (argc, argv)
  2. int     argc;
  3. char    **argv;
  4. {
  5.     sys_init (argv[0]);   /* init the channel - and find out who we are */
  6.  
  7.     dirinit();              /* get to the right directory */
  8. #ifdef PP_DEBUG
  9.     if (argc > 1 && strcmp (argv[1], "debug") == 0)
  10.         debug_channel_control (argc, argv, chaninit, process, endproc);
  11.     else
  12. #endif
  13.         channel_control (argc, argv, chaninit, process, endproc);
  14.     exit (0);
  15. }
  16.  
  17. static int chaninit (arg)
  18. struct type_Qmgr_Channel *arg;
  19. {
  20.     char    *p = qb2str (arg);
  21.  
  22.     if ((mychan = ch_nm2struct (p)) == (CHAN *)0)
  23.         err_abrt (RP_PARM, "Channel '%s' not known", p);
  24.     exam_init (mychan);
  25.     free (p);
  26.     return OK;
  27. }
  28.  
  29. static int endproc ()
  30. {
  31.     if (cur_host)
  32.         exam_close (OK);
  33. }
  34.  
  35. static struct type_Qmgr_DeliveryStatus *process (arg)
  36. struct type_Qmgr_ProcMsg *arg;
  37. {
  38.     struct prm_vars prm;
  39.     struct type_Qmgr_UserList *up;
  40.     Q_struct        Qstruct, *qp = &Qstruct;
  41.     int     retval;
  42.     ADDR    *ap,
  43.         *ad_sendr = NULLADDR,
  44.         *ad_recip = NULLADDR,
  45.         *alp,
  46.         *ad_list = NULLADDR;
  47.     int     ad_count;
  48.  
  49.     if (this_msg) free (this_msg);
  50.  
  51.     this_msg = qb2str (arg -> qid);
  52.  
  53.     PP_TRACE (("process msg %s", this_msg));
  54.  
  55.     bzero ((char *)&prm, sizeof prm);
  56.     bzero ((char *)qp, sizeof *qp);
  57.  
  58.     (void) delivery_init (arg -> users);
  59.  
  60.     retval = rd_msg (this_msg, &prm, qp, &ad_sendr, &ad_recip, &ad_count);
  61.  
  62.     if (rp_isbad (retval)) {
  63.         PP_LOG (LLOG_EXCEPTIONS, ("rd_msg err: %s", this_msg));
  64.         return delivery_setall (int_Qmgr_status_messageFailure);
  65.     }
  66.  
  67.     sender = ad_sendr -> ad_r822adr;
  68.  
  69.  
  70.     for (ap = ad_recip; ap; ap = ap -> ad_next) {
  71.         for (up = arg ->users; up; up = up -> next) {
  72.             if (up -> RecipientId -> parm != ap -> ad_no)
  73.                 continue;
  74.  
  75.             if (chan_acheck (ap, mychan,
  76.                      ad_list == NULL, &cur_mta) == NOTOK)
  77.                 continue;
  78.         }
  79.         if (up == NULL)
  80.             continue;
  81.  
  82.         if (ad_list == NULLADDR)
  83.             ad_list = alp = (ADDR *) calloc (1, sizeof *alp);
  84.         else {
  85.             alp -> ad_next = (ADDR *) calloc (1, sizeof *alp);
  86.             alp = alp -> ad_next;
  87.         }
  88.         *alp = *ap;
  89.         alp -> ad_next = NULLADDR;
  90.     }
  91.  
  92.     if (ad_list == NULLADDR) {
  93.         PP_LOG (LLOG_EXCEPTIONS, ("No recipients in user list"));
  94.         rd_end ();
  95.         return deliverystate;
  96.     }
  97.  
  98.     deliver (ad_list, qp); /* do what is required */
  99.  
  100.     rd_end();
  101.  
  102.     return deliverystate;
  103. }
  104.  
  105.  
  106. static void dirinit()       /* Change into pp queue space */
  107. {
  108.     if (chdir (quedfldir) < 0)
  109.         err_abrt (RP_LIO, "Unable to change directory to '%s'",
  110.                         quedfldir);
  111. }
  112.