2bd4c2700f4921fbf3a61cb46c89386aee073f1e
[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 extern const unsigned short DefaultMXPort;
26
27 typedef struct _mailq_entry {
28         StrBuf *Recipient;
29         StrBuf *StatusMessage;
30         StrBuf *AllStatusMessages;
31         int Status;
32         /**<
33          * 0 = No delivery has yet been attempted
34          * 2 = Delivery was successful
35          * 3 = Transient error like connection problem. Try next remote if available.
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         int StillActive;
45         int nAttempt;
46 }MailQEntry;
47
48 typedef struct queueitem {
49         long SendBounceMail;
50         long MessageID;
51         long QueMsgID;
52         long Submitted;
53         int FailNow;
54         HashList *MailQEntries;
55 /* copy of the currently parsed item in the MailQEntries list;
56  * if null add a new one.
57  */
58         MailQEntry *Current;
59         time_t ReattemptWhen;
60         time_t Retry;
61
62         long ActiveDeliveries;
63         long NotYetShutdownDeliveries;
64         StrBuf *EnvelopeFrom;
65         StrBuf *BounceTo;
66         StrBuf *SenderRoom;
67         ParsedURL *URL;
68         ParsedURL *FallBackHost;
69         int HaveRelay;
70 } OneQueItem;
71
72 typedef void (*QItemHandler)(OneQueItem *Item, StrBuf *Line, const char **Pos);
73
74
75 typedef struct __QItemHandlerStruct {
76         QItemHandler H;
77 } QItemHandlerStruct;
78 int     DecreaseQReference(OneQueItem *MyQItem);
79 void DecreaseShutdownDeliveries(OneQueItem *MyQItem);
80 int GetShutdownDeliveries(OneQueItem *MyQItem);
81 void    RemoveQItem(OneQueItem *MyQItem);
82 int     CountActiveQueueEntries(OneQueItem *MyQItem, int before);
83 StrBuf *SerializeQueueItem(OneQueItem *MyQItem);
84 void    smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt, ParsedURL *Relay);
85
86 int CheckQEntryIsBounce(MailQEntry *ThisItem);