X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=webcit%2Fsmtpqueue.c;h=b5c750a311a1b4106a9072b8ae20f3e51db4996a;hp=b03c4e0dcdce4d18dfd2efe15f4aaf3e62a7378d;hb=HEAD;hpb=dce0a5f39c40ebf63f06c4ad6549e09bce672f2d diff --git a/webcit/smtpqueue.c b/webcit/smtpqueue.c index b03c4e0dc..b5c750a31 100644 --- a/webcit/smtpqueue.c +++ b/webcit/smtpqueue.c @@ -3,269 +3,10 @@ */ #include "webcit.h" +CtxType CTX_MAILQITEM = CTX_NONE; +CtxType CTX_MAILQ_RCPT = CTX_NONE; HashList *QItemHandlers = NULL; -/* - * display one message in the queue - */ -void display_queue_msg(long msgnum) -{ - char buf[1024]; - char keyword[32]; - int in_body = 0; - int is_delivery_list = 0; - time_t submitted = 0; - time_t attempted = 0; - time_t last_attempt = 0; - int number_of_attempts = 0; - char sender[256]; - char recipients[65536]; - int recipients_len = 0; - char thisrecp[256]; - char thisdsn[256]; - char thismsg[512]; - int thismsg_len; - long msgid = 0; - int len; - - strcpy(sender, ""); - strcpy(recipients, ""); - recipients_len = 0; - - serv_printf("MSG2 %ld", msgnum); - serv_getln(buf, sizeof buf); - if (buf[0] != '1') return; - - while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { - - if (!IsEmptyStr(buf)) { - len = strlen(buf); - if (buf[len - 1] == 13) { - buf[len - 1] = 0; - } - } - - if ( (IsEmptyStr(buf)) && (in_body == 0) ) { - in_body = 1; - } - - if ( (!in_body) - && (!strncasecmp(buf, "Content-type: application/x-citadel-delivery-list", 49)) - ) { - is_delivery_list = 1; - } - - if ( (in_body) && (!is_delivery_list) ) { - while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { - /* Not a delivery list; flush and return quietly. */ - } - return; - } - - if ( (in_body) && (is_delivery_list) ) { - extract_token(keyword, buf, 0, '|', sizeof keyword); - - if (!strcasecmp(keyword, "msgid")) { - msgid = extract_long(buf, 1); - } - - if (!strcasecmp(keyword, "submitted")) { - submitted = extract_long(buf, 1); - } - - if (!strcasecmp(keyword, "attempted")) { - attempted = extract_long(buf, 1); - ++number_of_attempts; - if (attempted > last_attempt) { - last_attempt = attempted; - } - } - - if (!strcasecmp(keyword, "bounceto")) { - char *atsign; - extract_token(sender, buf, 1, '|', sizeof sender); - - /* Strip off local hostname if it's our own */ - atsign = strchr(sender, '@'); - if (atsign != NULL) { - ++atsign; - if (!strcasecmp(atsign, ChrPtr(WC->serv_info->serv_nodename))) { - --atsign; - *atsign = 0; - } - } - } - - if (!strcasecmp(keyword, "remote")) { - thismsg[0] = 0; - - extract_token(thisrecp, buf, 1, '|', sizeof thisrecp); - extract_token(thisdsn, buf, 3, '|', sizeof thisdsn); - - if (!IsEmptyStr(thisrecp)) { - stresc(thismsg, sizeof thismsg, thisrecp, 1, 1); - if (!IsEmptyStr(thisdsn)) { - strcat(thismsg, "
  "); - stresc(&thismsg[strlen(thismsg)], sizeof thismsg, - thisdsn, 1, 1); - strcat(thismsg, ""); - } - thismsg_len = strlen(thismsg); - - if ((recipients_len + thismsg_len + 100) < sizeof recipients) { - if (!IsEmptyStr(recipients)) { - strcpy(&recipients[recipients_len], "
"); - recipients_len += 6; - } - strcpy(&recipients[recipients_len], thismsg); - recipients_len += thismsg_len; - } - } - - } - - } - - } - - wc_printf(""); - wc_printf("%ld
", msgnum); - wc_printf(" %s", - msgnum, msgid, _("(Delete)") - ); - - wc_printf(""); - if (submitted > 0) { - webcit_fmt_date(buf, 1024, submitted, 1); - wc_printf("%s", buf); - } - else { - wc_printf(" "); - } - - wc_printf(""); - if (last_attempt > 0) { - webcit_fmt_date(buf, 1024, last_attempt, 1); - wc_printf("%s", buf); - } - else { - wc_printf(" "); - } - - wc_printf(""); - escputs(sender); - - wc_printf(""); - wc_printf("%s", recipients); - wc_printf("\n"); - -} - - -void display_smtpqueue_inner_div(void) { - message_summary *Msg = NULL; - wcsession *WCC = WC; - int i; - int num_msgs; - StrBuf *Buf; - SharedMessageStatus Stat; - - memset(&Stat, 0, sizeof(SharedMessageStatus)); - /* Check to see if we can go to the __CitadelSMTPspoolout__ room. - * If not, we don't have access to the queue. - */ - Buf = NewStrBufPlain(HKEY("__CitadelSMTPspoolout__")); - gotoroom(Buf); - FreeStrBuf(&Buf); - if (!strcasecmp(ChrPtr(WCC->CurRoom.name), "__CitadelSMTPspoolout__")) { - - Stat.maxload = 10000; - Stat.lowest_found = (-1); - Stat.highest_found = (-1); -// 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("" - ); - - wc_printf("\n"); - - for (i=0; (i < num_msgs) && (i < Stat.maxload); ++i) { - Msg = GetMessagePtrAt(i, WCC->summ); - if (Msg != NULL) { - display_queue_msg(Msg->msgnum); - } - } - - wc_printf("
"); - wc_printf(_("Message ID")); - wc_printf(""); - wc_printf(_("Date/time submitted")); - wc_printf(""); - wc_printf(_("Last attempt")); - wc_printf(""); - wc_printf(_("Sender")); - wc_printf(""); - wc_printf(_("Recipients")); - wc_printf("
"); - - } - else { - wc_printf("

