From 715008dfb6283528fcac64dc21b88dcbb237abad Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sat, 18 Feb 2012 18:35:59 +0100 Subject: [PATCH] SMTP-Queue-View: templatize register a view for the mailq. its not supporting a separate js for reloading, since the original didn't also. --- webcit/smtpqueue.c | 398 +++++++++++++++++- webcit/static/styles/webcit.css | 8 + webcit/static/t/aide/global_config.html | 2 +- webcit/static/t/view_mailq/footer.html | 7 + webcit/static/t/view_mailq/footer_empty.html | 11 + webcit/static/t/view_mailq/header.html | 31 ++ webcit/static/t/view_mailq/message.html | 11 + .../static/t/view_mailq/message_bearer.html | 2 + webcit/static/t/view_mailq/recipient.html | 4 + webcit/subst.c | 2 + webcit/subst.h | 4 +- 11 files changed, 477 insertions(+), 3 deletions(-) create mode 100644 webcit/static/t/view_mailq/footer.html create mode 100644 webcit/static/t/view_mailq/footer_empty.html create mode 100644 webcit/static/t/view_mailq/header.html create mode 100644 webcit/static/t/view_mailq/message.html create mode 100644 webcit/static/t/view_mailq/message_bearer.html create mode 100644 webcit/static/t/view_mailq/recipient.html diff --git a/webcit/smtpqueue.c b/webcit/smtpqueue.c index 4cb1ce74b..4a30afa45 100644 --- a/webcit/smtpqueue.c +++ b/webcit/smtpqueue.c @@ -3,6 +3,7 @@ */ #include "webcit.h" +HashList *QItemHandlers = NULL; /* * display one message in the queue @@ -181,7 +182,8 @@ void display_smtpqueue_inner_div(void) { Stat.maxload = 10000; Stat.lowest_found = (-1); Stat.highest_found = (-1); - num_msgs = load_msg_ptrs("MSGS ALL", &Stat, NULL); +// num_msgs = load_msg_ptrs("MSGS ALL|0|1", "SUBJ|;QMSG", &Stat, NULL); + num_msgs = load_msg_ptrs("MSGS ", NULL, &Stat, NULL); if (num_msgs > 0) { wc_printf("" @@ -257,10 +259,404 @@ void display_smtpqueue(void) } + + + + + + + + + +typedef struct _mailq_entry { + StrBuf *Recipient; + StrBuf *StatusMessage; + int Status; + /**< + * 0 = No delivery has yet been attempted + * 2 = Delivery was successful + * 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 + * be generated. + */ + + int n; + int Active; +}MailQEntry; + +typedef struct queueitem { + long MessageID; + long QueMsgID; + long Submitted; + int FailNow; + HashList *MailQEntries; +/* copy of the currently parsed item in the MailQEntries list; + * if null add a new one. + */ + MailQEntry *Current; + time_t ReattemptWhen; + time_t Retry; + + long ActiveDeliveries; + StrBuf *EnvelopeFrom; + StrBuf *BounceTo; + ParsedURL *URL; + ParsedURL *FallBackHost; +} OneQueItem; + + +typedef void (*QItemHandler)(OneQueItem *Item, StrBuf *Line, const char **Pos); + + +void FreeMailQEntry(void *qv) +{ + MailQEntry *Q = qv; + FreeStrBuf(&Q->Recipient); + FreeStrBuf(&Q->StatusMessage); + free(Q); +} +void FreeQueItem(OneQueItem **Item) +{ + DeleteHash(&(*Item)->MailQEntries); + FreeStrBuf(&(*Item)->EnvelopeFrom); + FreeStrBuf(&(*Item)->BounceTo); + FreeURL(&(*Item)->URL); + free(*Item); + Item = NULL; +} +void HFreeQueItem(void *Item) +{ + FreeQueItem((OneQueItem**)&Item); +} + + +OneQueItem *DeserializeQueueItem(StrBuf *RawQItem, long QueMsgID) +{ + OneQueItem *Item; + const char *pLine = NULL; + StrBuf *Line; + StrBuf *Token; + + Item = (OneQueItem*)malloc(sizeof(OneQueItem)); + memset(Item, 0, sizeof(OneQueItem)); + Item->Retry = 0; + Item->MessageID = -1; + Item->QueMsgID = QueMsgID; + + Token = NewStrBuf(); + Line = NewStrBufPlain(NULL, 128); + while (pLine != StrBufNOTNULL) { + const char *pItemPart = NULL; + void *vHandler; + + StrBufExtract_NextToken(Line, RawQItem, &pLine, '\n'); + if (StrLength(Line) == 0) continue; + StrBufExtract_NextToken(Token, Line, &pItemPart, '|'); + if (GetHash(QItemHandlers, SKEY(Token), &vHandler)) + { + QItemHandler H; + H = (QItemHandler) vHandler; + H(Item, Line, &pItemPart); + } + } + FreeStrBuf(&Line); + FreeStrBuf(&Token); +/* + Put(ActiveQItems, + LKEY(Item->MessageID), + Item, + HFreeQueItem); +*/ + + return Item; +} + +void tmplput_MailQID(StrBuf *Target, WCTemplputParams *TP) +{ + OneQueItem *Item = (OneQueItem*) CTX; + StrBufAppendPrintf(Target, "%ld", Item->QueMsgID);; +} +void tmplput_MailQPayloadID(StrBuf *Target, WCTemplputParams *TP) +{ + OneQueItem *Item = (OneQueItem*) CTX; + StrBufAppendPrintf(Target, "%ld", Item->MessageID); +} +void tmplput_MailQBounceTo(StrBuf *Target, WCTemplputParams *TP) +{ + OneQueItem *Item = (OneQueItem*) CTX; + StrBufAppendTemplate(Target, TP, Item->BounceTo, 0); +} +void tmplput_MailQAttempted(StrBuf *Target, WCTemplputParams *TP) +{ + char datebuf[64]; + OneQueItem *Item = (OneQueItem*) CTX; + webcit_fmt_date(datebuf, 64, Item->ReattemptWhen, DATEFMT_BRIEF); + StrBufAppendBufPlain(Target, datebuf, -1, 0); +} +void tmplput_MailQSubmitted(StrBuf *Target, WCTemplputParams *TP) +{ + char datebuf[64]; + OneQueItem *Item = (OneQueItem*) CTX; + webcit_fmt_date(datebuf, 64, Item->Submitted, DATEFMT_BRIEF); + StrBufAppendBufPlain(Target, datebuf, -1, 0); +} +void tmplput_MailQEnvelopeFrom(StrBuf *Target, WCTemplputParams *TP) +{ + OneQueItem *Item = (OneQueItem*) CTX; + StrBufAppendTemplate(Target, TP, Item->EnvelopeFrom, 0); +} +void tmplput_MailQRetry(StrBuf *Target, WCTemplputParams *TP) +{ + char datebuf[64]; + OneQueItem *Item = (OneQueItem*) CTX; + + if (Item->Retry == 0) { + StrBufAppendBufPlain(Target, _("First Attempt pending"), -1, 0); + } + else { + webcit_fmt_date(datebuf, sizeof(datebuf), Item->Retry, DATEFMT_BRIEF); + StrBufAppendBufPlain(Target, datebuf, -1, 0); + } +} + +void tmplput_MailQRCPT(StrBuf *Target, WCTemplputParams *TP) +{ + MailQEntry *Entry = (MailQEntry*) CTX; + StrBufAppendTemplate(Target, TP, Entry->Recipient, 0); +} +void tmplput_MailQRCPTStatus(StrBuf *Target, WCTemplputParams *TP) +{ + MailQEntry *Entry = (MailQEntry*) CTX; + StrBufAppendPrintf(Target, "%ld", Entry->Status); +} +void tmplput_MailQStatusMsg(StrBuf *Target, WCTemplputParams *TP) +{ + MailQEntry *Entry = (MailQEntry*) CTX; + StrBufAppendTemplate(Target, TP, Entry->StatusMessage, 0); +} + +HashList *iterate_get_Recipients(StrBuf *Target, WCTemplputParams *TP) +{ + OneQueItem *Item = (OneQueItem*) CTX; + return Item->MailQEntries; +} + + +void NewMailQEntry(OneQueItem *Item) +{ + Item->Current = (MailQEntry*) malloc(sizeof(MailQEntry)); + memset(Item->Current, 0, sizeof(MailQEntry)); + + if (Item->MailQEntries == NULL) + Item->MailQEntries = NewHash(1, Flathash); + Item->Current->StatusMessage = NewStrBuf(); + Item->Current->n = GetCount(Item->MailQEntries); + Put(Item->MailQEntries, + IKEY(Item->Current->n), + Item->Current, + FreeMailQEntry); +} + +void QItem_Handle_MsgID(OneQueItem *Item, StrBuf *Line, const char **Pos) +{ + Item->MessageID = StrBufExtractNext_long(Line, Pos, '|'); +} + +void QItem_Handle_EnvelopeFrom(OneQueItem *Item, StrBuf *Line, const char **Pos) +{ + if (Item->EnvelopeFrom == NULL) + Item->EnvelopeFrom = NewStrBufPlain(NULL, StrLength(Line)); + StrBufExtract_NextToken(Item->EnvelopeFrom, Line, Pos, '|'); +} + +void QItem_Handle_BounceTo(OneQueItem *Item, StrBuf *Line, const char **Pos) +{ + if (Item->BounceTo == NULL) + Item->BounceTo = NewStrBufPlain(NULL, StrLength(Line)); + StrBufExtract_NextToken(Item->BounceTo, Line, Pos, '|'); +} + +void QItem_Handle_Recipient(OneQueItem *Item, StrBuf *Line, const char **Pos) +{ + if (Item->Current == NULL) + NewMailQEntry(Item); + if (Item->Current->Recipient == NULL) + Item->Current->Recipient=NewStrBufPlain(NULL, StrLength(Line)); + StrBufExtract_NextToken(Item->Current->Recipient, Line, Pos, '|'); + Item->Current->Status = StrBufExtractNext_int(Line, Pos, '|'); + StrBufExtract_NextToken(Item->Current->StatusMessage, Line, Pos, '|'); + Item->Current = NULL; // TODO: is this always right? +} + + +void QItem_Handle_retry(OneQueItem *Item, StrBuf *Line, const char **Pos) +{ + Item->Retry = + StrBufExtractNext_int(Line, Pos, '|'); + Item->Retry *= 2; +} + + +void QItem_Handle_Submitted(OneQueItem *Item, StrBuf *Line, const char **Pos) +{ + Item->Submitted = atol(*Pos); + +} + +void QItem_Handle_Attempted(OneQueItem *Item, StrBuf *Line, const char **Pos) +{ + Item->ReattemptWhen = StrBufExtractNext_int(Line, Pos, '|'); +} + + + + + + + + +void render_QUEUE(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset) +{ + WCTemplputParams SubTP; + + memset(&SubTP, 0, sizeof(WCTemplputParams)); + SubTP.Filter.ContextType = CTX_MAILQITEM; + SubTP.Context = DeserializeQueueItem(Mime->Data, Mime->msgnum); + DoTemplate(HKEY("view_mailq_message"),NULL, &SubTP); + FreeQueItem ((OneQueItem**)&SubTP.Context); +} + +void +ServerShutdownModule_SMTP_QUEUE +(void) +{ + DeleteHash(&QItemHandlers); +} +void +ServerStartModule_SMTP_QUEUE +(void) +{ + QItemHandlers = NewHash(0, NULL); +} + +int qview_PrintPageHeader(SharedMessageStatus *Stat, void **ViewSpecific) +{ + if (!WC->is_aide) + { + output_headers(1, 1, 1, 0, 0, 0); + } + else + { + output_headers(1, 1, 2, 0, 0, 0); + } + return 0; +} + +int qview_GetParamsGetServerCall(SharedMessageStatus *Stat, + void **ViewSpecific, + long oper, + char *cmd, + long len, + char *filter, + long flen) +{ + if (!WC->is_aide) + { + DoTemplate(HKEY("aide_required"), NULL, NULL); + end_burst(); + + return 300; + } + else { + snprintf(cmd, len, "MSGS ALL|0|1"); + snprintf(filter, flen, "SUBJ|QMSG"); + DoTemplate(HKEY("view_mailq_header"), NULL, NULL); + return 200; + } +} + +/* + * Display task view + */ +int qview_LoadMsgFromServer(SharedMessageStatus *Stat, + void **ViewSpecific, + message_summary* Msg, + int is_new, + int i) +{ + wcsession *WCC = WC; + const StrBuf *Mime; + + /* Not (yet?) needed here? calview *c = (calview *) *ViewSpecific; */ + read_message(WCC->WBuf, HKEY("view_mailq_message_bearer"), Msg->msgnum, NULL, &Mime); + + return 0; +} + + +int qview_RenderView_or_Tail(SharedMessageStatus *Stat, + void **ViewSpecific, + long oper) +{ + wcsession *WCC = WC; + WCTemplputParams SubTP; + + if (GetCount(WCC->summ) == 0) + DoTemplate(HKEY("view_mailq_footer_empty"),NULL, &SubTP); + else + DoTemplate(HKEY("view_mailq_footer"),NULL, &SubTP); + + return 0; +} +int qview_Cleanup(void **ViewSpecific) +{ + wDumpContent(1); + return 0; +} + void InitModule_SMTP_QUEUE (void) { + + Put(QItemHandlers, HKEY("msgid"), QItem_Handle_MsgID, reference_free_handler); + Put(QItemHandlers, HKEY("envelope_from"), QItem_Handle_EnvelopeFrom, reference_free_handler); + Put(QItemHandlers, HKEY("retry"), QItem_Handle_retry, reference_free_handler); + 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("submitted"), QItem_Handle_Submitted, reference_free_handler); + WebcitAddUrlHandler(HKEY("display_smtpqueue"), "", 0, display_smtpqueue, 0); WebcitAddUrlHandler(HKEY("display_smtpqueue_inner_div"), "", 0, display_smtpqueue_inner_div, 0); + RegisterMimeRenderer(HKEY("application/x-citadel-delivery-list"), render_QUEUE, 1, 9000); + + + RegisterNamespace("MAILQ:ID", 0, 0, tmplput_MailQID, NULL, CTX_MAILQITEM); + RegisterNamespace("MAILQ:PAYLOAD:ID", 0, 0, tmplput_MailQPayloadID, NULL, CTX_MAILQITEM); + RegisterNamespace("MAILQ:BOUNCETO", 0, 1, tmplput_MailQBounceTo, NULL, CTX_MAILQITEM); + 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:RETRY", 0, 0, tmplput_MailQRetry, NULL, CTX_MAILQITEM); + + RegisterNamespace("MAILQ:RCPT:ADDR", 0, 1, tmplput_MailQRCPT, NULL, CTX_MAILQ_RCPT); + RegisterNamespace("MAILQ:RCPT:STATUS", 0, 0, tmplput_MailQRCPTStatus, NULL, CTX_MAILQ_RCPT); + RegisterNamespace("MAILQ:RCPT:STATUSMSG", 0, 1, tmplput_MailQStatusMsg, NULL, CTX_MAILQ_RCPT); + + RegisterIterator("MAILQ:RCPT", 0, NULL, iterate_get_Recipients, + NULL, NULL, CTX_MAILQ_RCPT, CTX_MAILQITEM, IT_NOFLAG); + + + RegisterReadLoopHandlerset( + VIEW_QUEUE, + qview_GetParamsGetServerCall, + qview_PrintPageHeader, + NULL, /* TODO: is this right? */ + NULL, + qview_LoadMsgFromServer, + qview_RenderView_or_Tail, + qview_Cleanup); + } diff --git a/webcit/static/styles/webcit.css b/webcit/static/styles/webcit.css index 278b42e53..884b0d0ae 100644 --- a/webcit/static/styles/webcit.css +++ b/webcit/static/styles/webcit.css @@ -738,6 +738,14 @@ ul.adminitems li { ul.adminitems li span { display: block } +/* Mailq */ +table.mailstatus {background-color: lightgray } +td.mailstatus_0 {background-color: gray } +td.mailstatus_1 {background-color: gray } +td.mailstatus_2 {background-color: green } +td.mailstatus_3 {background-color: orange } +td.mailstatus_4 {background-color: yellow } +td.mailstatus_5 {background-color: red } /* Room list - Tree Node */ diff --git a/webcit/static/t/aide/global_config.html b/webcit/static/t/aide/global_config.html index fb11d1a0d..891c7ec2d 100644 --- a/webcit/static/t/aide/global_config.html +++ b/webcit/static/t/aide/global_config.html @@ -2,5 +2,5 @@
  • -
  • +
  • diff --git a/webcit/static/t/view_mailq/footer.html b/webcit/static/t/view_mailq/footer.html new file mode 100644 index 000000000..2880a2b46 --- /dev/null +++ b/webcit/static/t/view_mailq/footer.html @@ -0,0 +1,7 @@ +
    + + +

    + +


    + diff --git a/webcit/static/t/view_mailq/footer_empty.html b/webcit/static/t/view_mailq/footer_empty.html new file mode 100644 index 000000000..6121b3b91 --- /dev/null +++ b/webcit/static/t/view_mailq/footer_empty.html @@ -0,0 +1,11 @@ + + +

    + +


    + + +

    + +


    + diff --git a/webcit/static/t/view_mailq/header.html b/webcit/static/t/view_mailq/header.html new file mode 100644 index 000000000..919a4f31d --- /dev/null +++ b/webcit/static/t/view_mailq/header.html @@ -0,0 +1,31 @@ + + +
    + + + + diff --git a/webcit/static/t/view_mailq/message.html b/webcit/static/t/view_mailq/message.html new file mode 100644 index 000000000..a6e972f86 --- /dev/null +++ b/webcit/static/t/view_mailq/message.html @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/webcit/static/t/view_mailq/message_bearer.html b/webcit/static/t/view_mailq/message_bearer.html new file mode 100644 index 000000000..939ded0fe --- /dev/null +++ b/webcit/static/t/view_mailq/message_bearer.html @@ -0,0 +1,2 @@ + + diff --git a/webcit/static/t/view_mailq/recipient.html b/webcit/static/t/view_mailq/recipient.html new file mode 100644 index 000000000..62dd82185 --- /dev/null +++ b/webcit/static/t/view_mailq/recipient.html @@ -0,0 +1,4 @@ + + + diff --git a/webcit/subst.c b/webcit/subst.c index f1a01cf55..6e5ab6fc6 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -111,6 +111,8 @@ const char *CtxNames[] = { "Context VCARD", "Context SIEVE List", "Context SIEVE Script", + "Context MailQ-Item", + "Context MailQ-Recipient", "Context UNKNOWN" }; diff --git a/webcit/subst.h b/webcit/subst.h index e04489c5d..3bf491749 100644 --- a/webcit/subst.h +++ b/webcit/subst.h @@ -62,8 +62,10 @@ enum { #define CTX_VCARD 21 #define CTX_SIEVELIST 22 #define CTX_SIEVESCRIPT 23 +#define CTX_MAILQITEM 24 +#define CTX_MAILQ_RCPT 25 -#define CTX_UNKNOWN 24 +#define CTX_UNKNOWN 25 /** -- 2.30.2
    + + + + + + + + + +

    +

    + +
    +