-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I have further updated the patch for sieve notify, so it handles only new style variable substitution: ${from}, ${env-from}, ${subject}. This substitution is only a hack since it should probably move into libsieve when that supports the sieve variables extension.
BTW I could not find any official list of variables which should be recognised, my reasoning behind using the ones above is that cyrus implementation supported the versions of these key words $from$, $env-from$, $subject$ and I still have scripts that make use of this. It is easy enough to migrate the scripts to use the new variables, but where are these actually referred to in RFCs? The earlier patch (versione 0.2) was also incomplete (missing modifications to dbamil.h). This one should solve also that problem. The dbmail.conf parameters remain the same: # Defaults to "NEW MAIL NOTIFICATION" # #SIEVE_NOTIFY_SUBJECT = # # Sender address for sieve notifications. Can be one of: fixed script recipient # Defaults to recipient. # If fixed, sieve notification will be from SIEVE_NOTIFY_SENDER, fallback to recipient # If script, sieve notifications are from the address specified in the script, fallback to recipient # If recipient, sieve notifications are from the Delivered-to header or envelope recipient address of the email # #SIEVE_NOTIFY_SENDER_TYPE = recipient # # Defaults to undefined # #SIEVE_NOTIFY_SENDER = Any further comments or improvements are welcome. thanks, John -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4-svn0 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFHvo1Hd4I3jTtt9EIRAuMVAJ0Z9P0ROgODWyqvGHeAwxWen5jY7ACfZl9y i7MyF+SHv0TthRQNXfpTycE= =5RBe -----END PGP SIGNATURE-----
diff -ur dbmail-2.2.9/dbmail.h dbmail-2.2.9-patch/dbmail.h --- dbmail-2.2.9/dbmail.h 2008-02-20 18:46:11.000000000 +0100 +++ dbmail-2.2.9-patch/dbmail.h 2008-02-21 18:32:17.000000000 +0100 @@ -201,6 +201,7 @@ #define DEFAULT_POSTMASTER "[EMAIL PROTECTED]" #define AUTO_NOTIFY_SENDER "[EMAIL PROTECTED]" #define AUTO_NOTIFY_SUBJECT "NEW MAIL NOTIFICATION" +#define DEFAULT_SIEVE_NOTIFY_SUBJECT "NEW MAIL NOTIFICATION" /* input reading linelimit */ #define MAX_LINESIZE (65*1024) diff -ur dbmail-2.2.9/modules/sortsieve.c dbmail-2.2.9-patch/modules/sortsieve.c --- dbmail-2.2.9/modules/sortsieve.c 2008-02-09 13:08:28.000000000 +0100 +++ dbmail-2.2.9-patch/modules/sortsieve.c 2008-02-21 20:45:22.000000000 +0100 @@ -172,6 +172,8 @@ const char *rc_to, *rc_from; int importance; char * const * options; + field_t val; + field_t fixed_sender; fromaddr = sieve2_getvalue_string(s, "fromaddr"); method = sieve2_getvalue_string(s, "method"); @@ -179,22 +181,37 @@ importance = sieve2_getvalue_int(s, "importance"); options = sieve2_getvalue_stringlist(s, "options"); - // FIXME: should be validated as a user might try - // to forge an address from their script. - rc_from = fromaddr; - if (!rc_from) - rc_from = dbmail_message_get_header(m->message, "Delivered-To"); + // initialize rc_from to the recipient address (default value) + rc_from = dbmail_message_get_header(m->message, "Delivered-To"); if (!rc_from) rc_from = m->message->envelope_recipient->str; - rc_to = dbmail_message_get_header(m->message, "Reply-To"); - if (!rc_to) - rc_to = dbmail_message_get_header(m->message, "Return-Path"); - -// send_notification(m->message, rc_to, rc_from, method, message); + config_get_value("SIEVE_NOTIFY_SENDER_TYPE", "DELIVERY", val); + // use script value for sender address + if (strcasecmp(val, "script") == 0) { + if(fromaddr) + rc_from = fromaddr; + } + // fixed sender address for notifications + if (strcasecmp(val, "fixed") == 0) { + config_get_value("SIEVE_NOTIFY_SENDER", "DELIVERY", val); + if (strlen(val)) + { + g_strlcpy(fixed_sender,val,FIELDSIZE); + rc_from = fixed_sender; + } + } - TRACE(TRACE_INFO, "Notification from [%s] to [%s] was not sent as notify is not supported in this release.", rc_from, rc_to); + // squirrelmail avelsieve 1.9.7 uses options to store destination address for notification + // the new ietf draft will use a URI e.g. "mailto:[EMAIL PROTECTED]" - this codes does not yet support it + rc_to = options[0]; + if (!rc_to) + { + TRACE(TRACE_ERROR, "Notification from [%s] was not sent. No destination address specified in script.", rc_from); + return SIEVE2_OK; + } + send_sieve_notification(m->message, rc_to, rc_from, method, message); return SIEVE2_OK; } @@ -660,7 +677,7 @@ } } if (sieve_config.notify) { - TRACE(TRACE_ERROR, "Sieve notify is not supported in this release."); + TRACE(TRACE_DEBUG, "Sieve notify enabled."); res = sieve2_callbacks(sieve2_context, notify_callbacks); if (res != SIEVE2_OK) { TRACE(TRACE_ERROR, "Error [%d] when calling sieve2_callbacks: [%s]", @@ -715,7 +732,7 @@ sieve2_callbacks(sieve2_context, vacation_callbacks); } if (sieve_config.notify) { - TRACE(TRACE_ERROR, "Sieve notify is not supported in this release."); + TRACE(TRACE_DEBUG, "Sieve notify enabled."); sieve2_callbacks(sieve2_context, notify_callbacks); } if (sieve_config.debug) { diff -ur dbmail-2.2.9/pipe.c dbmail-2.2.9-patch/pipe.c --- dbmail-2.2.9/pipe.c 2008-02-09 13:08:28.000000000 +0100 +++ dbmail-2.2.9-patch/pipe.c 2008-02-22 09:19:45.000000000 +0100 @@ -31,6 +31,33 @@ #define MAX_COMM_SIZE 512 #define RING_SIZE 6 +int str_replace(const char *search, const char *replace, char ** p_subject) +{ + char * position,*new_subject,*temp_str; + + if (!search) return 0; + if (!replace) return 0; + if (!(*p_subject)) return 0; + TRACE(TRACE_INFO, "trying to replace [%s] with [%s] in [%s]",search,replace,*p_subject); + temp_str = g_strdup(*p_subject); + if (!temp_str) + TRACE(TRACE_ERROR, "out of memory in str_replace"); + position = g_strstr_len(temp_str,strlen(temp_str),search); + if (position) + { + *position = '\0'; + new_subject = g_strconcat(temp_str,replace,position+strlen(search), NULL); + g_free(*p_subject); + *p_subject = new_subject; + g_free(temp_str); + return 1; + } + g_free(temp_str); + return 0; +} + + + static int valid_sender(const char *addr) { int ret = 1; @@ -331,6 +358,78 @@ return result; } + +/* + * Send a notification from sieve. + */ + +int send_sieve_notification(struct DbmailMessage *message, const char *to, const char *from, const char *method, const char *body) +{ + const char * subject; + const char * autosubheader, *msg_subject, *msg_from, *msg_env_from; + char * new_body; + int result; + field_t val; + + autosubheader = dbmail_message_get_header(message, "Auto-Submitted"); + if (autosubheader && strcasecmp(autosubheader, "sieve-notify") == 0) + { + TRACE(TRACE_MESSAGE, "Notification from [%s] to [%s] was not sent. Notify loop detected.", from, to); + return 1; + } + + if (!method) + { + TRACE(TRACE_ERROR, "Notification from [%s] to [%s] was not sent. No method specified in script.", from, to); + return 1; + } + + if (strcasecmp(method, "mailto") == 0) + { + config_get_value("SIEVE_NOTIFY_SUBJECT", "DELIVERY", val); + if (! strlen(val)) + subject = g_strdup(DEFAULT_SIEVE_NOTIFY_SUBJECT); + else + subject = g_strdup(val); + + // do variable substitutions in the notify message body + // format $variable$ is used by squirrelmail avelsieve v.1.9.7 + // but also can manage newer format ${variable} + msg_subject = dbmail_message_get_header(message, "Subject"); + msg_from = dbmail_message_get_header(message, "From"); + msg_env_from = message->envelope_recipient->str; + new_body = g_strdup(body); + // if (!new_body) + if (msg_subject) + { + str_replace("${subject}",msg_subject,&new_body); + } + if (msg_from) + { + str_replace("${from}",msg_from,&new_body); + } + if (msg_env_from) + { + str_replace("${env-from}",msg_env_from,&new_body); + } + + struct DbmailMessage *new_message = dbmail_message_new(); + new_message = dbmail_message_construct(new_message, to, from, subject, new_body); + dbmail_message_set_header(new_message, "Auto-Submitted", "sieve-notify"); + result = send_mail(new_message, to, from, NULL, SENDMESSAGE, SENDMAIL); + dbmail_message_free(new_message); + + if(result) + TRACE(TRACE_ERROR, "Notification from [%s] to [%s] was not sent. Error in sending message.", from, to); + + g_free(subject); + g_free(new_body); + return result; + } + + TRACE(TRACE_ERROR, "Notification from [%s] to [%s] was not sent. Unsupported method [%s].", from, to, method); + return 1; +} /* * Send an automatic reply. diff -ur dbmail-2.2.9/pipe.h dbmail-2.2.9-patch/pipe.h --- dbmail-2.2.9/pipe.h 2008-02-09 13:08:28.000000000 +0100 +++ dbmail-2.2.9-patch/pipe.h 2008-02-20 18:22:27.000000000 +0100 @@ -51,5 +51,7 @@ int send_forward_list(struct DbmailMessage *message, struct dm_list *targets, const char *from); int send_alert(u64_t user_idnr, char *subject, char *body); +int send_sieve_notification(struct DbmailMessage *message, + const char *to, const char *from, const char *method, const char *body); #endif
_______________________________________________ Dbmail-dev mailing list Dbmail-dev@dbmail.org http://twister.fastxs.net/mailman/listinfo/dbmail-dev