c6cd97f5810c25a0914f9023a2d231b732a9b126
[citadel.git] / citadel / modules / smtp / smtpqueue.h
1 /*
2  *
3  * Copyright (c) 1998-2012 by the citadel.org team
4  *
5  *  This program is open source software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 /*****************************************************************************/
21 /*               SMTP CLIENT (Queue Management) STUFF                        */
22 /*****************************************************************************/
23
24 #define MaxAttempts 15
25
26 typedef struct _mailq_entry {
27         StrBuf *Recipient;
28         StrBuf *StatusMessage;
29         int Status;
30         /**<
31          * 0 = No delivery has yet been attempted
32          * 2 = Delivery was successful
33          * 3 = Transient error like connection problem. Try next remote if available.
34          * 4 = A transient error was experienced ... try again later
35          * 5 = Delivery to this address failed permanently.  The error message
36          *     should be placed in the fourth field so that a bounce message may
37          *     be generated.
38          */
39
40         int n;
41         int Active;
42 }MailQEntry;
43
44 typedef struct queueitem {
45         long SendBounceMail;
46         long MessageID;
47         long QueMsgID;
48         long Submitted;
49         int FailNow;
50         HashList *MailQEntries;
51 /* copy of the currently parsed item in the MailQEntries list;
52  * if null add a new one.
53  */
54         MailQEntry *Current;
55         time_t ReattemptWhen;
56         time_t Retry;
57
58         long ActiveDeliveries;
59         long NotYetShutdownDeliveries;
60         StrBuf *EnvelopeFrom;
61         StrBuf *BounceTo;
62         StrBuf *SenderRoom;
63         ParsedURL *URL;
64         ParsedURL *FallBackHost;
65 } OneQueItem;
66
67 typedef void (*QItemHandler)(OneQueItem *Item, StrBuf *Line, const char **Pos);
68
69
70 typedef struct __QItemHandlerStruct {
71         QItemHandler H;
72 } QItemHandlerStruct;
73 int     DecreaseQReference(OneQueItem *MyQItem);
74 void DecreaseShutdownDeliveries(OneQueItem *MyQItem);
75 int GetShutdownDeliveries(OneQueItem *MyQItem);
76 void    RemoveQItem(OneQueItem *MyQItem);
77 int     CountActiveQueueEntries(OneQueItem *MyQItem);
78 StrBuf *SerializeQueueItem(OneQueItem *MyQItem);
79 void    smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt);
80
81 int CheckQEntryIsBounce(MailQEntry *ThisItem);