Back to index

courier  0.68.2
submit.h
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2001 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #ifndef       submit_h
00007 #define       submit_h
00008 
00009 #include      "afx.h"
00010 #include      "dbobj.h"
00011 #include      "courier.h"
00012 #if    HAVE_SYS_STAT_H
00013 #include      <sys/stat.h>
00014 #endif
00015 #if    HAVE_UNISTD_H
00016 #include      <unistd.h>
00017 #endif
00018 #include      <fstream>
00019 #include      <time.h>
00020 
00021 #include      <list>
00022 #include      <string>
00023 #include      <set>
00024 
00026 //
00027 // The SubmitFile class creates one or more control files in
00028 // ${localstatedir}/tmp.
00029 //
00030 // The drudge work in submit.C calculates the actual sender/recipients,
00031 // including aliases.dat lookups, and we get a raw list of addresses
00032 //
00033 // The SubmitFile class is implemented in submit2.C
00034 //
00035 // void Sender(const char *sender, const char *envid, char dsnformat)
00036 //            - specifies envelope sender 'envid', and dsn format 'dsnformat'
00037 // int ChkRecipient(const char *) - returns non-zero if this is a duplicate
00038 //                          recipient, zero if not.
00039 //
00040 // void AddReceipient(const char *recipient, const char *orecipient,
00041 //            const char *dsn, int isalias)
00042 //                                - records recipient address 'recipient',
00043 //                            which is original recipient 'orecipient',
00044 //                                with delivery status notifications set to
00045 //                            'dsn'.  'isalias' is non zero if this is
00046 //                            a local alias, in which case the recipient
00047 //                            is immediately marked as being received.
00048 // void ReceipientFilter(struct rw_transport *module,
00049 //            const char *host,
00050 //            const char *address);
00051 //                          - After the message is received, it can be
00052 //                          optionally spam filtered.  Record recipient
00053 //                          information now, and then run each individual
00054 //                          recipient address's filter later.
00055 //                          ReceipientFilter supplies the recipient info
00056 //                          for the last address called to AddReceipient.
00057 //                          Addresses resulting from alias expansion are
00058 //                          not filtered.
00059 //
00060 // void interrupt() - should be called if process receives an interrupt.
00061 //                    interrupt() deletes any temporary files that were created.
00062 //
00064 
00065 struct rfc2045;
00066 struct rw_transport;
00067 
00068 class RcptFilterInfo {
00069 public:
00070        unsigned num_control_file;
00071        unsigned num_receipient;
00072 
00073        struct rw_transport *driver;
00074        std::string host;
00075        std::string address;
00076        unsigned rcptnum;
00077 } ;
00078 
00079 class SubmitFile {
00080 private:
00081 
00082 static SubmitFile *current_submit_file;
00083 
00084        unsigned num_control_files_created;
00085 
00086        std::string name1stctlfile();
00087        std::string namefile(const char *, unsigned n);
00088 
00089  public:
00090        std::set<std::string> all_files;
00091  private:
00092        unsigned      rcptcount;
00093        afxopipestream       ctlfile;
00094        afxiopipestream      datfile;
00095        ino_t         ctlinodenum;
00096        ino_t         ctlpid;
00097        time_t        ctltimestamp;
00098        std::string   basemsgid;
00099 
00100        struct        rfc2045 *rwrfcptr;
00101        const char    *frommta;
00102        unsigned long bytecount;
00103        unsigned long sizelimit;
00104        int           diskfull;
00105        unsigned      diskspacecheck;
00106        std::string   sender, envid, dsnformat;
00107        std::string   receipient;
00108        std::set<std::string> addrlist_map;
00109        DbObj                              addrlist_gdbm;
00110 
00111        std::list<RcptFilterInfo> rcptfilterlist;
00112        std::fstream  rcptfilterlist_file;
00113 
00114        const char *sending_module;
00115 
00116        void   openctl();
00117        void   closectl();
00118 public:
00119        SubmitFile();
00120        ~SubmitFile();
00121 
00122        std::string QueueID();
00123        void SendingModule(const char *p) {sending_module=p;}
00124        void Sender(const char *, const char *, const char *, char);
00125        int ChkRecipient(const char *);
00126        void AddReceipient(const char *, const char *, const char *, int);
00127 
00128        void ReceipientFilter(struct rw_transport *,
00129                      const char *,
00130                      const char *,
00131                      unsigned);
00132 
00133        void MessageStart();
00134        void Message(const char *);
00135        int MessageEnd(unsigned, int, int);
00136 
00137        static std::string get_msgid_for_filtering(unsigned, void *);
00138 
00139 static void interrupt();
00140 static void trapsignals();
00141 
00142 
00143 private:
00144        int datafilter(const char *, unsigned, const char *);
00145 
00146        void do_datafilter( unsigned &, int &, int,
00147                          struct rw_transport *, std::string, std::string, unsigned,
00148 
00149                          unsigned, unsigned, const char *, unsigned nrcpts);
00150 } ;
00151 
00152 #endif