Commit 026e47c0 026e47c0ad9a02c51f0afb56c2a04ae308efbea6 by Sam Roberts

mailer_check_to(): ensures that there all the to addresses are

qualified.
mailer_check_from(): ensures that there is only one address, and it
is qualified.
1 parent 15f1743e
...@@ -24,26 +24,29 @@ ...@@ -24,26 +24,29 @@
24 extern "C" { 24 extern "C" {
25 #endif 25 #endif
26 26
27 extern int mailer_create __P ((mailer_t *, const char *)); 27 extern int mailer_create __P ((mailer_t *, const char *));
28 extern void mailer_destroy __P ((mailer_t *)); 28 extern void mailer_destroy __P ((mailer_t *));
29 29 extern int mailer_open __P ((mailer_t, int flags));
30 extern int mailer_open __P ((mailer_t, int flags)); 30 extern int mailer_close __P ((mailer_t));
31 extern int mailer_close __P ((mailer_t)); 31 extern int mailer_send_message __P ((mailer_t, message_t, address_t from, address_t to));
32 32
33 extern int mailer_send_message __P ((mailer_t, message_t, address_t from, address_t to)); 33 /* Accessor functions. */
34 34 extern int mailer_get_property __P ((mailer_t, property_t *));
35 extern int mailer_get_property __P ((mailer_t, property_t *)); 35 extern int mailer_get_stream __P ((mailer_t, stream_t *));
36 /* stream settings */ 36 extern int mailer_set_stream __P ((mailer_t, stream_t));
37 extern int mailer_get_stream __P ((mailer_t, stream_t *)); 37 extern int mailer_get_debug __P ((mailer_t, mu_debug_t *));
38 extern int mailer_set_stream __P ((mailer_t, stream_t)); 38 extern int mailer_set_debug __P ((mailer_t, mu_debug_t));
39
40 /* stream settings */
41 extern int mailer_get_debug __P ((mailer_t, mu_debug_t *));
42 extern int mailer_set_debug __P ((mailer_t, mu_debug_t));
43
44 extern int mailer_get_observable __P ((mailer_t, observable_t *)); 39 extern int mailer_get_observable __P ((mailer_t, observable_t *));
40 extern int mailer_get_url __P ((mailer_t, url_t *));
41
42 /* Utility functions, primarily for use of implementing concrete mailers. */
45 43
46 extern int mailer_get_url __P ((mailer_t, url_t *)); 44 /* A valid from address_t contains a single address that has a qualified
45 email address. */
46 extern int mailer_check_from __P((address_t from));
47 /* A valid to address_t contains 1 or more addresses, that are
48 qualified email addresses. */
49 extern int mailer_check_to __P((address_t to));
47 50
48 #ifdef __cplusplus 51 #ifdef __cplusplus
49 } 52 }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
27 27
28 #include <mailutils/address.h> 28 #include <mailutils/address.h>
29 #include <mailutils/debug.h> 29 #include <mailutils/debug.h>
30 #include <mailutils/errno.h>
30 #include <mailutils/iterator.h> 31 #include <mailutils/iterator.h>
31 #include <mailutils/observer.h> 32 #include <mailutils/observer.h>
32 #include <mailutils/property.h> 33 #include <mailutils/property.h>
...@@ -174,34 +175,75 @@ mailer_close (mailer_t mailer) ...@@ -174,34 +175,75 @@ mailer_close (mailer_t mailer)
174 return mailer->_close (mailer); 175 return mailer->_close (mailer);
175 } 176 }
176 177
177 /* messages */ 178
179 int
180 mailer_check_from(address_t from)
181 {
182 size_t n = 0;
183
184 if(!from)
185 return EINVAL;
186
187 if(address_get_count(from, &n) || n != 1)
188 return MU_ERR_MAILER_BAD_FROM;
189
190 if(address_get_email_count(from, &n) || n == 0)
191 return MU_ERR_MAILER_BAD_FROM;
192
193 return 0;
194 }
195
196 int
197 mailer_check_to(address_t to)
198 {
199 size_t count = 0;
200 size_t emails = 0;
201 size_t groups = 0;
202
203 if(!to)
204 return EINVAL;
205
206 if(address_get_count(to, &count))
207 return MU_ERR_MAILER_BAD_TO;
208
209 if(address_get_email_count(to, &emails))
210 return MU_ERR_MAILER_BAD_TO;
211
212 if(emails == 0)
213 return MU_ERR_MAILER_NO_RCPT_TO;
214
215 if(address_get_group_count(to, &groups))
216 return MU_ERR_MAILER_BAD_TO;
217
218 if(count - emails - groups != 0)
219 /* then not everything is a group or an email address */
220 return MU_ERR_MAILER_BAD_TO;
221
222 return 0;
223 }
224
178 int 225 int
179 mailer_send_message (mailer_t mailer, message_t msg, address_t from, address_t to) 226 mailer_send_message (mailer_t mailer, message_t msg, address_t from, address_t to)
180 { 227 {
181 int status; 228 int status;
182 size_t count = 0;
183 229
184 if (mailer == NULL || mailer->_send_message == NULL) 230 if (mailer == NULL || mailer->_send_message == NULL)
185 return ENOSYS; 231 return ENOSYS;
186 232
187 /* Common API checking. */ 233 /* Common API checking. */
188 234
235 /* FIXME: this should be done in the concrete APIs, sendmail doesn't
236 yet, though, so do it here. */
189 if (from) 237 if (from)
190 { 238 {
191 if ((status = address_get_email_count (from, &count)) != 0) 239 if ((status = mailer_check_from (from)) != 0)
192 return status; 240 return status;
193
194 if (count != 1)
195 return EINVAL;
196 } 241 }
197 242
198 if (to) 243 if (to)
199 { 244 {
200 if ((status = address_get_email_count (to, &count)) != 0) 245 if ((status = mailer_check_to (to)) != 0)
201 return status; 246 return status;
202
203 if (count < 1)
204 return EINVAL;
205 } 247 }
206 248
207 return mailer->_send_message (mailer, msg, from, to); 249 return mailer->_send_message (mailer, msg, from, to);
......