"); - wc_printf(_("The queue is empty.")); - wc_printf("


"); - } - } - else { - wc_printf("

"); - wc_printf(_("You do not have permission to view this resource.")); - wc_printf("


"); - } - output_headers(0, 0, 0, 0, 0, 0); - end_burst(); -} - -/* - * display the outbound SMTP queue - */ -void display_smtpqueue(void) -{ - output_headers(1, 1, 2, 0, 0, 0); - - wc_printf("
\n"); - wc_printf("

"); - wc_printf(_("View the outbound SMTP queue")); - wc_printf("

\n"); - wc_printf("
\n"); - - wc_printf("
\n"); - - wc_printf("" - "
\n"); - - wc_printf("
" - "
" - "
" - "
" - "%s" - "
" - "
\n", _("Refresh this page") - ); - - StrBufAppendPrintf(WC->trailing_javascript, "RefreshSMTPqueueDisplay();\n"); - - wDumpContent(1); - -} - - - - - - - - typedef struct _mailq_entry { @@ -387,54 +128,54 @@ OneQueItem *DeserializeQueueItem(StrBuf *RawQItem, long QueMsgID) void tmplput_MailQID(StrBuf *Target, WCTemplputParams *TP) { - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); StrBufAppendPrintf(Target, "%ld", Item->QueMsgID);; } void tmplput_MailQPayloadID(StrBuf *Target, WCTemplputParams *TP) { - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); StrBufAppendPrintf(Target, "%ld", Item->MessageID); } void tmplput_MailQBounceTo(StrBuf *Target, WCTemplputParams *TP) { - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); StrBufAppendTemplate(Target, TP, Item->BounceTo, 0); } void tmplput_MailQAttempted(StrBuf *Target, WCTemplputParams *TP) { char datebuf[64]; - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); 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; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); 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; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); StrBufAppendTemplate(Target, TP, Item->EnvelopeFrom, 0); } void tmplput_MailQSourceRoom(StrBuf *Target, WCTemplputParams *TP) { - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); StrBufAppendTemplate(Target, TP, Item->SenderRoom, 0); } int Conditional_MailQ_HaveSourceRoom(StrBuf *Target, WCTemplputParams *TP) { - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); return StrLength(Item->SenderRoom) > 0; } void tmplput_MailQRetry(StrBuf *Target, WCTemplputParams *TP) { char datebuf[64]; - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); if (Item->Retry == 0) { StrBufAppendBufPlain(Target, _("First Attempt pending"), -1, 0); @@ -447,23 +188,23 @@ void tmplput_MailQRetry(StrBuf *Target, WCTemplputParams *TP) void tmplput_MailQRCPT(StrBuf *Target, WCTemplputParams *TP) { - MailQEntry *Entry = (MailQEntry*) CTX; + MailQEntry *Entry = (MailQEntry*) CTX(CTX_MAILQ_RCPT); StrBufAppendTemplate(Target, TP, Entry->Recipient, 0); } void tmplput_MailQRCPTStatus(StrBuf *Target, WCTemplputParams *TP) { - MailQEntry *Entry = (MailQEntry*) CTX; + MailQEntry *Entry = (MailQEntry*) CTX(CTX_MAILQ_RCPT); StrBufAppendPrintf(Target, "%ld", Entry->Status); } void tmplput_MailQStatusMsg(StrBuf *Target, WCTemplputParams *TP) { - MailQEntry *Entry = (MailQEntry*) CTX; + MailQEntry *Entry = (MailQEntry*) CTX(CTX_MAILQ_RCPT); StrBufAppendTemplate(Target, TP, Entry->StatusMessage, 0); } HashList *iterate_get_Recipients(StrBuf *Target, WCTemplputParams *TP) { - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); return Item->MailQEntries; } @@ -511,6 +252,7 @@ void QItem_Handle_SenderRoom(OneQueItem *Item, StrBuf *Line, const char **Pos) void QItem_Handle_Recipient(OneQueItem *Item, StrBuf *Line, const char **Pos) { + const char *pch; if (Item->Current == NULL) NewMailQEntry(Item); if (Item->Current->Recipient == NULL) @@ -518,6 +260,18 @@ void QItem_Handle_Recipient(OneQueItem *Item, StrBuf *Line, const char **Pos) StrBufExtract_NextToken(Item->Current->Recipient, Line, Pos, '|'); Item->Current->Status = StrBufExtractNext_int(Line, Pos, '|'); StrBufExtract_NextToken(Item->Current->StatusMessage, Line, Pos, '|'); + + pch = ChrPtr(Item->Current->StatusMessage); + while ((pch != NULL) && (*pch != '\0')) { + pch = strchr(pch, ';'); + if (pch != NULL) { + pch ++; + if (*pch == ' ') { + StrBufPeek(Item->Current->StatusMessage, + pch, -1, '\n'); + } + } + } Item->Current = NULL; // TODO: is this always right? } @@ -542,19 +296,20 @@ void QItem_Handle_Attempted(OneQueItem *Item, StrBuf *Line, const char **Pos) - - - - -void render_QUEUE(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset) +void render_QUEUE(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset) { + wc_mime_attachment *Mime = CTX(CTX_MIME_ATACH); WCTemplputParams SubTP; + OneQueItem* Context; - 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); + Context = DeserializeQueueItem(Mime->Data, Mime->msgnum); + StackContext(TP, &SubTP, Context, CTX_MAILQITEM, 0, TP->Tokens); + { + DoTemplate(HKEY("view_mailq_message"), NULL, &SubTP); + } + UnStackContext(&SubTP); + + FreeQueItem (&Context); } void @@ -572,14 +327,10 @@ ServerStartModule_SMTP_QUEUE int qview_PrintPageHeader(SharedMessageStatus *Stat, void **ViewSpecific) { - if (!WC->is_aide) - { - output_headers(1, 1, 1, 0, 0, 0); - } + if (yesbstr("ListOnly")) + output_headers(1, 0, 0, 0, 0, 0); else - { - output_headers(1, 1, 2, 0, 0, 0); - } + output_headers(1, 1, 1, 0, 0, 0); return 0; } @@ -601,7 +352,10 @@ int qview_GetParamsGetServerCall(SharedMessageStatus *Stat, else { snprintf(cmd, len, "MSGS ALL|0|1"); snprintf(filter, flen, "SUBJ|QMSG"); - DoTemplate(HKEY("view_mailq_header"), NULL, NULL); + if (yesbstr("ListOnly")) + DoTemplate(HKEY("view_mailq_table"), NULL, NULL); + else + DoTemplate(HKEY("view_mailq_header"), NULL, NULL); return 200; } } @@ -619,7 +373,7 @@ int qview_LoadMsgFromServer(SharedMessageStatus *Stat, const StrBuf *Mime; /* Not (yet?) needed here? calview *c = (calview *) *ViewSpecific; */ - read_message(WCC->WBuf, HKEY("view_mailq_message_bearer"), Msg->msgnum, NULL, &Mime); + read_message(WCC->WBuf, HKEY("view_mailq_message_bearer"), Msg->msgnum, NULL, &Mime, NULL); return 0; } @@ -632,16 +386,23 @@ int qview_RenderView_or_Tail(SharedMessageStatus *Stat, wcsession *WCC = WC; WCTemplputParams SubTP; - if (GetCount(WCC->summ) == 0) - DoTemplate(HKEY("view_mailq_footer_empty"),NULL, &SubTP); + memset(&SubTP, 0, sizeof(WCTemplputParams)); + if (yesbstr("ListOnly")) + DoTemplate(HKEY("view_mailq_footer_listonly"),NULL, &SubTP); else - DoTemplate(HKEY("view_mailq_footer"),NULL, &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); + + wDumpContent(yesbstr("ListOnly")?0:1); return 0; } @@ -649,6 +410,8 @@ void InitModule_SMTP_QUEUE (void) { + RegisterCTX(CTX_MAILQITEM); + RegisterCTX(CTX_MAILQ_RCPT); RegisterQItemHandler(HKEY("msgid"), QItem_Handle_MsgID); RegisterQItemHandler(HKEY("envelope_from"), QItem_Handle_EnvelopeFrom); @@ -658,12 +421,7 @@ InitModule_SMTP_QUEUE RegisterQItemHandler(HKEY("bounceto"), QItem_Handle_BounceTo); RegisterQItemHandler(HKEY("source_room"), QItem_Handle_SenderRoom); RegisterQItemHandler(HKEY("submitted"), QItem_Handle_Submitted); - - 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); @@ -671,7 +429,7 @@ InitModule_SMTP_QUEUE 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); + RegisterConditional("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); @@ -690,6 +448,7 @@ InitModule_SMTP_QUEUE NULL, qview_LoadMsgFromServer, qview_RenderView_or_Tail, - qview_Cleanup); + qview_Cleanup, + NULL); }