1 /* $Id$ */
2 
3 /*
4  * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef DELIVER_H
20 #define DELIVER_H
21 
22 /* Deliver return codes. */
23 #define DELIVER_SUCCESS 0
24 #define DELIVER_FAILURE 1
25 
26 /* Deliver context. */
27 struct deliver_ctx {
28 	double				 tim;
29 
30 	struct action			*action;
31 	struct actitem			*actitem;
32 	struct rule			*rule;
33 
34 	struct account			*account;
35 	struct mail			*mail;
36 
37 	struct userdata			*udata;
38 
39 	struct mail			 wr_mail;
40 
41 	TAILQ_ENTRY(deliver_ctx)	 entry;
42 };
43 
44 /* Delivery types. */
45 enum delivertype {
46 	DELIVER_INCHILD,/* don't pass to parent */
47 	DELIVER_ASUSER,	/* pass to parent to drop privs */
48 	DELIVER_WRBACK	/* modifies mail: pass to parent and receive new mail */
49 };
50 
51 /* Deliver functions. */
52 struct deliver {
53 	const char	*name;
54 	enum delivertype type;
55 
56 	int		 (*deliver)(struct deliver_ctx *, struct actitem *);
57 	void		 (*desc)(struct actitem *, char *, size_t);
58 };
59 
60 /* Deliver smtp states. */
61 enum deliver_smtp_state {
62 	SMTP_CONNECTING,
63 	SMTP_HELO,
64 	SMTP_FROM,
65 	SMTP_TO,
66 	SMTP_DATA,
67 	SMTP_DONE,
68 	SMTP_QUIT
69 };
70 
71 /* Deliver smtp data. */
72 struct deliver_smtp_data {
73 	struct server	server;
74 	struct replstr	to;
75 	struct replstr	from;
76 };
77 
78 /* Deliver imap data. */
79 struct deliver_imap_data {
80 	char		*user;
81 	char		*pass;
82 	struct server	 server;
83 	int		 nocrammd5;
84 	int		 nologin;
85 	int		 starttls;
86 
87 	struct replstr	 folder;
88 };
89 
90 /* Deliver mbox data. */
91 struct deliver_mbox_data {
92 	struct replpath	path;
93 	int		compress;
94 };
95 
96 /* Deliver add-header data. */
97 struct deliver_add_header_data {
98 	struct replstr	hdr;
99 	struct replstr	value;
100 };
101 
102 /* Deliver remove-header data. */
103 struct deliver_remove_header_data {
104 	struct replstrs	*hdrs;
105 };
106 
107 /* Deliver write data. */
108 struct deliver_write_data {
109 	struct replpath	path;
110 	int		append;
111 };
112 
113 /* Deliver maildir data. */
114 struct deliver_maildir_data {
115 	struct replpath	path;
116 };
117 
118 /* Deliver rewrite data. */
119 struct deliver_rewrite_data {
120 	struct replpath	cmd;
121 };
122 
123 /* Deliver pipe data. */
124 struct deliver_pipe_data {
125 	struct replpath	cmd;
126 	int		pipe;
127 };
128 
129 /* Deliver tag data. */
130 struct deliver_tag_data {
131 	struct replstr	 key;
132 	struct replstr	 value;
133 };
134 
135 /* Deliver action data. */
136 struct deliver_action_data {
137 	struct replstrs	*actions;
138 };
139 
140 /* Deliver add-to-cache data. */
141 struct deliver_add_to_cache_data {
142 	char		*path;
143 	struct replstr	 key;
144 };
145 
146 /* Deliver remove-from-cache data. */
147 struct deliver_remove_from_cache_data {
148 	char		*path;
149 	struct replstr	 key;
150 };
151 
152 /* deliver-smtp.c */
153 extern struct deliver	 deliver_smtp;
154 
155 /* deliver-imap.c */
156 extern struct deliver	 deliver_imap;
157 
158 /* deliver-stdout.c */
159 extern struct deliver	 deliver_stdout;
160 
161 /* deliver-tag.c */
162 extern struct deliver	 deliver_tag;
163 
164 /* deliver-pipe.c */
165 extern struct deliver	 deliver_pipe;
166 
167 /* deliver-drop.c */
168 extern struct deliver	 deliver_drop;
169 
170 /* deliver-keep.c */
171 extern struct deliver	 deliver_keep;
172 
173 /* deliver-maildir.c */
174 extern struct deliver	 deliver_maildir;
175 
176 /* deliver-remove-header.c */
177 extern struct deliver	 deliver_remove_header;
178 
179 /* deliver-add-header.c */
180 extern struct deliver	 deliver_add_header;
181 
182 /* deliver-mbox.c */
183 extern struct deliver	 deliver_mbox;
184 
185 /* deliver-write.c */
186 extern struct deliver	 deliver_write;
187 
188 /* deliver-rewrite.c */
189 extern struct deliver	 deliver_rewrite;
190 
191 /* deliver-add-to-cache.c */
192 extern struct deliver	 deliver_add_to_cache;
193 
194 /* deliver-remove-from-cache.c */
195 extern struct deliver	 deliver_remove_from_cache;
196 
197 #endif
198