X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=webcit%2Fmsg_renderers.c;h=9c63236903813da9046d502827dc2c5930e4a8a4;hp=459f8e9554e926c0b7e590a472e331c6ba77b934;hb=dda7d0d3dfaa0a7fede33155e2795f4379d492e7;hpb=a3ba94ad306d781296c53012f732f3a910015263
diff --git a/webcit/msg_renderers.c b/webcit/msg_renderers.c
index 459f8e955..9c6323690 100644
--- a/webcit/msg_renderers.c
+++ b/webcit/msg_renderers.c
@@ -1,6 +1,17 @@
#include "webcit.h"
#include "webserver.h"
-#include "groupdav.h"
+#include "dav.h"
+
+CtxType CTX_MAILSUM = CTX_NONE;
+CtxType CTX_MIME_ATACH = CTX_NONE;
+
+static inline void CheckConvertBufs(struct wcsession *WCC)
+{
+ if (WCC->ConvertBuf1 == NULL)
+ WCC->ConvertBuf1 = NewStrBuf();
+ if (WCC->ConvertBuf2 == NULL)
+ WCC->ConvertBuf2 = NewStrBuf();
+}
/*
* message index functions
@@ -35,15 +46,15 @@ void DestroyMessageSummary(void *vMsg)
FreeStrBuf(&Msg->reply_inreplyto);
FreeStrBuf(&Msg->reply_references);
FreeStrBuf(&Msg->cccc);
+ FreeStrBuf(&Msg->ReplyTo);
FreeStrBuf(&Msg->hnod);
FreeStrBuf(&Msg->AllRcpt);
FreeStrBuf(&Msg->Room);
FreeStrBuf(&Msg->Rfca);
+ FreeStrBuf(&Msg->EnvTo);
FreeStrBuf(&Msg->OtherNode);
- FreeStrBuf(&Msg->reply_to);
-
- DeleteHash(&Msg->Attachments); /**< list of Accachments */
+ DeleteHash(&Msg->Attachments); /* list of Attachments */
DeleteHash(&Msg->Submessages);
DeleteHash(&Msg->AttachLinks);
DeleteHash(&Msg->AllAttach);
@@ -239,7 +250,7 @@ void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
}
int Conditional_ANONYMOUS_MESSAGE(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
return Msg->nhdr != 0;
}
@@ -251,73 +262,151 @@ void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
+ wcsession *WCC = WC;
+
+ CheckConvertBufs(WCC);
FreeStrBuf(&Msg->from);
Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset, FoundCharset);
+ StrBuf_RFC822_2_Utf8(Msg->from,
+ HdrLine,
+ WCC->DefaultCharset,
+ FoundCharset,
+ WCC->ConvertBuf1,
+ WCC->ConvertBuf2);
}
void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendTemplate(Target, TP, Msg->from, 0);
}
-
-
void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
+ wcsession *WCC = WC;
+
+ CheckConvertBufs(WCC);
FreeStrBuf(&Msg->subj);
Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset, FoundCharset);
+ StrBuf_RFC822_2_Utf8(Msg->subj,
+ HdrLine,
+ WCC->DefaultCharset,
+ FoundCharset,
+ WCC->ConvertBuf1,
+ WCC->ConvertBuf2);
}
void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
-{/*////TODO: Fwd: and RE: filter!!*/
+{
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
- message_summary *Msg = (message_summary*) CTX;
+ if (TP->Tokens->nParameters == 4)
+ {
+ const char *pch;
+ long len;
+
+ GetTemplateTokenString(Target, TP, 3, &pch, &len);
+ if ((len > 0)&&
+ (strstr(ChrPtr(Msg->subj), pch) == NULL))
+ {
+ GetTemplateTokenString(Target, TP, 2, &pch, &len);
+ StrBufAppendBufPlain(Target, pch, len, 0);
+ }
+ }
StrBufAppendTemplate(Target, TP, Msg->subj, 0);
}
int Conditional_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
+
+
return StrLength(Msg->subj) > 0;
}
void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
+ wcsession *WCC = WC;
+
+ CheckConvertBufs(WCC);
FreeStrBuf(&Msg->reply_inreplyto);
Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset, FoundCharset);
+ StrBuf_RFC822_2_Utf8(Msg->reply_inreplyto,
+ HdrLine,
+ WCC->DefaultCharset,
+ FoundCharset,
+ WCC->ConvertBuf1,
+ WCC->ConvertBuf2);
}
void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendTemplate(Target, TP, Msg->reply_inreplyto, 0);
}
int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
- return Msg->is_new != 0;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
+ return (Msg->Flags & MSGFLAG_READ) != 0;
}
void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
+ wcsession *WCC = WC;
+
+ CheckConvertBufs(WCC);
FreeStrBuf(&Msg->reply_references);
Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset, FoundCharset);
+ StrBuf_RFC822_2_Utf8(Msg->reply_references,
+ HdrLine,
+ WCC->DefaultCharset,
+ FoundCharset,
+ WCC->ConvertBuf1,
+ WCC->ConvertBuf2);
}
void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendTemplate(Target, TP, Msg->reply_references, 0);
}
+void examine_replyto(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
+{
+ wcsession *WCC = WC;
+
+ CheckConvertBufs(WCC);
+ FreeStrBuf(&Msg->ReplyTo);
+ Msg->ReplyTo = NewStrBufPlain(NULL, StrLength(HdrLine));
+ StrBuf_RFC822_2_Utf8(Msg->ReplyTo,
+ HdrLine,
+ WCC->DefaultCharset,
+ FoundCharset,
+ WCC->ConvertBuf1,
+ WCC->ConvertBuf2);
+ if (Msg->AllRcpt == NULL)
+ Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
+ if (StrLength(Msg->AllRcpt) > 0) {
+ StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
+ }
+ StrBufAppendBuf(Msg->AllRcpt, Msg->ReplyTo, 0);
+}
+void tmplput_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
+{
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
+ StrBufAppendTemplate(Target, TP, Msg->ReplyTo, 0);
+}
void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
+ wcsession *WCC = WC;
+
+ CheckConvertBufs(WCC);
FreeStrBuf(&Msg->cccc);
Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->cccc, HdrLine, WC->DefaultCharset, FoundCharset);
+ StrBuf_RFC822_2_Utf8(Msg->cccc,
+ HdrLine,
+ WCC->DefaultCharset,
+ FoundCharset,
+ WCC->ConvertBuf1,
+ WCC->ConvertBuf2);
if (Msg->AllRcpt == NULL)
Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
if (StrLength(Msg->AllRcpt) > 0) {
@@ -327,7 +416,7 @@ void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
}
void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendTemplate(Target, TP, Msg->cccc, 0);
}
@@ -342,7 +431,7 @@ void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
}
void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendTemplate(Target, TP, Msg->Room, 0);
}
@@ -354,19 +443,24 @@ void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
}
void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendTemplate(Target, TP, Msg->Rfca, 0);
}
int Conditional_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
return StrLength(Msg->Rfca) > 0;
}
int Conditional_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
return StrLength(Msg->cccc) > 0;
}
+int Conditional_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
+{
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
+ return StrLength(Msg->ReplyTo) > 0;
+}
void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
@@ -382,21 +476,44 @@ void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
}
void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendTemplate(Target, TP, Msg->OtherNode, 0);
}
int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
return StrLength(Msg->OtherNode) > 0;
}
+void examine_nvto(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
+{
+ wcsession *WCC = WC;
+
+ CheckConvertBufs(WCC);
+ FreeStrBuf(&Msg->EnvTo);
+ Msg->EnvTo = NewStrBufPlain(NULL, StrLength(HdrLine));
+ StrBuf_RFC822_2_Utf8(Msg->EnvTo,
+ HdrLine,
+ WCC->DefaultCharset,
+ FoundCharset,
+ WCC->ConvertBuf1,
+ WCC->ConvertBuf2);
+}
+
void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
+ wcsession *WCC = WC;
+
+ CheckConvertBufs(WCC);
FreeStrBuf(&Msg->to);
Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->to, HdrLine, WC->DefaultCharset, FoundCharset);
+ StrBuf_RFC822_2_Utf8(Msg->to,
+ HdrLine,
+ WCC->DefaultCharset,
+ FoundCharset,
+ WCC->ConvertBuf1,
+ WCC->ConvertBuf2);
if (Msg->AllRcpt == NULL)
Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
if (StrLength(Msg->AllRcpt) > 0) {
@@ -406,22 +523,22 @@ void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
}
void tmplput_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendTemplate(Target, TP, Msg->to, 0);
}
int Conditional_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
return StrLength(Msg->to) != 0;
}
int Conditional_MAIL_SUMM_SUBJ(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
return StrLength(Msg->subj) != 0;
}
void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendTemplate(Target, TP, Msg->AllRcpt, 0);
}
@@ -444,28 +561,35 @@ void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
{
char datebuf[64];
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_BRIEF);
StrBufAppendBufPlain(Target, datebuf, -1, 0);
}
+void tmplput_MAIL_SUMM_EUID(StrBuf *Target, WCTemplputParams *TP)
+{
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
+ StrBufAppendTemplate(Target, TP, Msg->euid, 0);
+}
+
void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
{
char datebuf[64];
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_FULL);
StrBufAppendBufPlain(Target, datebuf, -1, 0);
}
void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
}
-void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_MAIL(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
{
+ wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
const StrBuf *TemplateMime;
if (Mime->Data == NULL)
@@ -486,10 +610,12 @@ void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset
*/
}
-void render_MIME_VCard(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_MIME_VCard(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
{
+ wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
wcsession *WCC = WC;
- MimeLoadData(Mime);
+ if (StrLength(Mime->Data) == 0)
+ MimeLoadData(Mime);
if (StrLength(Mime->Data) > 0) {
StrBuf *Buf;
Buf = NewStrBuf();
@@ -504,48 +630,16 @@ void render_MIME_VCard(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundC
}
/* In all cases, display the full card */
- display_vcard(Buf, Mime->Data, 0, 1, NULL, Mime->msgnum);
+ display_vcard(Buf, Mime, 0, 1, NULL, -1);
FreeStrBuf(&Mime->Data);
Mime->Data = Buf;
}
}
-void render_MIME_VNote(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
-{
- MimeLoadData(Mime);
- if (StrLength(Mime->Data) > 0) {
- struct vnote *v;
- StrBuf *Buf;
- char *vcard;
-
- Buf = NewStrBuf();
- vcard = SmashStrBuf(&Mime->Data);
- v = vnote_new_from_str(vcard);
- free (vcard);
- if (v) {
- WCTemplputParams TP;
-
- memset(&TP, 0, sizeof(WCTemplputParams));
- TP.Filter.ContextType = CTX_VNOTE;
- TP.Context = v;
- DoTemplate(HKEY("mail_vnoteitem"),
- Buf, &TP);
-
- vnote_free(v);
- Mime->Data = Buf;
- }
- else {
- if (Mime->Data == NULL)
- Mime->Data = NewStrBuf();
- else
- FlushStrBuf(Mime->Data);
- }
- }
-}
-
-void render_MIME_ICS(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_MIME_ICS(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
{
+ wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
if (StrLength(Mime->Data) == 0) {
MimeLoadData(Mime);
}
@@ -558,26 +652,39 @@ void render_MIME_ICS(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCha
void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
+ const char *Ptr = NULL;
wc_mime_attachment *Mime;
StrBuf *Buf;
-
+ wcsession *WCC = WC;
+
+ CheckConvertBufs(WCC);
Mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
memset(Mime, 0, sizeof(wc_mime_attachment));
Mime->msgnum = Msg->msgnum;
Buf = NewStrBuf();
Mime->Name = NewStrBuf();
- StrBufExtract_token(Buf, HdrLine, 0, '|');
- StrBuf_RFC822_to_Utf8(Mime->Name, Buf, WC->DefaultCharset, FoundCharset);
+ StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
+ StrBuf_RFC822_2_Utf8(Mime->Name,
+ Buf,
+ WCC->DefaultCharset,
+ FoundCharset,
+ WCC->ConvertBuf1,
+ WCC->ConvertBuf2);
StrBufTrim(Mime->Name);
- StrBufExtract_token(Buf, HdrLine, 1, '|');
+ StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
Mime->FileName = NewStrBuf();
- StrBuf_RFC822_to_Utf8(Mime->FileName, Buf, WC->DefaultCharset, FoundCharset);
+ StrBuf_RFC822_2_Utf8(Mime->FileName,
+ Buf,
+ WCC->DefaultCharset,
+ FoundCharset,
+ WCC->ConvertBuf1,
+ WCC->ConvertBuf2);
StrBufTrim(Mime->FileName);
Mime->PartNum = NewStrBuf();
- StrBufExtract_token(Mime->PartNum, HdrLine, 2, '|');
+ StrBufExtract_NextToken(Mime->PartNum, HdrLine, &Ptr, '|');
StrBufTrim(Mime->PartNum);
if (strchr(ChrPtr(Mime->PartNum), '.') != NULL)
Mime->level = 2;
@@ -585,18 +692,24 @@ void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundChars
Mime->level = 1;
Mime->Disposition = NewStrBuf();
- StrBufExtract_token(Mime->Disposition, HdrLine, 3, '|');
+ StrBufExtract_NextToken(Mime->Disposition, HdrLine, &Ptr, '|');
Mime->ContentType = NewStrBuf();
- StrBufExtract_token(Mime->ContentType, HdrLine, 4, '|');
+ StrBufExtract_NextToken(Mime->ContentType, HdrLine, &Ptr, '|');
StrBufTrim(Mime->ContentType);
StrBufLowerCase(Mime->ContentType);
-
if (!strcmp(ChrPtr(Mime->ContentType), "application/octet-stream")) {
StrBufPlain(Mime->ContentType,
GuessMimeByFilename(SKEY(Mime->FileName)), -1);
}
- Mime->length = StrBufExtract_int(HdrLine, 5, '|');
+
+ Mime->length = StrBufExtractNext_int(HdrLine, &Ptr, '|');
+
+ StrBufSkip_NTokenS(HdrLine, &Ptr, '|', 1); /* cbid?? */
+
+ Mime->Charset = NewStrBuf();
+ StrBufExtract_NextToken(Mime->Charset, HdrLine, &Ptr, '|');
+
if ( (StrLength(Mime->FileName) == 0) && (StrLength(Mime->Name) > 0) ) {
StrBufAppendBuf(Mime->FileName, Mime->Name, 0);
@@ -617,12 +730,14 @@ void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundChars
}
-void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime)
+void evaluate_mime_part(StrBuf *Target, WCTemplputParams *TP)
{
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
+ wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
void *vMimeRenderer;
/* just print the root-node */
- if ((Mime->level == 1) &&
+ if ((Mime->level >= 1) &&
GetHash(MimeRenderHandler, SKEY(Mime->ContentType), &vMimeRenderer) &&
vMimeRenderer != NULL)
{
@@ -631,14 +746,14 @@ void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime)
Msg->Submessages = NewHash(1,NULL);
Put(Msg->Submessages, SKEY(Mime->PartNum), Mime, reference_free_handler);
}
- else if ((Mime->level == 1) &&
+ else if ((Mime->level >= 1) &&
(!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
&& (!strncasecmp(ChrPtr(Mime->ContentType), "image/", 6)) ){
if (Msg->AttachLinks == NULL)
Msg->AttachLinks = NewHash(1,NULL);
Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
}
- else if ((Mime->level == 1) &&
+ else if ((Mime->level >= 1) &&
(StrLength(Mime->ContentType) > 0) &&
( (!strcasecmp(ChrPtr(Mime->Disposition), "attachment"))
|| (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
@@ -659,25 +774,33 @@ void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime)
void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
}
void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
+ wcsession *WCC = WC;
+
+ CheckConvertBufs(WCC);
FreeStrBuf(&Msg->hnod);
Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset, FoundCharset);
+ StrBuf_RFC822_2_Utf8(Msg->hnod,
+ HdrLine,
+ WCC->DefaultCharset,
+ FoundCharset,
+ WCC->ConvertBuf1,
+ WCC->ConvertBuf2);
}
void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendTemplate(Target, TP, Msg->hnod, 0);
}
int Conditional_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
return StrLength(Msg->hnod) > 0;
}
@@ -747,42 +870,97 @@ void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCh
Hdr = (headereval*)vHdr;
Hdr->evaluator(Msg, Value, FoundCharset);
}
- else lprintf(1, "don't know how to handle content type sub-header[%s]\n", ChrPtr(Token));
+ else syslog(LOG_WARNING, "don't know how to handle content type sub-header[%s]\n", ChrPtr(Token));
}
FreeStrBuf(&Token);
FreeStrBuf(&Value);
}
}
+
+message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, StrBuf *FoundCharset, long MsgNum)
+{
+ void *vHdr;
+ headereval *Hdr;
+ message_summary *Msg;
+ StrBuf *Buf;
+ const char *buf;
+ const char *ebuf;
+ int nBuf;
+ long len;
+
+ Buf = NewStrBuf();
+
+ serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
+
+ StrBuf_ServGetln(Buf);
+ if (GetServerStatus(Buf, NULL) == 1) {
+ FreeStrBuf(&Buf);
+ return NULL;
+ }
+
+ Msg = (message_summary*)malloc(sizeof(message_summary));
+ memset(Msg, 0, sizeof(message_summary));
+ while (len = StrBuf_ServGetln(Buf),
+ (len >= 0) &&
+ ((len != 3) ||
+ strcmp(ChrPtr(Buf), "000")))
+ {
+ buf = ChrPtr(Buf);
+ ebuf = strchr(ChrPtr(Buf), '=');
+ nBuf = ebuf - buf;
+
+ if (GetHash(MsgHeaderHandler, buf, nBuf, &vHdr) &&
+ (vHdr != NULL)) {
+ Hdr = (headereval*)vHdr;
+ StrBufCutLeft(Buf, nBuf + 1);
+ Hdr->evaluator(Msg, Buf, FoundCharset);
+ }
+ else syslog(LOG_INFO, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
+ }
+ return Msg;
+}
+
void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
}
+void tmplput_MAIL_SUMM_PERMALINK(StrBuf *Target, WCTemplputParams *TP)
+{
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
+ char perma_link[1024];
+
+ strcpy(perma_link, "/readfwd?go=");
+ urlesc(&perma_link[12], sizeof(perma_link) - 12, (char *)ChrPtr(WC->CurRoom.name) );
+ sprintf(&perma_link[strlen(perma_link)], "?start_reading_at=%ld#%ld", Msg->msgnum, Msg->msgnum);
+ StrBufAppendPrintf(Target, "%s", perma_link);
+}
+
int Conditional_MAIL_MIME_ALL(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
return GetCount(Msg->Attachments) > 0;
}
int Conditional_MAIL_MIME_SUBMESSAGES(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
return GetCount(Msg->Submessages) > 0;
}
int Conditional_MAIL_MIME_ATTACHLINKS(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
return GetCount(Msg->AttachLinks) > 0;
}
int Conditional_MAIL_MIME_ATTACH(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
return GetCount(Msg->AllAttach) > 0;
}
@@ -818,40 +996,53 @@ void tmplput_EDIT_WIKI_BODY(StrBuf *Target, WCTemplputParams *TP)
long msgnum;
StrBuf *Buf;
- msgnum = locate_message_by_uid(BSTR("page"));
- if (msgnum >= 0L) {
- Buf = NewStrBuf();
- read_message(Buf, HKEY("view_message_wikiedit"), msgnum, NULL, &Mime);
- StrBufAppendTemplate(Target, TP, Buf, 1);
- FreeStrBuf(&Buf);
+ /* Insert the existing content of the wiki page into the editor. But we only want
+ * to do this the first time -- if the user is uploading an attachment we don't want
+ * to do it again.
+ */
+ if (!havebstr("attach_button")) {
+ char *wikipage = strdup(bstr("page"));
+ putbstr("format", NewStrBufPlain(HKEY("plain")));
+ str_wiki_index(wikipage);
+ msgnum = locate_message_by_uid(wikipage);
+ free(wikipage);
+ if (msgnum >= 0L) {
+ Buf = NewStrBuf();
+ read_message(Buf, HKEY("view_message_wikiedit"), msgnum, NULL, &Mime);
+ StrBufAppendTemplate(Target, TP, Buf, 1);
+ FreeStrBuf(&Buf);
+ }
}
}
void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
{
- message_summary *Msg = (message_summary*) CTX;
+ message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
StrBufAppendTemplate(Target, TP, Msg->MsgBody->Data, 0);
}
-void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_MAIL_variformat(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
{
/* Messages in legacy Citadel variformat get handled thusly... */
- StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
- FmOut(Target, "JUSTIFY", Mime->Data);
+ wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
+ StrBuf *TTarget = NewStrBufPlain(NULL, StrLength(Mime->Data));
+ FmOut(TTarget, "JUSTIFY", Mime->Data);
FreeStrBuf(&Mime->Data);
- Mime->Data = Target;
+ Mime->Data = TTarget;
}
-void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_MAIL_text_plain(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
{
+ wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
const char *ptr, *pte;
const char *BufPtr = NULL;
StrBuf *Line;
StrBuf *Line1;
StrBuf *Line2;
- StrBuf *Target;
-
+ StrBuf *TTarget;
+ long Linecount;
+ long nEmptyLines;
int bn = 0;
int bq = 0;
int i;
@@ -887,7 +1078,7 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *F
else {
ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
if (ic == (iconv_t)(-1) ) {
- lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
+ syslog(LOG_WARNING, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
__FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
}
}
@@ -896,8 +1087,9 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *F
Line = NewStrBufPlain(NULL, SIZ);
Line1 = NewStrBufPlain(NULL, SIZ);
Line2 = NewStrBufPlain(NULL, SIZ);
- Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
-
+ TTarget = NewStrBufPlain(NULL, StrLength(Mime->Data));
+ Linecount = 0;
+ nEmptyLines = 0;
if (StrLength(Mime->Data) > 0)
do
{
@@ -920,33 +1112,40 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *F
if (i > 0) StrBufCutLeft(Line, i);
if (StrLength(Line) == 0) {
- StrBufAppendBufPlain(Target, HKEY("
\n"), 0);
+ if (Linecount == 0)
+ continue;
+ StrBufAppendBufPlain(TTarget, HKEY("
\n"), 0);
+
+ nEmptyLines ++;
continue;
}
-
+ nEmptyLines = 0;
for (i = bn; i < bq; i++)
- StrBufAppendBufPlain(Target, HKEY("
"), 0); + StrBufAppendBufPlain(TTarget, HKEY(""), 0); #ifdef HAVE_ICONV if (ConvertIt) { StrBufConvert(Line, Line1, &ic); } #endif - StrBufAppendBufPlain(Target, HKEY(""), 0); + StrBufAppendBufPlain(TTarget, HKEY(""), 0); UrlizeText(Line1, Line, Line2); - StrEscAppend(Target, Line1, NULL, 0, 0); - StrBufAppendBufPlain(Target, HKEY(""), 0); for (i = bq; i < bn; i++) - StrBufAppendBufPlain(Target, HKEY(""), 0); + StrBufAppendBufPlain(TTarget, HKEY("