* message index functions
*/
+void DestroyMimeParts(wc_mime_attachment *Mime)
+{
+ FreeStrBuf(&Mime->Name);
+ FreeStrBuf(&Mime->FileName);
+ FreeStrBuf(&Mime->PartNum);
+ FreeStrBuf(&Mime->Disposition);
+ FreeStrBuf(&Mime->ContentType);
+ FreeStrBuf(&Mime->Charset);
+ FreeStrBuf(&Mime->Data);
+}
-
+void DestroyMime(void *vMime)
+{
+ wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
+ DestroyMimeParts(Mime);
+ free(Mime);
+}
void DestroyMessageSummary(void *vMsg)
{
FreeStrBuf(&Msg->Rfca);
FreeStrBuf(&Msg->OtherNode);
+ FreeStrBuf(&Msg->reply_to);
+
+ DeleteHash(&Msg->Attachments); /**< list of Accachments */
+ DeleteHash(&Msg->Submessages);
+ DeleteHash(&Msg->AttachLinks);
+ DeleteHash(&Msg->AllAttach);
+
+ DestroyMimeParts(&Msg->MsgBody);
+
free(Msg);
}
/*----------------------------------------------------------------------------*/
-void examine_nhdr(message_summary *Msg, StrBuf *HdrLine)
+void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
Msg->nhdr = 0;
if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
Msg->nhdr = 1;
}
-void examine_type(message_summary *Msg, StrBuf *HdrLine)
+void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
Msg->format_type = StrToi(HdrLine);
}
-void examine_from(message_summary *Msg, StrBuf *HdrLine)
+void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
FreeStrBuf(&Msg->from);
Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset);
+ StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset, FoundCharset);
}
void tmplput_MAIL_SUMM_FROM(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
{
-void examine_subj(message_summary *Msg, StrBuf *HdrLine)
+void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
FreeStrBuf(&Msg->subj);
Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset);
+ StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset, FoundCharset);
lprintf(1,"%s", ChrPtr(Msg->subj));
}
void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
}
-void examine_msgn(message_summary *Msg, StrBuf *HdrLine)
+void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
FreeStrBuf(&Msg->reply_inreplyto);
Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset);
+ StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset, FoundCharset);
}
void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
{
}
-void examine_wefw(message_summary *Msg, StrBuf *HdrLine)
+void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
FreeStrBuf(&Msg->reply_references);
Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset);
+ StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset, FoundCharset);
}
void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
{
}
-void examine_cccc(message_summary *Msg, StrBuf *HdrLine)
+void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
FreeStrBuf(&Msg->cccc);
Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->cccc, HdrLine, WC->DefaultCharset);
+ StrBuf_RFC822_to_Utf8(Msg->cccc, HdrLine, WC->DefaultCharset, FoundCharset);
if (Msg->AllRcpt == NULL)
Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
if (StrLength(Msg->AllRcpt) > 0) {
-void examine_room(message_summary *Msg, StrBuf *HdrLine)
+void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
if ((StrLength(HdrLine) > 0) &&
(strcasecmp(ChrPtr(HdrLine), WC->wc_roomname))) {
}
-void examine_rfca(message_summary *Msg, StrBuf *HdrLine)
+void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
FreeStrBuf(&Msg->Rfca);
Msg->Rfca = NewStrBufDup(HdrLine);
}
-void examine_node(message_summary *Msg, StrBuf *HdrLine)
+void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
if ( (StrLength(HdrLine) > 0) &&
((WC->room_flags & QR_NETWORK)
}
-void examine_rcpt(message_summary *Msg, StrBuf *HdrLine)
+void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
FreeStrBuf(&Msg->to);
Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->to, HdrLine, WC->DefaultCharset);
+ StrBuf_RFC822_to_Utf8(Msg->to, HdrLine, WC->DefaultCharset, FoundCharset);
if (Msg->AllRcpt == NULL)
Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
if (StrLength(Msg->AllRcpt) > 0) {
-void examine_time(message_summary *Msg, StrBuf *HdrLine)
+void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
Msg->date = StrTol(HdrLine);
}
-void examine_mime_part(message_summary *Msg, StrBuf *HdrLine)
+void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
wc_mime_attachment *mime;
StrBuf *Buf;
mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
memset(mime, 0, sizeof(wc_mime_attachment));
- Buf=NewStrBuf();
+ Buf = NewStrBuf();
mime->Name = NewStrBuf();
StrBufExtract_token(mime->Name, HdrLine, 0, '|');
+
StrBufExtract_token(Buf, HdrLine, 1, '|');
- StrBuf_RFC822_to_Utf8(mime->FileName, Buf, WC->DefaultCharset);
+ mime->FileName = NewStrBuf();
+ StrBuf_RFC822_to_Utf8(mime->FileName, Buf, WC->DefaultCharset, FoundCharset);
+
mime->PartNum = NewStrBuf();
StrBufExtract_token(mime->PartNum, HdrLine, 2, '|');
+
mime->Disposition = NewStrBuf();
StrBufExtract_token(mime->Disposition, HdrLine, 3, '|');
+
mime->ContentType = NewStrBuf();
StrBufExtract_token(mime->ContentType, HdrLine, 4, '|');
+
mime->length = StrBufExtract_int(HdrLine, 5, '|');
StrBufTrim(mime->Name);
StrBufTrim(mime->FileName);
+
if ( (StrLength(mime->FileName) == 0) && (StrLength(mime->Name) > 0) ) {
StrBufAppendBuf(mime->FileName, mime->Name, 0);
}
+ if (Msg->AllAttach == NULL)
+ Msg->AllAttach = NewHash(1,NULL);
+ Put(Msg->AllAttach, SKEY(mime->PartNum), mime, DestroyMime);
+
if (!strcasecmp(ChrPtr(mime->ContentType), "message/rfc822")) {
if (Msg->Submessages == NULL)
Msg->Submessages = NewHash(1,NULL);
- Put(Msg->Submessages, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
+ Put(Msg->Submessages, SKEY(mime->PartNum), mime, reference_free_handler);
}
else if ((!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->PartNum, reference_free_handler);
+ Put(Msg->AttachLinks, SKEY(mime->PartNum), mime, reference_free_handler);
}
else if ((StrLength(mime->ContentType) > 0) &&
( (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))
if (Msg->AttachLinks == NULL)
Msg->AttachLinks = NewHash(1,NULL);
- Put(Msg->AttachLinks, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
+ Put(Msg->AttachLinks, SKEY(mime->PartNum), mime, reference_free_handler);
if (strcasecmp(ChrPtr(mime->ContentType), "application/octet-stream") == 0) {
FlushStrBuf(mime->ContentType);
StrBufAppendBufPlain(mime->ContentType,
Msg->cal_partnum_ref = mime;
}
/** end handler prep ***/
+
+ FreeStrBuf(&Buf);
+
}
void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
{
-void examine_hnod(message_summary *Msg, StrBuf *HdrLine)
+void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
FreeStrBuf(&Msg->hnod);
Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset);
+ StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset, FoundCharset);
}
void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
{
-void examine_text(message_summary *Msg, StrBuf *HdrLine)
+void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{////TODO: read messages here
Msg->MsgBody.Data = NewStrBuf();
}
-void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine)
+void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
Msg->MsgBody.PartNum = NewStrBufDup(HdrLine);
StrBufTrim(Msg->MsgBody.PartNum);/////TODO: striplt == trim?
}
-void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine)
+void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
////TODO: do we care?
}
-void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine)
+void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{
Msg->MsgBody.length = StrTol(HdrLine);
Msg->MsgBody.size_known = 1;
}
-void examine_content_type(message_summary *Msg, StrBuf *HdrLine)
+void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
{////TODO
int len, i;
Msg->MsgBody.ContentType = NewStrBufDup(HdrLine);
}
-void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData)
+void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
{
/* Messages in legacy Citadel variformat get handled thusly... */
StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
Mime->Data = Target;
}
-void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData)
+void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
{
+ StrBuf *cs = NULL;
const char *ptr, *pte;
const char *BufPtr = NULL;
StrBuf *Line = NewStrBuf();
#ifdef HAVE_ICONV
if (ConvertIt) {
- ctdl_iconv_open("UTF-8", ChrPtr(Mime->Charset), &ic);
- if (ic == (iconv_t)(-1) ) {
- lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
- __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
+ if (StrLength(Mime->Charset) != 0)
+ cs = Mime->Charset;
+ else if (StrLength(FoundCharset) > 0)
+ cs = FoundCharset;
+ else if (StrLength(WC->DefaultCharset) > 0)
+ cs = WC->DefaultCharset;
+ if (cs == 0) {
+ ConvertIt = 0;
+ }
+ 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",
+ __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
+ }
}
}
#endif
StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
for (i = bq; i < bn; i++)
StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
-
+
+ if (ConvertIt == 1) {
+ StrBufConvert(Line, Line1, &ic);
+ }
+
StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
UrlizeText(Line1, Line, Line2);
FreeStrBuf(&Line2);
}
-void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData)
+void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
{
StrBuf *Buf;
/* HTML is fun, but we've got to strip it first */
Mime->Data = Buf;
}
-void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData)
+void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
{
/* Unknown weirdness */
FlushStrBuf(Mime->Data);
+HashList *iterate_get_mime_All(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+ message_summary *Msg = (message_summary*) Context;
+ return Msg->AllAttach;
+}
+HashList *iterate_get_mime_Submessages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+ message_summary *Msg = (message_summary*) Context;
+ return Msg->Submessages;
+}
+HashList *iterate_get_mime_AttachLinks(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+ message_summary *Msg = (message_summary*) Context;
+ return Msg->AttachLinks;
+}
+HashList *iterate_get_mime_Attachments(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+ message_summary *Msg = (message_summary*) Context;
+ return Msg->AllAttach;
+}
+
+
+void tmplput_MIME_ATTACH(StrBuf *TemplBuffer, void *Context, WCTemplateToken *Token)
+{
+}
+
+
+
+
/*
* Look for URL's embedded in a buffer and make them linkable. We use a
struct wcsession *WCC = WC;
StrBuf *Buf;
StrBuf *Token;
- message_summary *Msg;
+ StrBuf *FoundCharset;
+ message_summary *Msg = NULL;
headereval *Hdr;
void *vHdr;
char buf[SIZ];
Token = NewStrBuf();
Msg = (message_summary *)malloc(sizeof(message_summary));
memset(Msg, 0, sizeof(message_summary));
-
+ FoundCharset = NewStrBuf();
while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
if ( (StrLength(Buf)==3) &&
!strcmp(ChrPtr(Buf), "000"))
FreeStrBuf(&Buf);
FreeStrBuf(&Token);
DestroyMessageSummary(Msg);
+ FreeStrBuf(&FoundCharset);
return;
}
else {
if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
(vHdr != NULL)) {
Hdr = (headereval*)vHdr;
- Hdr->evaluator(Msg, Buf);
+ Hdr->evaluator(Msg, Buf, FoundCharset);
if (Hdr->Type == 1) {
state++;
}
if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
(vHdr != NULL)) {
Hdr = (headereval*)vHdr;
- Hdr->evaluator(Msg, Buf);
+ Hdr->evaluator(Msg, Buf, FoundCharset);
}
break;
}
break;
}
}
-
-
- if (GetHash(MimeRenderHandler, SKEY(Msg->MsgBody.ContentType), &vHdr) &&
+
+ /* strip the bare contenttype, so we ommit charset etc. */
+ StrBufExtract_token(Buf, Msg->MsgBody.ContentType, 0, ';');
+ StrBufTrim(Buf);
+ if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
(vHdr != NULL)) {
RenderMimeFunc Render;
Render = (RenderMimeFunc)vHdr;
- Render(&Msg->MsgBody, NULL);
+ Render(&Msg->MsgBody, NULL, FoundCharset);
}
if (nhdr == 1) {
wprintf("****");
}
-
- if (StrLength(Msg->cccc)> 0) {
- StrBuf *tmp;
- tmp = Msg->cccc;
- Msg->cccc = Buf;
- StrBuf_RFC822_to_Utf8(Msg->cccc, tmp, WCC->DefaultCharset);
- Buf = tmp;
- }
- if (StrLength(Msg->subj)> 0) {
- StrBuf *tmp;
- tmp = Msg->subj;
- Msg->subj = Buf;
- StrBuf_RFC822_to_Utf8(Msg->subj, tmp, WCC->DefaultCharset);
- Buf = tmp;
- }
-
DoTemplate(HKEY("view_message"), NULL, Msg, CTX_MAILSUM);
if (num_attach_links > 0) {
free(attach_links);
}
-
+ DestroyMessageSummary(Msg);
+ FreeStrBuf(&FoundCharset);
+ FreeStrBuf(&Token);
+ FreeStrBuf(&Buf);
}
*/
int load_msg_ptrs(char *servcmd, int with_headers)
{
+ StrBuf* FoundCharset = NULL;
struct wcsession *WCC = WC;
message_summary *Msg;
StrBuf *Buf, *Buf2;
StrBufExtract_token(Buf2, Buf, 2, '|');
if (StrLength(Buf2) != 0) {
/** Handle senders with RFC2047 encoding */
- StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset);
+ StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
}
/** Nodename */
if (StrLength(Buf2) == 0)
StrBufAppendBufPlain(Msg->subj, _("(no subj)"), 0, -1);
else {
- StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset);
+ StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
if ((StrLength(Msg->subj) > 75) &&
(StrBuf_Utf8StrLen(Msg->subj) > 75)) {
StrBuf_Utf8StrCut(Msg->subj, 72);
char cmd[256] = "";
char buf[SIZ];
char old_msgs[SIZ];
- int a, b;
+ int a = 0;
+ int b = 0;
int nummsgs;
long startmsg;
int maxmsgs;
RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, CTX_MAILSUM);
+ RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
+ RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
+ RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
+
+
+ RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All,
+ tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
+ RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages,
+ tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
+ RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks,
+ tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
+ RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments,
+ tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat);
RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain);
RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html);
RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN);
-
- RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
- RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
- RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
-
RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
RegisterMsgHdr(HKEY("type"), examine_type, 0);
RegisterMsgHdr(HKEY("from"), examine_from, 0);