From 9167a0462f67a85ecfb6c46fb96d765e2f2f0b02 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sat, 25 Feb 2012 17:23:31 +0100 Subject: [PATCH] MailQ: remember & display the room for mailingilst Queue-Entries --- citadel/modules/network/netmail.h | 1 - citadel/modules/network/serv_netmail.c | 5 ++- citadel/modules/smtp/serv_smtpqueue.c | 26 +++++++++++- citadel/modules/smtp/smtpqueue.h | 2 + citadel/msgbase.c | 53 +++++++++++++++---------- citadel/msgbase.h | 1 + citadel/techdoc/delivery-list.txt | 9 +++++ webcit/smtpqueue.c | 25 ++++++++++++ webcit/static/t/view_mailq/message.html | 2 +- 9 files changed, 98 insertions(+), 26 deletions(-) diff --git a/citadel/modules/network/netmail.h b/citadel/modules/network/netmail.h index d2bd14153..c324f4344 100644 --- a/citadel/modules/network/netmail.h +++ b/citadel/modules/network/netmail.h @@ -1,3 +1,2 @@ void network_deliver_digest(SpoolControl *sc); -void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc); void network_spool_msg(long msgnum, void *userdata); diff --git a/citadel/modules/network/serv_netmail.c b/citadel/modules/network/serv_netmail.c index 709877a64..7dcda8db6 100644 --- a/citadel/modules/network/serv_netmail.c +++ b/citadel/modules/network/serv_netmail.c @@ -203,7 +203,7 @@ void network_deliver_digest(SpoolControl *sc) { /* * Deliver list messages to everyone on the list ... efficiently */ -void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc) { +void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc, const char *RoomName) { char *recps = NULL; size_t recps_len = SIZ; struct recptypes *valid; @@ -251,6 +251,7 @@ void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc) { if (valid != NULL) { valid->bounce_to = strdup(bounce_to); valid->envelope_from = strdup(bounce_to); + valid->sending_room = strdup(RoomName); CtdlSubmitMsg(msg, valid, NULL, 0); free_recipients(valid); } @@ -390,7 +391,7 @@ void network_spool_msg(long msgnum, } /* Handle delivery */ - network_deliver_list(msg, sc); + network_deliver_list(msg, sc, CC->room.QRname); CtdlFreeMessage(msg); } } diff --git a/citadel/modules/smtp/serv_smtpqueue.c b/citadel/modules/smtp/serv_smtpqueue.c index 2d406f2e3..c4b46142a 100644 --- a/citadel/modules/smtp/serv_smtpqueue.c +++ b/citadel/modules/smtp/serv_smtpqueue.c @@ -170,6 +170,7 @@ void FreeQueItem(OneQueItem **Item) DeleteHash(&(*Item)->MailQEntries); FreeStrBuf(&(*Item)->EnvelopeFrom); FreeStrBuf(&(*Item)->BounceTo); + FreeStrBuf(&(*Item)->SenderRoom); FreeURL(&(*Item)->URL); free(*Item); Item = NULL; @@ -296,6 +297,11 @@ StrBuf *SerializeQueueItem(OneQueItem *MyQItem) StrBufAppendBuf(QMessage, MyQItem->EnvelopeFrom, 0); } + if (StrLength(MyQItem->SenderRoom) > 0) { + StrBufAppendBufPlain(QMessage, HKEY("\nsource_room|"), 0); + StrBufAppendBuf(QMessage, MyQItem->SenderRoom, 0); + } + StrBufAppendBufPlain(QMessage, HKEY("\nretry|"), 0); StrBufAppendPrintf(QMessage, "%ld", MyQItem->Retry); @@ -364,6 +370,13 @@ void QItem_Handle_BounceTo(OneQueItem *Item, StrBuf *Line, const char **Pos) StrBufExtract_NextToken(Item->BounceTo, Line, Pos, '|'); } +void QItem_Handle_SenderRoom(OneQueItem *Item, StrBuf *Line, const char **Pos) +{ + if (Item->SenderRoom == NULL) + Item->SenderRoom = NewStrBufPlain(NULL, StrLength(Line)); + StrBufExtract_NextToken(Item->SenderRoom, Line, Pos, '|'); +} + void QItem_Handle_Recipient(OneQueItem *Item, StrBuf *Line, const char **Pos) { if (Item->Current == NULL) @@ -555,6 +568,17 @@ void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt) StrBufAppendBuf(BounceMB, Msg, 0); FreeStrBuf(&Msg); + if (StrLength(MyQItem->SenderRoom) > 0) + { + StrBufAppendBufPlain( + BounceMB, + HKEY("The message was originaly posted in: "), 0); + StrBufAppendBuf(BounceMB, MyQItem->SenderRoom, 0); + StrBufAppendBufPlain( + BounceMB, + HKEY("\n"), 0); + } + /* Attach the original message */ StrBufAppendBufPlain(BounceMB, HKEY("--"), 0); StrBufAppendBuf(BounceMB, boundary, 0); @@ -1033,8 +1057,8 @@ CTDL_MODULE_INIT(smtp_queu) Put(QItemHandlers, HKEY("attempted"), QItem_Handle_Attempted, reference_free_handler); Put(QItemHandlers, HKEY("remote"), QItem_Handle_Recipient, reference_free_handler); Put(QItemHandlers, HKEY("bounceto"), QItem_Handle_BounceTo, reference_free_handler); + Put(QItemHandlers, HKEY("source_room"), QItem_Handle_SenderRoom, reference_free_handler); Put(QItemHandlers, HKEY("submitted"), QItem_Handle_Submitted, reference_free_handler); - smtp_init_spoolout(); CtdlRegisterCleanupHook(smtp_evq_cleanup); diff --git a/citadel/modules/smtp/smtpqueue.h b/citadel/modules/smtp/smtpqueue.h index 97b76e790..1b834f9b1 100644 --- a/citadel/modules/smtp/smtpqueue.h +++ b/citadel/modules/smtp/smtpqueue.h @@ -30,6 +30,7 @@ typedef struct _mailq_entry { /**< * 0 = No delivery has yet been attempted * 2 = Delivery was successful + * 3 = Transient error like connection problem. Try next remote if available. * 4 = A transient error was experienced ... try again later * 5 = Delivery to this address failed permanently. The error message * should be placed in the fourth field so that a bounce message may @@ -56,6 +57,7 @@ typedef struct queueitem { long ActiveDeliveries; StrBuf *EnvelopeFrom; StrBuf *BounceTo; + StrBuf *SenderRoom; ParsedURL *URL; ParsedURL *FallBackHost; } OneQueItem; diff --git a/citadel/msgbase.c b/citadel/msgbase.c index cedd10984..6551f696a 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -3027,7 +3027,6 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ int qualified_for_journaling = 0; CitContext *CCC = MyContext(); char bounce_to[1024] = ""; - size_t tmp = 0; int rv = 0; syslog(LOG_DEBUG, "CtdlSubmitMsg() called\n"); @@ -3337,29 +3336,41 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ * contain a recipient. */ if ((recps != NULL) && (recps->num_internet > 0)) { + StrBuf *SpoolMsg = NewStrBuf(); + long nTokens; + syslog(LOG_DEBUG, "Generating delivery instructions\n"); - instr_alloc = 1024; - instr = malloc(instr_alloc); - snprintf(instr, instr_alloc, - "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n" - "bounceto|%s\n", - SPOOLMIME, newmsgid, (long)time(NULL), - bounce_to - ); - if (recps->envelope_from != NULL) { - tmp = strlen(instr); - snprintf(&instr[tmp], instr_alloc-tmp, "envelope_from|%s\n", recps->envelope_from); - } + StrBufPrintf(SpoolMsg, + "Content-type: "SPOOLMIME"\n" + "\n" + "msgid|%ld\n" + "submitted|%ld\n" + "bounceto|%s\n", + newmsgid, + (long)time(NULL), + bounce_to); - for (i=0; irecp_internet, '|'); ++i) { - tmp = strlen(instr); - extract_token(recipient, recps->recp_internet, i, '|', sizeof recipient); - if ((tmp + strlen(recipient) + 32) > instr_alloc) { - instr_alloc = instr_alloc * 2; - instr = realloc(instr, instr_alloc); + if (recps->envelope_from != NULL) { + StrBufAppendBufPlain(SpoolMsg, HKEY("envelope_from|"), 0); + StrBufAppendBufPlain(SpoolMsg, recps->envelope_from, -1, 0); + StrBufAppendBufPlain(SpoolMsg, HKEY("\n"), 0); + } + if (recps->sending_room != NULL) { + StrBufAppendBufPlain(SpoolMsg, HKEY("source_room|"), 0); + StrBufAppendBufPlain(SpoolMsg, recps->sending_room, -1, 0); + StrBufAppendBufPlain(SpoolMsg, HKEY("\n"), 0); + } + + nTokens = num_tokens(recps->recp_internet, '|'); + for (i = 0; i < nTokens; i++) { + long len; + len = extract_token(recipient, recps->recp_internet, i, '|', sizeof recipient); + if (len > 0) { + StrBufAppendBufPlain(SpoolMsg, HKEY("remote|"), 0); + StrBufAppendBufPlain(SpoolMsg, recipient, len, 0); + StrBufAppendBufPlain(SpoolMsg, HKEY("|0||\n"), 0); } - snprintf(&instr[tmp], instr_alloc - tmp, "remote|%s|0||\n", recipient); } imsg = malloc(sizeof(struct CtdlMessage)); @@ -3370,7 +3381,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ imsg->cm_fields['U'] = strdup("QMSG"); imsg->cm_fields['A'] = strdup("Citadel"); imsg->cm_fields['J'] = strdup("do not journal"); - imsg->cm_fields['M'] = instr; /* imsg owns this memory now */ + imsg->cm_fields['M'] = SmashStrBuf(&SpoolMsg); /* imsg owns this memory now */ CtdlSubmitMsg(imsg, NULL, SMTP_SPOOLOUT_ROOM, QP_EADDR); CtdlFreeMessage(imsg); } diff --git a/citadel/msgbase.h b/citadel/msgbase.h index 37a94c63d..59b02457b 100644 --- a/citadel/msgbase.h +++ b/citadel/msgbase.h @@ -75,6 +75,7 @@ struct recptypes { char *display_recp; char *bounce_to; char *envelope_from; + char *sending_room; }; #define RECPTYPES_MAGIC 0xfeeb diff --git a/citadel/techdoc/delivery-list.txt b/citadel/techdoc/delivery-list.txt index f1c221942..da2ba524e 100644 --- a/citadel/techdoc/delivery-list.txt +++ b/citadel/techdoc/delivery-list.txt @@ -75,6 +75,15 @@ fails). phase of the SMTP transaction. If an envelope sender is not supplied, one is extracted from the message body. + INSTRUCTION: source_room + SYNTAX: source_room|Citadel Support + DESCRIPTION: + when sending mailinglist rooms this contains the source room for displaying + and messaging purposes. + + + + -- Once per Remote-part per Queue-Item -- INSTRUCTION: remote diff --git a/webcit/smtpqueue.c b/webcit/smtpqueue.c index 4a30afa45..f5e390825 100644 --- a/webcit/smtpqueue.c +++ b/webcit/smtpqueue.c @@ -275,6 +275,7 @@ typedef struct _mailq_entry { /**< * 0 = No delivery has yet been attempted * 2 = Delivery was successful + * 3 = Transient error like connection problem. Try next remote if available. * 4 = A transient error was experienced ... try again later * 5 = Delivery to this address failed permanently. The error message * should be placed in the fourth field so that a bounce message may @@ -301,6 +302,7 @@ typedef struct queueitem { long ActiveDeliveries; StrBuf *EnvelopeFrom; StrBuf *BounceTo; + StrBuf *SenderRoom; ParsedURL *URL; ParsedURL *FallBackHost; } OneQueItem; @@ -321,6 +323,7 @@ void FreeQueItem(OneQueItem **Item) DeleteHash(&(*Item)->MailQEntries); FreeStrBuf(&(*Item)->EnvelopeFrom); FreeStrBuf(&(*Item)->BounceTo); + FreeStrBuf(&(*Item)->SenderRoom); FreeURL(&(*Item)->URL); free(*Item); Item = NULL; @@ -406,6 +409,18 @@ void tmplput_MailQEnvelopeFrom(StrBuf *Target, WCTemplputParams *TP) OneQueItem *Item = (OneQueItem*) CTX; StrBufAppendTemplate(Target, TP, Item->EnvelopeFrom, 0); } +void tmplput_MailQSourceRoom(StrBuf *Target, WCTemplputParams *TP) +{ + OneQueItem *Item = (OneQueItem*) CTX; + StrBufAppendTemplate(Target, TP, Item->SenderRoom, 0); +} + +int Conditional_MailQ_HaveSourceRoom(StrBuf *Target, WCTemplputParams *TP) +{ + OneQueItem *Item = (OneQueItem*) CTX; + return StrLength(Item->SenderRoom) > 0; +} + void tmplput_MailQRetry(StrBuf *Target, WCTemplputParams *TP) { char datebuf[64]; @@ -477,6 +492,13 @@ void QItem_Handle_BounceTo(OneQueItem *Item, StrBuf *Line, const char **Pos) StrBufExtract_NextToken(Item->BounceTo, Line, Pos, '|'); } +void QItem_Handle_SenderRoom(OneQueItem *Item, StrBuf *Line, const char **Pos) +{ + if (Item->SenderRoom == NULL) + Item->SenderRoom = NewStrBufPlain(NULL, StrLength(Line)); + StrBufExtract_NextToken(Item->SenderRoom, Line, Pos, '|'); +} + void QItem_Handle_Recipient(OneQueItem *Item, StrBuf *Line, const char **Pos) { if (Item->Current == NULL) @@ -626,6 +648,7 @@ InitModule_SMTP_QUEUE Put(QItemHandlers, HKEY("attempted"), QItem_Handle_Attempted, reference_free_handler); Put(QItemHandlers, HKEY("remote"), QItem_Handle_Recipient, reference_free_handler); Put(QItemHandlers, HKEY("bounceto"), QItem_Handle_BounceTo, reference_free_handler); + Put(QItemHandlers, HKEY("source_room"), QItem_Handle_SenderRoom, reference_free_handler); Put(QItemHandlers, HKEY("submitted"), QItem_Handle_Submitted, reference_free_handler); WebcitAddUrlHandler(HKEY("display_smtpqueue"), "", 0, display_smtpqueue, 0); @@ -639,6 +662,8 @@ InitModule_SMTP_QUEUE RegisterNamespace("MAILQ:ATTEMPTED", 0, 0, tmplput_MailQAttempted, NULL, CTX_MAILQITEM); RegisterNamespace("MAILQ:SUBMITTED", 0, 0, tmplput_MailQSubmitted, NULL, CTX_MAILQITEM); RegisterNamespace("MAILQ:ENVELOPEFROM", 0, 1, tmplput_MailQEnvelopeFrom, NULL, CTX_MAILQITEM); + RegisterNamespace("MAILQ:SRCROOM", 0, 1, tmplput_MailQSourceRoom, NULL, CTX_MAILQITEM); + RegisterConditional(HKEY("COND:MAILQ:HAVESRCROOM"), 0, Conditional_MailQ_HaveSourceRoom, CTX_MAILQITEM); RegisterNamespace("MAILQ:RETRY", 0, 0, tmplput_MailQRetry, NULL, CTX_MAILQITEM); RegisterNamespace("MAILQ:RCPT:ADDR", 0, 1, tmplput_MailQRCPT, NULL, CTX_MAILQ_RCPT); diff --git a/webcit/static/t/view_mailq/message.html b/webcit/static/t/view_mailq/message.html index a6e972f86..27ad7d513 100644 --- a/webcit/static/t/view_mailq/message.html +++ b/webcit/static/t/view_mailq/message.html @@ -3,7 +3,7 @@ -
+

-- 2.30.2