Back to index

courier  0.68.2
comdsn2.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 1999 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 
00007 #include      "courier.h"
00008 #include      "comctlfile.h"
00009 #include      <string.h>
00010 #include      <stdlib.h>
00011 
00012 /* Determine if this recipient should be reported on */
00013 
00014 const char *dsn_sender(struct ctlfile *ctf, unsigned i, int isdelayeddsn)
00015 {
00016 char   c=ctf->delstatus[i][0];
00017 const char *p;
00018 const char *sender=ctf->sender;
00019 
00020 /* This msg just came back from the dsn module */
00021 
00022        if (c != COMCTLFILE_DELSUCCESS && !isdelayeddsn)
00023               c=COMCTLFILE_DELFAIL;
00024               /* Deferrals are treated as failures for final dsn */
00025 
00026 
00027        {
00028               static int bouncetoauth = -1;
00029 
00030               if (bouncetoauth < 0)
00031               {
00032                      p=getenv("DSNTOAUTHADDR");
00033 
00034                      bouncetoauth=p && *p == '0' ? 0:1;
00035               }
00036 
00037               if (bouncetoauth)
00038               {
00039                      int i;
00040 
00041                      i=ctlfile_searchfirst(ctf, COMCTLFILE_AUTHNAME);
00042 
00043                      if (i >= 0 &&
00044                          strchr(ctf->lines[i]+1, '@'))
00045                      {
00046                             sender=ctf->lines[i]+1;
00047                      }
00048               }
00049        }
00050 
00051        /*
00052        ** An empty envelope sender always bounces failures to postmaster,
00053        ** doublebounce.
00054        */
00055 
00056        if (*sender == 0)
00057               return (!isdelayeddsn &&
00058                      c == COMCTLFILE_DELFAIL &&
00059                      (ctf->dsnreceipients[i] == 0 ||
00060                      ctf->dsnreceipients[i][0] == 0 ||
00061                      strchr(ctf->dsnreceipients[i], 'F'))
00062                             ? "postmaster":0);
00063 
00064        if (strcmp(sender, TRIPLEBOUNCE) == 0)    return (0);
00065 
00066        switch (c)    {
00067        case COMCTLFILE_DELSUCCESS:
00068               if (isdelayeddsn)
00069                      return (0);   /* This is a delayed DSN only */
00070 
00071               /*
00072               ** Only succesfull local deliveries or relays are ever
00073               ** reported.
00074               */
00075 
00076               for (p=ctf->delstatus[i]; *p; p++)
00077                      if (*p == 'l' || *p == 'r') break;
00078               if (!*p)      return (0);
00079 
00080               /*
00081               ** To report a success DSN, NOTIFY=SUCCESS must always be
00082               ** selected.
00083               */
00084 
00085               if (ctf->dsnreceipients[i] &&
00086                      ctf->dsnreceipients[i][0] &&
00087                      strchr(ctf->dsnreceipients[i], 'S'))
00088                      break;
00089               return (0);
00090 
00091        case COMCTLFILE_DELFAIL:
00092               if (isdelayeddsn)
00093                      return (0);   /* This is a delayed DSN only */
00094 
00095               /*
00096               ** Report failures unless NOTIFY was used, and FAILURE was
00097               ** NOT selected.
00098               */
00099 
00100               if (ctf->dsnreceipients[i] &&
00101                      ctf->dsnreceipients[i][0] &&
00102                      strchr(ctf->dsnreceipients[i], 'F') == 0)
00103                      return (0);
00104               break;
00105        default:
00106 
00107               /* Delayed DSN */
00108 
00109               if (!isdelayeddsn)   return (0);
00110 
00111               if ( ctf->dsnreceipients[i] && ctf->dsnreceipients[i][0])
00112               {
00113               const char *p=ctf->dsnreceipients[i];
00114 
00115                      for ( ; *p; p++)
00116                      /*
00117                      ** When NOTIFY was used, and DELAY was selected,
00118                      ** always report.
00119                      */
00120                             if (*p == 'D')       break;
00121 
00122                      if (!*p)      return (0);
00123               }
00124               else
00125               {
00126               static int defaultdelay = -1;
00127 
00128                      if (defaultdelay < 0)
00129                      {
00130                             p=getenv(DSNDEFAULTNOTIFYDELAY);
00131                             defaultdelay=p && *p == '0' ? 0:1;
00132                      }
00133                      if (defaultdelay)
00134                             break;
00135                      return (0);
00136               }
00137               break;
00138        }
00139        return (sender);
00140 }