#include "dav.h"
#include "calendar.h"
-HashList *MsgHeaderHandler = NULL;
-HashList *MsgEvaluators = NULL;
HashList *MimeRenderHandler = NULL;
HashList *ReadLoopHandler = NULL;
int dbg_analyze_msg = 0;
void display_enter(void);
-typedef void (*MsgPartEvaluatorFunc)(message_summary *Sum, StrBuf *Buf);
-
-typedef struct _MsgPartEvaluatorStruct {
- MsgPartEvaluatorFunc f;
-} MsgPartEvaluatorStruct;
-
void fixview()
{
/* workaround for json listview; its not useable directly */
{
StrBuf *Buf;
StrBuf *HdrToken;
- headereval *Hdr;
- void *vHdr;
char buf[SIZ];
int Done = 0;
int state=0;
-
+ int rc;
+
Buf = NewStrBuf();
if (Msg->PartNum != NULL) {
serv_printf("MSG4 %ld|%s", Msg->msgnum, ChrPtr(Msg->PartNum));
StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
/* look up one of the examine_* functions to parse the content */
- if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
- (vHdr != NULL)) {
- Hdr = (headereval*)vHdr;
- Hdr->evaluator(Msg, Buf, FoundCharset);
- if (Hdr->Type == 1) {
- state++;
- }
- }/* TODO:
+ rc = EvaluateMsgHdr(SKEY(HdrToken), Msg, Buf, FoundCharset);
+ if (rc == 1) {
+ state++;
+ }
+ /* TODO:
else LogError(Target,
__FUNCTION__,
"don't know how to handle message header[%s]\n",
if (StrLength(HdrToken) > 0) {
StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
/* the examine*'s know how to do with mime headers too... */
- if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
- (vHdr != NULL)) {
- Hdr = (headereval*)vHdr;
- Hdr->evaluator(Msg, Buf, FoundCharset);
- }
+ EvaluateMsgHdr(SKEY(HdrToken), Msg, Buf, FoundCharset);
+
break;
}
}
* printable_view Nonzero to display a printable view
* section Optional for encapsulated message/rfc822 submessage
*/
-int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, const StrBuf *PartNum, const StrBuf **OutMime)
+int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, const StrBuf *PartNum, const StrBuf **OutMime, WCTemplputParams *TP)
{
StrBuf *Buf;
StrBuf *FoundCharset;
StrBufTrim(Buf);
StrBufLowerCase(Buf);
- StackContext(NULL, &SuperTP, Msg, CTX_MAILSUM, 0, NULL);
+ StackContext(TP, &SuperTP, Msg, CTX_MAILSUM, 0, NULL);
{
/* Locate a renderer capable of converting this MIME part into HTML */
if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
case ePOST:
Tmpl = sbstr("template");
if (StrLength(Tmpl) > 0)
- read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
+ read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime, NULL);
else
- read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
+ read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime, NULL);
http_transmit_thing(ChrPtr(Mime), 0);
break;
case eDELETE:
case ePOST:
Tmpl = sbstr("template");
if (StrLength(Tmpl) > 0)
- read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
+ read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime, NULL);
else
- read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
+ read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime, NULL);
http_transmit_thing(ChrPtr(Mime), 0);
break;
case eDELETE:
begin_burst();
- read_message(WC->WBuf, HKEY("view_message_print"), msgnum, NULL, &Mime);
+ read_message(WC->WBuf, HKEY("view_message_print"), msgnum, NULL, &Mime, NULL);
wDumpContent(0);
}
PACKAGE_STRING);
begin_burst();
- serv_printf("MSG2 %ld|3", msgnum);
+ serv_printf("MSG2 %ld|1", msgnum);
serv_getln(buf, sizeof buf);
if (buf[0] == '1') {
while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
}
-message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
-{
- void *vEval;
- MsgPartEvaluatorStruct *Eval;
- 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(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
- Eval = (MsgPartEvaluatorStruct*) vEval;
- StrBufCutLeft(Buf, nBuf + 1);
- Eval->f(Msg, Buf);
- }
- else syslog(LOG_INFO, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
- }
- return Msg;
-}
-
-
-
-
/*
* load message pointers from the server for a "read messages" operation
* \param MatchMSet MSet we want to flag
* \param FlagToSet Flag to set on each BasicMsgStruct->Flags if in MSet
*/
-void SetFlagsFromMSet(HashList *ScanMe, MSet *MatchMSet, int FlagToSet, int Reverse)
+long SetFlagsFromMSet(HashList *ScanMe, MSet *MatchMSet, int FlagToSet, int Reverse)
{
const char *HashKey;
long HKLen;
+ long count = 0;
HashPos *at;
void *vMsg;
message_summary *Msg;
Msg = (message_summary*) vMsg;
if (Reverse && IsInMSetList(MatchMSet, Msg->msgnum)) {
Msg->Flags = Msg->Flags | FlagToSet;
+ count++;
}
else if (!Reverse && !IsInMSetList(MatchMSet, Msg->msgnum)) {
Msg->Flags = Msg->Flags | FlagToSet;
+ count++;
}
}
DeleteHashPos(&at);
+ return count;
}
-void load_seen_flags(void)
+long load_seen_flags(void)
{
+ long count = 0;
StrBuf *OldMsg;
wcsession *WCC = WC;
MSet *MatchMSet;
}
else {
FreeStrBuf(&OldMsg);
- return;
+ return 0;
}
if (ParseMSet(&MatchMSet, OldMsg))
{
- SetFlagsFromMSet(WCC->summ, MatchMSet, MSGFLAG_READ, 0);
+ count = SetFlagsFromMSet(WCC->summ, MatchMSet, MSGFLAG_READ, 0);
}
DeleteMSet(&MatchMSet);
FreeStrBuf(&OldMsg);
+ return count;
}
extern readloop_struct rlid[];
long HKLen;
WCTemplputParams SubTP;
SharedMessageStatus Stat;
- void *ViewSpecific;
+ void *ViewSpecific = NULL;
if (havebstr("is_summary") && (1 == (ibstr("is_summary")))) {
WCC->CurRoom.view = VIEW_MAILBOX;
Stat.startmsg = 0;
}
- if (Stat.load_seen) load_seen_flags();
+ if (Stat.load_seen) Stat.numNewmsgs = load_seen_flags();
/*
* Print any inforation above the message list...
Foo = NewStrBuf ();
StrBufPrintf(Foo, "%ld", Stat.nummsgs);
- PutBstr(HKEY("__READLOOP:TOTALMSGS"), NewStrBufDup(Foo));
+ PutBstr(HKEY("__READLOOP:TOTALMSGS"), NewStrBufDup(Foo)); /* keep Foo! */
+
+ StrBufPrintf(Foo, "%ld", Stat.numNewmsgs);
+ PutBstr(HKEY("__READLOOP:NEWMSGS"), NewStrBufDup(Foo)); /* keep Foo! */
+
StrBufPrintf(Foo, "%ld", Stat.startmsg);
- PutBstr(HKEY("__READLOOP:STARTMSG"), Foo);
+ PutBstr(HKEY("__READLOOP:STARTMSG"), Foo); /* store Foo elsewhere, descope it here. */
}
/*
long newnlen;
void *v;
wc_mime_attachment *att;
+ const StrBuf *Tmpl = sbstr("template");
+ const StrBuf *MimeType = NULL;
+ const StrBuf *UID;
+ begin_burst();
syslog(LOG_DEBUG, "upload_attachment()\n");
- wc_printf("upload_attachment()<br>\n");
+ if (!Tmpl) wc_printf("upload_attachment()<br>\n");
if (WCC->upload_length <= 0) {
syslog(LOG_DEBUG, "ERROR no attachment was uploaded\n");
- wc_printf("ERROR no attachment was uploaded<br>\n");
+ if (Tmpl)
+ {
+ putlbstr("UPLOAD_ERROR", 1);
+ MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
+ }
+ else wc_printf("ERROR no attachment was uploaded<br>\n");
+ http_transmit_thing(ChrPtr(MimeType), 0);
+
return;
}
syslog(LOG_DEBUG, "Client is uploading %d bytes\n", WCC->upload_length);
- wc_printf("Client is uploading %d bytes<br>\n", WCC->upload_length);
- att = malloc(sizeof(wc_mime_attachment));
+ if (Tmpl) putlbstr("UPLOAD_LENGTH", WCC->upload_length);
+ else wc_printf("Client is uploading %d bytes<br>\n", WCC->upload_length);
+
+ att = (wc_mime_attachment*)malloc(sizeof(wc_mime_attachment));
memset(att, 0, sizeof(wc_mime_attachment ));
att->length = WCC->upload_length;
att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1);
att->FileName = NewStrBufDup(WCC->upload_filename);
-
+ UID = sbstr("qquuid");
+ if (UID)
+ att->PartNum = NewStrBufDup(UID);
+
if (WCC->attachments == NULL) {
WCC->attachments = NewHash(1, Flathash);
}
att->Data = WCC->upload;
WCC->upload = NULL;
WCC->upload_length = 0;
+
+ if (Tmpl) MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
+ http_transmit_thing(ChrPtr(MimeType), 0);
}
StrBuf *WhichAttachment;
HashPos *at;
long len;
+ int found=0;
const char *key;
WhichAttachment = NewStrBufDup(sbstr("which_attachment"));
+ if (ChrPtr(WhichAttachment)[0] == '/')
+ StrBufCutLeft(WhichAttachment, 1);
StrBufUnescape(WhichAttachment, 0);
at = GetNewHashPos(WCC->attachments, 0);
do {
+ vAtt = NULL;
GetHashPos(WCC->attachments, at, &len, &key, &vAtt);
-
+
att = (wc_mime_attachment*) vAtt;
- if ((att != NULL) &&
- (strcmp(ChrPtr(WhichAttachment),
- ChrPtr(att->FileName) ) == 0))
+ if ((att != NULL) &&
+ (
+ !strcmp(ChrPtr(WhichAttachment), ChrPtr(att->FileName)) ||
+ ((att->PartNum != NULL) &&
+ !strcmp(ChrPtr(WhichAttachment), ChrPtr(att->PartNum)))
+ ))
{
DeleteEntryFromHash(WCC->attachments, at);
+ found=1;
break;
}
}
while (NextHashPos(WCC->attachments, at));
- FreeStrBuf(&WhichAttachment);
- wc_printf("remove_attachment() completed\n");
-}
-
-long FourHash(const char *key, long length)
-{
- int i;
- long ret = 0;
- const unsigned char *ptr = (const unsigned char*)key;
-
- for (i = 0; i < 4; i++, ptr ++)
- ret = (ret << 8) |
- ( ((*ptr >= 'a') &&
- (*ptr <= 'z'))?
- *ptr - 'a' + 'A':
- *ptr);
-
- return ret;
+ FreeStrBuf(&WhichAttachment);
+ wc_printf("remove_attachment(%d) completed\n", found);
}
-long l_subj;
-long l_wefw;
-long l_msgn;
-long l_from;
-long l_rcpt;
-long l_cccc;
-long l_replyto;
-long l_node;
-long l_rfca;
-long l_nvto;
const char *ReplyToModeStrings [3] = {
"reply",
int i = 0;
long replying_to;
+ int prefer_md;
+
+ get_pref_yesno("markdown", &prefer_md, 0);
+
if (havebstr("force_room")) {
gotoroom(sbstr("force_room"));
}
((len != 3) ||
strcmp(ChrPtr(Line), "000")))
{
- long which = 0;
+ eMessageField which;
if ((StrLength(Line) > 4) &&
- (ChrPtr(Line)[4] == '='))
- which = FourHash(ChrPtr(Line), 4);
-
- if (which == l_subj)
- {
- StrBuf *subj = NewStrBuf();
- StrBuf *FlatSubject;
-
- if (ReplyMode == eForward) {
- if (strncasecmp(ChrPtr(Line) + 5, "Fw:", 3)) {
- StrBufAppendBufPlain(subj, HKEY("Fw: "), 0);
+ (ChrPtr(Line)[4] == '=') &&
+ GetFieldFromMnemonic(&which, ChrPtr(Line)))
+ switch (which) {
+ case eMsgSubject: {
+ StrBuf *subj = NewStrBuf();
+ StrBuf *FlatSubject;
+
+ if (ReplyMode == eForward) {
+ if (strncasecmp(ChrPtr(Line) + 5, "Fw:", 3)) {
+ StrBufAppendBufPlain(subj, HKEY("Fw: "), 0);
+ }
}
- }
- else {
- if (strncasecmp(ChrPtr(Line) + 5, "Re:", 3)) {
- StrBufAppendBufPlain(subj, HKEY("Re: "), 0);
+ else {
+ if (strncasecmp(ChrPtr(Line) + 5, "Re:", 3)) {
+ StrBufAppendBufPlain(subj, HKEY("Re: "), 0);
+ }
}
- }
- StrBufAppendBufPlain(subj,
- ChrPtr(Line) + 5,
- StrLength(Line) - 5, 0);
- FlatSubject = NewStrBufPlain(NULL, StrLength(subj));
- StrBuf_RFC822_to_Utf8(FlatSubject, subj, NULL, NULL);
+ StrBufAppendBufPlain(subj,
+ ChrPtr(Line) + 5,
+ StrLength(Line) - 5, 0);
+ FlatSubject = NewStrBufPlain(NULL, StrLength(subj));
+ StrBuf_RFC822_to_Utf8(FlatSubject, subj, NULL, NULL);
- PutBstr(HKEY("subject"), FlatSubject);
- }
+ PutBstr(HKEY("subject"), FlatSubject);
+ }
+ break;
- else if (which == l_wefw)
- {
- int rrtok;
- int rrlen;
+ case eWeferences:
+ {
+ int rrtok;
+ int rrlen;
- wefw = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
+ wefw = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
- /* Trim down excessively long lists of thread references. We eliminate the
- * second one in the list so that the thread root remains intact.
- */
- rrtok = num_tokens(ChrPtr(wefw), '|');
- rrlen = StrLength(wefw);
- if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
- StrBufRemove_token(wefw, 1, '|');
+ /* Trim down excessively long lists of thread references. We eliminate the
+ * second one in the list so that the thread root remains intact.
+ */
+ rrtok = num_tokens(ChrPtr(wefw), '|');
+ rrlen = StrLength(wefw);
+ if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
+ StrBufRemove_token(wefw, 1, '|');
+ }
+ break;
}
- }
- else if (which == l_msgn) {
- msgn = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
- }
-
- else if (which == l_from) {
- StrBuf *FlatFrom;
- from = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
- FlatFrom = NewStrBufPlain(NULL, StrLength(from));
- StrBuf_RFC822_to_Utf8(FlatFrom, from, NULL, NULL);
- FreeStrBuf(&from);
- from = FlatFrom;
- for (i=0; i<StrLength(from); ++i) {
- if (ChrPtr(from)[i] == ',')
- StrBufPeek(from, NULL, i, ' ');
+ case emessageId:
+ msgn = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
+ break;
+
+ case eAuthor: {
+ StrBuf *FlatFrom;
+ from = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
+ FlatFrom = NewStrBufPlain(NULL, StrLength(from));
+ StrBuf_RFC822_to_Utf8(FlatFrom, from, NULL, NULL);
+ FreeStrBuf(&from);
+ from = FlatFrom;
+ for (i=0; i<StrLength(from); ++i) {
+ if (ChrPtr(from)[i] == ',')
+ StrBufPeek(from, NULL, i, ' ');
+ }
+ break;
}
- }
- else if (which == l_rcpt) {
- rcpt = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
- }
+ case eRecipient:
+ rcpt = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
+ break;
+
- else if (which == l_cccc) {
- cccc = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
- }
+ case eCarbonCopY:
+ cccc = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
+ break;
+
- else if (which == l_node) {
- node = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
- }
- else if (which == l_replyto) {
- replyto = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
- }
- else if (which == l_rfca) {
- StrBuf *FlatRFCA;
- rfca = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
- FlatRFCA = NewStrBufPlain(NULL, StrLength(rfca));
- StrBuf_RFC822_to_Utf8(FlatRFCA, rfca, NULL, NULL);
- FreeStrBuf(&rfca);
- rfca = FlatRFCA;
- }
- else if (which == l_nvto) {
- nvto = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
- putbstr("nvto", nvto);
- }
+ case eNodeName:
+ node = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
+ break;
+ case eReplyTo:
+ replyto = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
+ break;
+ case erFc822Addr: {
+ StrBuf *FlatRFCA;
+ rfca = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
+ FlatRFCA = NewStrBufPlain(NULL, StrLength(rfca));
+ StrBuf_RFC822_to_Utf8(FlatRFCA, rfca, NULL, NULL);
+ FreeStrBuf(&rfca);
+ rfca = FlatRFCA;
+ break;
+ }
+ case eenVelopeTo:
+ nvto = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
+ putbstr("nvto", nvto);
+ break;
+ case eXclusivID:
+ case eHumanNode:
+ case eJournal:
+ case eListID:
+ case eMesageText:
+ case eOriginalRoom:
+ case eMessagePath:
+ case eSpecialField:
+ case eTimestamp:
+ break;
+
+ }
}
begin_burst();
output_headers(1, 0, 0, 0, 1, 0);
- if (WCC->CurRoom.defview == VIEW_WIKIMD)
+ if ((WCC->CurRoom.defview == VIEW_WIKIMD) || prefer_md)
DoTemplate(HKEY("edit_markdown_epic"), NULL, &NoCtx);
else
DoTemplate(HKEY("edit_message"), NULL, &NoCtx);
PRF_YESNO,
NULL);
RegisterPreference("signature", _("Use this signature:"), PRF_QP_STRING, NULL);
- RegisterPreference("default_header_charset",
+ RegisterPreference("default_header_charset",
_("Default character set for email headers:"),
PRF_STRING,
NULL);
PRF_STRING,
NULL);
RegisterPreference("mailbox",_("Mailbox view mode"), PRF_STRING, NULL);
+ RegisterPreference("markdown",_("Prefer markdown editing"), PRF_YESNO, NULL);
+
WebcitAddUrlHandler(HKEY("readnew"), "", 0, h_readnew, ANONYMOUS|NEED_URL);
WebcitAddUrlHandler(HKEY("readold"), "", 0, h_readold, ANONYMOUS|NEED_URL);
/* json */
WebcitAddUrlHandler(HKEY("roommsgs"), "", 0, jsonMessageList,0);
-
- l_subj = FourHash("subj", 4);
- l_wefw = FourHash("wefw", 4);
- l_msgn = FourHash("msgn", 4);
- l_from = FourHash("from", 4);
- l_rcpt = FourHash("rcpt", 4);
- l_cccc = FourHash("cccc", 4);
- l_replyto = FourHash("rep2", 4);
- l_node = FourHash("node", 4);
- l_rfca = FourHash("rfca", 4);
- l_nvto = FourHash("nvto", 4);
-
- return ;
}
void