+
+ ReplyingModeStr = bstr("replying_mode");
+ if (ReplyingModeStr != NULL) for (i = 0; i < 3; i++) {
+ if (strcmp(ReplyingModeStr, ReplyToModeStrings[i]) == 0) {
+ ReplyMode = (eReplyToNodes) i;
+ break;
+ }
+ }
+
+
+ /*
+ * If the "replying_to" variable is set, it refers to a message
+ * number from which we must extract some header fields...
+ */
+ replying_to = lbstr("replying_to");
+ if (replying_to > 0) {
+ long len;
+ StrBuf *wefw = NULL;
+ StrBuf *msgn = NULL;
+ StrBuf *from = NULL;
+ StrBuf *node = NULL;
+ StrBuf *rfca = NULL;
+ StrBuf *rcpt = NULL;
+ StrBuf *cccc = NULL;
+ StrBuf *replyto = NULL;
+ StrBuf *nvto = NULL;
+ serv_printf("MSG0 %ld|1", replying_to);
+
+ StrBuf_ServGetln(Line);
+ if (GetServerStatusMsg(Line, NULL, 0, 0) == 1)
+ while (len = StrBuf_ServGetln(Line),
+ (len >= 0) &&
+ ((len != 3) ||
+ strcmp(ChrPtr(Line), "000")))
+ {
+ eMessageField which;
+ if ((StrLength(Line) > 4) &&
+ (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);
+ }
+ }
+ 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);
+ }
+ break;
+
+ case eWeferences:
+ {
+ int rrtok;
+ int rrlen;
+
+ 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, '|');
+ }
+ break;
+ }
+
+ 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;
+ }
+
+ case eRecipient:
+ rcpt = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
+ break;
+
+
+ case eCarbonCopY:
+ cccc = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5);
+ break;
+
+
+ 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;
+
+ }
+ }
+
+
+ if (StrLength(wefw) + StrLength(msgn) > 0) {
+ StrBuf *refs = NewStrBuf();
+ if (StrLength(wefw) > 0) {
+ StrBufAppendBuf(refs, wefw, 0);
+ }
+ if ( (StrLength(wefw) > 0) &&
+ (StrLength(msgn) > 0) )
+ {
+ StrBufAppendBufPlain(refs, HKEY("|"), 0);
+ }
+ if (StrLength(msgn) > 0) {
+ StrBufAppendBuf(refs, msgn, 0);
+ }
+ PutBstr(HKEY("references"), refs);
+ }
+
+ /*
+ * If this is a Reply or a ReplyAll, copy the sender's email into the To: field
+ */
+ if ((ReplyMode == eReply) || (ReplyMode == eReplyAll))
+ {
+ StrBuf *to_rcpt;
+ if ((StrLength(replyto) > 0) && (ReplyMode == eReplyAll)) {
+ to_rcpt = NewStrBuf();
+ StrBufAppendBuf(to_rcpt, replyto, 0);
+ }
+ else if (StrLength(rfca) > 0) {
+ to_rcpt = NewStrBuf();
+ StrBufAppendBuf(to_rcpt, from, 0);
+ StrBufAppendBufPlain(to_rcpt, HKEY(" <"), 0);
+ StrBufAppendBuf(to_rcpt, rfca, 0);
+ StrBufAppendBufPlain(to_rcpt, HKEY(">"), 0);
+ }
+ else {
+ to_rcpt = from;
+ from = NULL;
+ if ( (StrLength(node) > 0)
+ && (strcasecmp(ChrPtr(node), ChrPtr(WCC->serv_info->serv_nodename)))
+ ) {
+ StrBufAppendBufPlain(to_rcpt, HKEY(" @ "), 0);
+ StrBufAppendBuf(to_rcpt, node, 0);
+ }
+ }
+ PutBstr(HKEY("recp"), to_rcpt);
+ }
+
+ /*
+ * Only if this is a ReplyAll, copy all recipients into the Cc: field
+ */
+ if (ReplyMode == eReplyAll)
+ {
+ StrBuf *cc_rcpt = rcpt;
+ rcpt = NULL;
+ if ((StrLength(cccc) > 0) && (StrLength(replyto) == 0))
+ {
+ if (cc_rcpt != NULL) {
+ StrBufAppendPrintf(cc_rcpt, ", ");
+ StrBufAppendBuf(cc_rcpt, cccc, 0);
+ } else {
+ cc_rcpt = cccc;
+ cccc = NULL;
+ }
+ }
+ if (cc_rcpt != NULL)
+ PutBstr(HKEY("cc"), cc_rcpt);
+ }
+ FreeStrBuf(&wefw);
+ FreeStrBuf(&msgn);
+ FreeStrBuf(&from);
+ FreeStrBuf(&node);
+ FreeStrBuf(&rfca);
+ FreeStrBuf(&rcpt);
+ FreeStrBuf(&cccc);
+ }
+ FreeStrBuf(&Line);