46532c03286a698c14b1239438e4a4a4f9234b19
[citadel.git] / citadel / modules / smtp / smtp_clienthandlers.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 typedef enum _eSMTP_C_States {
21         eConnectMX,
22         eEHLO,
23         eHELO,
24         eSMTPAuth,
25         eFROM,
26         eRCPT,
27         eDATA,
28         eDATABody,
29         eDATATerminateBody,
30         eQUIT,
31         eMaxSMTPC
32 } eSMTP_C_States;
33
34
35 typedef struct _stmp_out_msg {
36         MailQEntry *MyQEntry;
37         OneQueItem *MyQItem;
38         long n;
39         AsyncIO IO;
40         long CXFlags;
41         int IDestructQueItem;
42         int nRemain;
43
44         eSMTP_C_States State;
45
46         struct ares_mx_reply *AllMX;
47         struct ares_mx_reply *CurrMX;
48         const char *mx_port;
49         const char *mx_host;
50         const char *LookupHostname;
51         int iMX, nMX;
52         int LookupWhich;
53
54         DNSQueryParts MxLookup;
55         DNSQueryParts HostLookup;
56         struct hostent *OneMX;
57         char **pIP;
58
59         ParsedURL *Relay;
60         ParsedURL *pCurrRelay;
61         StrBuf *msgtext;
62         StrBuf *QMsgData;
63         const char *envelope_from;
64
65         char user[1024];
66         char node[1024];
67         char name[1024];
68         char mailfrom[1024];
69
70         long Flags;
71 } SmtpOutMsg;
72
73
74 typedef eNextState (*SMTPReadHandler)(SmtpOutMsg *Msg);
75 typedef eNextState (*SMTPSendHandler)(SmtpOutMsg *Msg);
76
77 SMTPReadHandler ReadHandlers[eMaxSMTPC];
78 SMTPSendHandler SendHandlers[eMaxSMTPC];
79 const ConstStr ReadErrors[eMaxSMTPC+1];
80 const double SMTP_C_ReadTimeouts[eMaxSMTPC];
81 const double SMTP_C_SendTimeouts[eMaxSMTPC];
82 const double SMTP_C_ConnTimeout;
83
84 #define F_RELAY          (1<<0) /* we have a Relay    host configuration */
85 #define F_HAVE_FALLBACK  (1<<1) /* we have a fallback host configuration */
86 #define F_FALLBACK       (1<<2)
87 #define F_HAVE_MX        (1<<3) /* we have a list of mx records to go through.*/
88 #define F_DIRECT         (1<<4) /* no mx record found, trying direct connect. */
89
90 extern int SMTPClientDebugEnabled;
91
92 int smtp_resolve_recipients(SmtpOutMsg *SendMsg);
93
94 #define QID ((SmtpOutMsg*)IO->Data)->MyQItem->MessageID
95 #define N ((SmtpOutMsg*)IO->Data)->n
96 #define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (SMTPClientDebugEnabled != 0))
97
98 #define EVS_syslog(LEVEL, FORMAT, ...) \
99         DBGLOG(LEVEL) syslog(LEVEL,               \
100                "IO[%ld]CC[%d]S[%ld][%ld]" FORMAT, \
101                IO->ID, CCID, QID, N, __VA_ARGS__)
102
103 #define EVSM_syslog(LEVEL, FORMAT) \
104         DBGLOG(LEVEL) syslog(LEVEL, \
105                "IO[%ld]CC[%d]S[%ld][%ld]" FORMAT, \
106                IO->ID, CCID, QID, N)
107
108 #define EVNCS_syslog(LEVEL, FORMAT, ...) \
109         DBGLOG(LEVEL) syslog(LEVEL, "IO[%ld]S[%ld][%ld]" FORMAT, \
110                IO->ID, QID, N, __VA_ARGS__)
111
112 #define EVNCSM_syslog(LEVEL, FORMAT) \
113         DBGLOG(LEVEL) syslog(LEVEL, "IO[%ld]S[%ld][%ld]" FORMAT, \
114                IO->ID, QID, N)