Fix lots of warnings all over the place, make inbound buffers of FMOUT const.
[citadel.git] / webcit / messages.c
index 6d83128d2107041ac388cf19d9e3c0ec4e2a9b48..aede383fcb2ab5ef78d08f50bb1b0488d62e6104 100644 (file)
@@ -21,6 +21,7 @@
 #include "webcit.h"
 #include "webserver.h"
 #include "groupdav.h"
+#include "calendar.h"
 
 HashList *MsgHeaderHandler = NULL;
 HashList *MsgEvaluators = NULL;
@@ -246,7 +247,7 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, co
 }
 
 
-void
+long
 HttpStatus(long CitadelStatus)
 {
        long httpstatus = 502;
@@ -311,7 +312,7 @@ HttpStatus(long CitadelStatus)
                break;
        }
 
-
+       return httpstatus;
 }
 
 /*
@@ -733,7 +734,7 @@ void readloop(long oper, eCustomRoomRenderer ForceRenderer)
                GetHash(ReadLoopHandler, IKEY(WCC->CurRoom.view), &vViewMsg);
        }
        if (vViewMsg == NULL) {
-               return;                 // TODO: print message
+               return;                 /* TODO: print message */
        }
 
        ViewMsg = (RoomRenderer*) vViewMsg;
@@ -1282,15 +1283,14 @@ void remove_attachment(void) {
 void display_enter(void)
 {
        char buf[SIZ];
-       long now;
        const StrBuf *display_name = NULL;
        int recipient_required = 0;
        int subject_required = 0;
        int recipient_bad = 0;
        int is_anonymous = 0;
        wcsession *WCC = WC;
-
-       now = time(NULL);
+       int i = 0;
+       long replying_to;
 
        if (havebstr("force_room")) {
                gotoroom(sbstr("force_room"));
@@ -1347,6 +1347,139 @@ void display_enter(void)
                return;
        }
 
+
+       /*
+        * 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) {
+               char wefw[1024] = "";
+               char msgn[256] = "";
+               char from[256] = "";
+               char node[256] = "";
+               char rfca[256] = "";
+               char rcpt[SIZ] = "";
+               char cccc[SIZ] = "";
+               serv_printf("MSG0 %ld|1", replying_to); 
+               serv_getln(buf, sizeof buf);
+               if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+
+                       if ( (!strncasecmp(buf, "subj=", 5)) && (strlen(buf) > 5) ) {
+                               StrBuf *subj = NewStrBuf();
+                               if (!strcasecmp(bstr("replying_mode"), "forward")) {
+                                       if (strncasecmp(&buf[5], "Fw:", 3)) {
+                                               StrBufAppendBufPlain(subj, HKEY("Fw: "), 0);
+                                       }
+                               }
+                               else {
+                                       if (strncasecmp(&buf[5], "Re:", 3)) {
+                                               StrBufAppendBufPlain(subj, HKEY("Re: "), 0);
+                                       }
+                               }
+                               StrBufAppendBufPlain(subj, &buf[5], -1, 0);
+                               PutBstr(HKEY("subject"), subj);
+                       }
+
+                       else if (!strncasecmp(buf, "wefw=", 5)) {
+                               int rrtok;
+                               int rrlen;
+                               safestrncpy(wefw, &buf[5], sizeof wefw);
+
+                               /* 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(wefw, '|');
+                               rrlen = strlen(wefw);
+                               if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
+                                       remove_token(wefw, 1, '|');
+                               }
+                       }
+
+                       else if (!strncasecmp(buf, "msgn=", 5)) {
+                               safestrncpy(msgn, &buf[5], sizeof msgn);
+                       }
+
+                       else if (!strncasecmp(buf, "from=", 5)) {
+                               safestrncpy(from, &buf[5], sizeof from);
+                               for (i=0; i<strlen(from); ++i) {
+                                       if (from[i] == ',') from[i] = ' ';
+                               }
+                       }
+
+                       else if (!strncasecmp(buf, "rcpt=", 5)) {
+                               safestrncpy(rcpt, &buf[5], sizeof rcpt);
+                       }
+
+                       else if (!strncasecmp(buf, "cccc=", 5)) {
+                               safestrncpy(cccc, &buf[5], sizeof cccc);
+                       }
+
+                       else if (!strncasecmp(buf, "node=", 5)) {
+                               safestrncpy(node, &buf[5], sizeof node);
+                       }
+
+                       else if (!strncasecmp(buf, "rfca=", 5)) {
+                               safestrncpy(rfca, &buf[5], sizeof rfca);
+                       }
+
+               }
+
+               if (strlen(wefw) + strlen(msgn) > 0) {
+                       StrBuf *refs = NewStrBuf();
+                       if (!IsEmptyStr(wefw)) {
+                               StrBufAppendBufPlain(refs, wefw, -1, 0);
+                       }
+                       if ( (!IsEmptyStr(wefw)) && (!IsEmptyStr(msgn)) ) {
+                               StrBufAppendBufPlain(refs, HKEY("|"), 0);
+                       }
+                       if (!IsEmptyStr(msgn)) {
+                               StrBufAppendBufPlain(refs, msgn, -1, 0);
+                       }
+                       PutBstr(HKEY("references"), refs);
+               }
+
+               /*
+                * If this is a Reply or a ReplyAll, copy the sender's email into the To: field
+                */
+               if (    (!strcasecmp(bstr("replying_mode"), "reply"))
+                       || (!strcasecmp(bstr("replying_mode"), "replyall"))
+               ) {
+                       StrBuf *to_rcpt = NewStrBuf();
+                       if (!IsEmptyStr(rfca)) {
+                               StrBufAppendPrintf(to_rcpt, "%s <%s>", from, rfca);
+                       }
+                       else {
+                               StrBufAppendPrintf(to_rcpt, "%s", from);
+                               if (    (!IsEmptyStr(node))
+                                       && (strcasecmp(node, ChrPtr(WC->serv_info->serv_nodename)))
+                               ) {
+                                       StrBufAppendPrintf(to_rcpt, " @ %s", node);
+                               }
+                       }
+                       PutBstr(HKEY("recp"), to_rcpt);
+               }
+
+               /*
+                * Only if this is a ReplyAll, copy all recipients into the Cc: field
+                */
+               if (    (!strcasecmp(bstr("replying_mode"), "replyall"))
+               ) {
+                       StrBuf *cc_rcpt = NewStrBuf();
+                       if (!IsEmptyStr(rcpt)) {
+                               StrBufAppendPrintf(cc_rcpt, "%s", rcpt);
+                       }
+                       if ( (!IsEmptyStr(rcpt)) && (!IsEmptyStr(cccc)) ) {
+                               StrBufAppendPrintf(cc_rcpt, ", ");
+                       }
+                       if (!IsEmptyStr(cccc)) {
+                               StrBufAppendPrintf(cc_rcpt, "%s", cccc);
+                       }
+                       PutBstr(HKEY("cc"), cc_rcpt);
+               }
+
+       }
+
        /*
         * Otherwise proceed normally.
         * Do a custom room banner with no navbar...
@@ -1389,7 +1522,7 @@ void display_enter(void)
                        if (havebstr("recp") && 
                            havebstr("cc"  ) && 
                            havebstr("bcc" )) {
-                               recipient_bad = 1;
+                               recipient_bad = 1; /* TODO: and now????? */
                        }
                }
                else if (buf[0] != '2') {       /* Any other error means that we cannot continue */
@@ -1461,13 +1594,9 @@ void move_msg(void)
  */
 void confirm_move_msg(void)
 {
-       long msgid;
        char buf[SIZ];
        char targ[SIZ];
 
-       msgid = lbstr("msgid");
-
-
        output_headers(1, 1, 2, 0, 0, 0);
        wc_printf("<div id=\"banner\">\n");
        wc_printf("<h1>");