dovecot-sieve-1.0: Added support for mailto notify. Patch by Uld...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Jul 13 01:55:15 EEST 2007
details: http://hg.dovecot.org/dovecot-sieve-1.0/rev/0ddc99d4b747
changeset: 23:0ddc99d4b747
user: Timo Sirainen <tss at iki.fi>
date: Fri Jul 13 01:55:12 2007 +0300
description:
Added support for mailto notify. Patch by Uldis Pakuls.
diffstat:
1 file changed, 83 insertions(+), 24 deletions(-)
src/sieve-cmu.c | 107 ++++++++++++++++++++++++++++++++++++++++++-------------
diffs (117 lines):
diff -r f8f207198d09 -r 0ddc99d4b747 src/sieve-cmu.c
--- a/src/sieve-cmu.c Fri Jul 13 01:48:38 2007 +0300
+++ b/src/sieve-cmu.c Fri Jul 13 01:55:12 2007 +0300
@@ -258,30 +258,89 @@ static int sieve_keep(void *ac,
return SIEVE_OK;
}
-static int sieve_notify(void *ac __attr_unused__,
- void *interp_context __attr_unused__,
- void *script_context __attr_unused__,
- void *mc __attr_unused__,
- const char **errmsg __attr_unused__)
-{
-#if 0
- const char *notifier = config_getstring(IMAPOPT_SIEVENOTIFIER);
-
- if (notifier) {
- sieve_notify_context_t *nc = (sieve_notify_context_t *) ac;
- script_data_t *sd = (script_data_t *) script_context;
- int nopt = 0;
-
- /* count options */
- while (nc->options[nopt]) nopt++;
-
- /* "default" is a magic value that implies the default */
- notify(!strcmp("default",nc->method) ? notifier : nc->method,
- "SIEVE", nc->priority, sd->username, NULL,
- nopt, nc->options, nc->message);
- }
-#endif
- return SIEVE_FAIL;
+static bool contains_8bit(const char *msg)
+{
+ const unsigned char *s = (const unsigned char *)msg;
+
+ for (; *s != '\0'; s++) {
+ if ((*s & 0x80) != 0)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static int sieve_notify(void *ac,
+ void *ic __attr_unused__,
+ void *sc __attr_unused__,
+ void *mc,
+ const char **errmsg)
+{
+ sieve_notify_context_t *nc = (sieve_notify_context_t *) ac;
+ sieve_msgdata_t *m = mc;
+
+ int nopt = 0;
+ FILE *f;
+ struct smtp_client *smtp_client;
+ const char *outmsgid;
+
+ /* "default" is "mailto" as only one... */
+ if (!strcasecmp(nc->method, "default")) nc->method = "mailto";
+ /* check method */
+ if (strcasecmp(nc->method, "mailto")) {
+ *errmsg = "Unknown [unimplemented] notify method";
+ /* just log error, failed notify is not reason to abort all script. */
+ i_info("SIEVE ERROR: Unknown [unimplemented] notify method <%s>",
+ nc->method);
+ return SIEVE_OK;
+ }
+ /* count options */
+ while (nc->options[nopt]) {
+ smtp_client = smtp_client_open(nc->options[nopt], NULL, &f);
+ outmsgid = deliver_get_new_message_id();
+ fprintf(f, "Message-ID: %s\r\n", outmsgid);
+ fprintf(f, "Date: %s\r\n", message_date_create(ioloop_time));
+ fprintf(f, "X-Sieve: %s\r\n", SIEVE_VERSION);
+ if ( strcasecmp(nc->priority, "high") == 0 ) {
+ fprintf(f, "X-Priority: 1 (Highest)\r\n");
+ fprintf(f, "Importance: High\r\n");
+ } else if ( strcasecmp(nc->priority, "normal") == 0 ) {
+ fprintf(f, "X-Priority: 3 (Normal)\r\n");
+ fprintf(f, "Importance: Normal\r\n");
+ } else if ( strcasecmp(nc->priority, "low") == 0 ) {
+ fprintf(f, "X-Priority: 5 (Lowest)\r\n");
+ fprintf(f, "Importance: Low\r\n");
+ /* RFC: If no importance is given, the default value is "2 (Normal)" */
+ } else {
+ fprintf(f, "X-Priority: 3 (Normal)\r\n");
+ fprintf(f, "Importance: Normal\r\n");
+ }
+ fprintf(f, "From: Postmaster <%s>\r\n",
+ deliver_set->postmaster_address);
+ fprintf(f, "To: <%s>\r\n", nc->options[nopt]);
+ fprintf(f, "Subject: [SIEVE] New mail notification\r\n");
+ fprintf(f, "Auto-Submitted: auto-generated (notify)\r\n");
+ fprintf(f, "Precedence: bulk\r\n");
+ if (contains_8bit(nc->message)) {
+ fprintf(f, "MIME-Version: 1.0\r\n");
+ fprintf(f, "Content-Type: text/plain; charset=UTF-8\r\n");
+ fprintf(f, "Content-Transfer-Encoding: 8bit\r\n");
+ }
+ fprintf(f, "\r\n");
+ fprintf(f, "%s\r\n", nc->message);
+ if (smtp_client_close(smtp_client) == 0) {
+ i_info("msgid=%s: sent notification to <%s> (method=%s)",
+ m->id == NULL ? "" : str_sanitize(m->id, 80),
+ str_sanitize(nc->options[nopt], 80), nc->method);
+ } else {
+ i_info("msgid=%s: ERROR sending notification to <%s> "
+ "(method=%s)",
+ m->id == NULL ? "" : str_sanitize(m->id, 80),
+ str_sanitize(nc->options[nopt], 80), nc->method);
+ *errmsg = "Error sending notify mail";
+ }
+ nopt = nopt + 1;
+ }
+ return SIEVE_OK;
}
static int autorespond(void *ac,
More information about the dovecot-cvs
mailing list