X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=webcit%2Fmessages.c;fp=webcit%2Fmessages.c;h=a5447a378952ca84674ecaaf01f368fc277653e6;hp=3c3c92f6dd2f3b1aced34d0a484c81cfeee63278;hb=7c339ad1ffcbbd5b5d0d3610b734405e571d286e;hpb=b95a2e76213ef87c1bf98f8c64e8f13db5bef192 diff --git a/webcit/messages.c b/webcit/messages.c index 3c3c92f6d..a5447a378 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -787,13 +787,13 @@ void readloop(long oper, eCustomRoomRenderer ForceRenderer) Foo = NewStrBuf (); StrBufPrintf(Foo, "%ld", Stat.nummsgs); - PutBstr(HKEY("__READLOOP:TOTALMSGS"), NewStrBufDup(Foo)); // keep Foo! + PutBstr(HKEY("__READLOOP:TOTALMSGS"), NewStrBufDup(Foo)); /* keep Foo! */ StrBufPrintf(Foo, "%ld", Stat.numNewmsgs); - PutBstr(HKEY("__READLOOP:NEWMSGS"), NewStrBufDup(Foo)); // keep Foo! + PutBstr(HKEY("__READLOOP:NEWMSGS"), NewStrBufDup(Foo)); /* keep Foo! */ StrBufPrintf(Foo, "%ld", Stat.startmsg); - PutBstr(HKEY("__READLOOP:STARTMSG"), Foo); // store Foo elsewhere, descope it here. + PutBstr(HKEY("__READLOOP:STARTMSG"), Foo); /* store Foo elsewhere, descope it here. */ } /* @@ -1310,32 +1310,76 @@ void remove_attachment(void) { } -long FourHash(const char *key, long length) +/* Maps to msgkeys[] in msgbase.c: */ + +typedef enum _eMessageField { + eAuthor, + eXclusivID, + erFc822Addr, + eHumanNode, + emessageId, + eJournal, + eReplyTo, + eListID, + eMesageText, + eNodeName, + eOriginalRoom, + eMessagePath, + eRecipient, + eSpecialField, + eTimestamp, + eMsgSubject, + eenVelopeTo, + eWeferences, + eCarbonCopY +}eMessageField; + +const char* fieldMnemonics[] = { + "from", /* A -> eAuthor */ + "exti", /* E -> eXclusivID */ + "rfca", /* F -> erFc822Addr */ + "hnod", /* H -> eHumanNode */ + "msgn", /* I -> emessageId */ + "jrnl", /* J -> eJournal */ + "rep2", /* K -> eReplyTo */ + "list", /* L -> eListID */ + "text", /* M -> eMesageText */ + "node", /* N -> eNodeName */ + "room", /* O -> eOriginalRoom */ + "path", /* P -> eMessagePath */ + "rcpt", /* R -> eRecipient */ + "spec", /* S -> eSpecialField */ + "time", /* T -> eTimestamp */ + "subj", /* U -> eMsgSubject */ + "nvto", /* V -> eenVelopeTo */ + "wefw", /* W -> eWeferences */ + "cccc" /* Y -> eCarbonCopY */ +}; + +HashList *msgKeyLookup = NULL; + +int GetFieldFromMnemonic(eMessageField *f, const char* c) { - 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; + void *v = NULL; + if (GetHash(msgKeyLookup, c, 4, &v)) { + *f = (eMessageField) v; + return 1; + } + return 0; } -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; +void FillMsgKeyLookupTable(void) +{ + long i; + + msgKeyLookup = NewHash (1, FourHash); + + for (i=0; i < 20; i++) { + if (fieldMnemonics[i] != NULL) { + Put(msgKeyLookup, fieldMnemonics[i], 4, (void*)i, reference_free_handler); + } + } +} const char *ReplyToModeStrings [3] = { "reply", @@ -1469,95 +1513,112 @@ void display_enter(void) ((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