libev migration: start out with creating support for 'fallbackhost'
[citadel.git] / citadel / modules / smtp / smtpqueue.h
1 /*****************************************************************************/
2 /*               SMTP CLIENT (Queue Management) STUFF                        */
3 /*****************************************************************************/
4
5 typedef struct ParsedURL ParsedURL;
6 struct ParsedURL {
7         StrBuf *URL;
8         unsigned Port;
9         const char *Host;
10         const char *User;
11         const char *Pass;
12         const char *LocalPart;
13         int IsIP;
14         int af;
15         struct hostent *HEnt;
16         struct in6_addr Addr;
17         ParsedURL *Next;
18 };
19
20
21 #define MaxAttempts 15
22 typedef struct _delivery_attempt {
23         time_t when;
24         time_t retry;
25 }DeliveryAttempt;
26
27 typedef struct _mailq_entry {
28         DeliveryAttempt Attempts[MaxAttempts];
29         int nAttempts;
30         StrBuf *Recipient;
31         StrBuf *StatusMessage;
32         int Status;
33         /**<
34          * 0 = No delivery has yet been attempted
35          * 2 = Delivery was successful
36          * 4 = A transient error was experienced ... try again later
37          * 5 = Delivery to this address failed permanently.  The error message
38          *     should be placed in the fourth field so that a bounce message may
39          *     be generated.
40          */
41
42         int n;
43         int Active;
44 }MailQEntry;
45
46 typedef struct queueitem {
47         long MessageID;
48         long QueMsgID;
49         long Submitted;
50         int FailNow;
51         HashList *MailQEntries;
52         MailQEntry *Current; /* copy of the currently parsed item in the MailQEntries list; if null add a new one. */
53         DeliveryAttempt LastAttempt;
54         long ActiveDeliveries;
55         StrBuf *EnvelopeFrom;
56         StrBuf *BounceTo;
57         ParsedURL *URL;
58         ParsedURL *FallBackHost;
59 } OneQueItem;
60 typedef void (*QItemHandler)(OneQueItem *Item, StrBuf *Line, const char **Pos);
61
62 int DecreaseQReference(OneQueItem *MyQItem);
63 void RemoveQItem(OneQueItem *MyQItem);
64 int CountActiveQueueEntries(OneQueItem *MyQItem);
65 StrBuf *SerializeQueueItem(OneQueItem *MyQItem);
66
67 void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt);