Back to index

courier  0.68.2
maildirfilter.h
Go to the documentation of this file.
00001 #ifndef       maildirfilter_h
00002 #define       maildirfilter_h
00003 
00004 /*
00005 ** Copyright 2000-2004 Double Precision, Inc.
00006 ** See COPYING for distribution information.
00007 */
00008 
00009 
00010 #include      "config.h"
00011 
00012 #ifdef __cplusplus
00013 extern "C" {
00014 #endif
00015 
00016 enum maildirfiltertype {
00017        startswith,
00018        endswith,
00019        contains,
00020        hasrecipient,
00021        mimemultipart,
00022        textplain,
00023        islargerthan,        /* Use negation for the opposite! */
00024        anymessage
00025        } ;
00026 
00027 struct maildirfilterrule {
00028        struct maildirfilterrule *next, *prev;
00029        char *rulename;
00030        enum maildirfiltertype type;
00031        int flags;
00032 
00033 #define       MFR_DOESNOT   1      /* Negates pretty much every condition */
00034 #define       MFR_BODY      2      /* startswith/endswith/contains applied
00035                             ** to body.
00036                             */
00037 #define       MFR_CONTINUE  4      /* Continue filtering (cc instead of to) */
00038 #define MFR_PLAINSTRING     8      /* Pattern is a plain string, not a regex */
00039 
00040        char *fieldname;     /* Match this header */
00041        char *fieldvalue;    /* Match/search value */
00042        char *tofolder;             /* Destination folder, fwd address, err msg */
00043        char *fromhdr;              /* From: header on autoreplies. */
00044        } ;
00045 
00046 struct maildirfilter {
00047        struct maildirfilterrule *first, *last;
00048        } ;
00049 
00050 /****************************************************************************/
00051 /*             Low-level filter access functions                            */
00052 /****************************************************************************/
00053 
00054 /*
00055 ** A maildirfilter structure is initialized simply by nulling it out, then: */
00056 
00057 struct maildirfilterrule *maildir_filter_appendrule(struct maildirfilter *r,
00058                                    const char *name,
00059                                    enum maildirfiltertype type,
00060                                    int flags,
00061                                    const char *header,
00062                                    const char *value,
00063                                    const char *folder,
00064                                    const char *fromhdr,
00065                                    int *errcode);       /* Append a new rule */
00066 
00067 int maildir_filter_setautoreplyfrom(struct maildirfilter *, const char *);
00068 
00069 /* Move a given rule up or down in the hierarchy */
00070 
00071 void maildir_filter_ruleup(struct maildirfilter *, struct maildirfilterrule *);
00072 void maildir_filter_ruledown(struct maildirfilter *, struct maildirfilterrule *);
00073 
00074 /* Delete a given rule */
00075 
00076 void maildir_filter_ruledel(struct maildirfilter *, struct maildirfilterrule *);
00077 
00078 /* Update an existing rule */
00079 
00080 int maildir_filter_ruleupdate(struct maildirfilter *, struct maildirfilterrule *,
00081                 const char *,
00082                 enum maildirfiltertype,
00083                 int,
00084                 const char *,
00085                 const char *,
00086                 const char *,
00087                 const char *,
00088                 int *);
00089 
00090 #define       maildir_filter_freerules(r) do { \
00091        while ( (r)->first ) \
00092               maildir_filter_ruledel( (r), (r)->first );       \
00093        } while (0)
00094 
00095 
00096 /*
00097 ** maildir_filter_appendrule and maildir_filter_ruleupdate set err_code to the following upon an error
00098 ** exit
00099 */
00100 
00101 #define       MF_ERR_BADRULENAME   1
00102 #define       MF_ERR_BADRULETYPE   2
00103 #define       MF_ERR_BADRULEHEADER 3
00104 #define       MF_ERR_BADRULEVALUE  4
00105 #define       MF_ERR_BADRULEFOLDER 5
00106 #define MF_ERR_BADFROMHDR   6
00107 #define MF_ERR_EXISTS              7
00108 #define MF_ERR_INTERNAL            100
00109 
00110 /* Save/Load rules from the given file */
00111 
00112 int maildir_filter_saverules(struct maildirfilter *,
00113                const char *,              /* Filename */
00114                const char *,              /* Maildir */
00115                const char *,              /* Path to maildir from mailfilter */
00116                const char *);             /* The return address */
00117 
00118 int maildir_filter_loadrules(struct maildirfilter *, const char *);
00119 
00120 #define       MF_LOADOK     0
00121 #define       MF_LOADNOTFOUND      1
00122 #define       MF_LOADFOREIGN       2
00123 #define       MF_LOADERROR  3
00124 
00125 /****************************************************************************/
00126 /*             High-level filter access functions                            */
00127 /****************************************************************************/
00128 
00129 int maildir_filter_importmaildirfilter(const char *); /* Get the maildir filter */
00130 int maildir_filter_loadmaildirfilter(struct maildirfilter *, const char *);
00131 int maildir_filter_savemaildirfilter(struct maildirfilter *, const char *, const char *);
00132 int maildir_filter_exportmaildirfilter(const char *);
00133                                           /* Commit the maildir filter */
00134 int maildir_filter_hasmaildirfilter(const char *);             /* Is maildir filter defined? */
00135 
00136 void maildir_filter_endmaildirfilter(const char *);            /* Remove the temp file */
00137 
00138        /*
00139        ** A convenient structure to parse autoresponder parameters.
00140        */
00141 
00142 struct maildir_filter_autoresp_info {
00143        char *name;
00144        int dsnflag;
00145        unsigned days;
00146        int noquote;
00147 } ;
00148 
00149 int maildir_filter_autoresp_info_init_str(struct maildir_filter_autoresp_info *, const char *);
00150 int maildir_filter_autoresp_info_init(struct maildir_filter_autoresp_info *, const char *);
00151 void maildir_filter_autoresp_info_free(struct maildir_filter_autoresp_info *);
00152 char *maildir_filter_autoresp_info_asstr(struct maildir_filter_autoresp_info *);
00153 
00154 #ifdef __cplusplus
00155 }
00156 #endif
00157 
00158 #endif