b2778b99517d17d91b7b7f01af39a07c4b18958a
[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         int Status;
31         /**<
32          * 0 = No delivery has yet been attempted
33          * 2 = Delivery was successful
34          * 3 = Transient error like connection problem. Try next remote if available.
35          * 4 = A transient error was experienced ... try again later
36          * 5 = Delivery to this address failed permanently.  The error message
37          *     should be placed in the fourth field so that a bounce message may
38          *     be generated.
39          */
40
41         int n;
42         int Active;
43         int StillActive;
44 }MailQEntry;
45
46 typedef struct queueitem {
47         long SendBounceMail;
48         long MessageID;
49         long QueMsgID;
50         long Submitted;
51         int FailNow;
52         HashList *MailQEntries;
53 /* copy of the currently parsed item in the MailQEntries list;
54  * if null add a new one.
55  */
56         MailQEntry *Current;
57         time_t ReattemptWhen;
58         time_t Retry;
59
60         long ActiveDeliveries;
61         long NotYetShutdownDeliveries;
62         StrBuf *EnvelopeFrom;
63         StrBuf *BounceTo;
64         StrBuf *SenderRoom;
65         ParsedURL *URL;
66         ParsedURL *FallBackHost;
67         int HaveRelay;
68 } OneQueItem;
69
70 typedef void (*QItemHandler)(OneQueItem *Item, StrBuf *Line, const char **Pos);
71
72
73 typedef struct __QItemHandlerStruct {
74         QItemHandler H;
75 } QItemHandlerStruct;
76 int     DecreaseQReference(OneQueItem *MyQItem);
77 void DecreaseShutdownDeliveries(OneQueItem *MyQItem);
78 int GetShutdownDeliveries(OneQueItem *MyQItem);
79 void    RemoveQItem(OneQueItem *MyQItem);
80 int     CountActiveQueueEntries(OneQueItem *MyQItem, int before);
81 StrBuf *SerializeQueueItem(OneQueItem *MyQItem);
82 void    smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt, ParsedURL *Relay);
83
84 int CheckQEntryIsBounce(MailQEntry *ThisItem);