X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fmessages.c;h=d1b0f20817cc3b2bbe6f5584573b2d5ae6380516;hb=HEAD;hp=6c478dcf3c2144e283930b985f4b5dae73b43b18;hpb=c6aec42f213ec284e34648f3d69bcf927dccddb1;p=citadel.git diff --git a/webcit/messages.c b/webcit/messages.c index 6c478dcf3..ec6306ecc 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -17,7 +17,7 @@ // GNU General Public License for more details. #include "webcit.h" -#include "webserver.h" + #include "dav.h" #include "calendar.h" @@ -39,12 +39,12 @@ void fixview() { } -int load_message(message_summary * Msg, StrBuf * FoundCharset, StrBuf ** Error) { +int load_message(message_summary *Msg, StrBuf *FoundCharset, StrBuf **Error) { StrBuf *Buf; StrBuf *HdrToken; char buf[SIZ]; int Done = 0; - int state = 0; + int state=0; int rc; Buf = NewStrBuf(); @@ -67,8 +67,10 @@ int load_message(message_summary * Msg, StrBuf * FoundCharset, StrBuf ** Error) /* begin everythingamundo table */ HdrToken = NewStrBuf(); - while (!Done && StrBuf_ServGetln(Buf) >= 0) { - if ((StrLength(Buf) == 3) && !strcmp(ChrPtr(Buf), "000")) { + while (!Done && StrBuf_ServGetln(Buf)>=0) { + if ( (StrLength(Buf)==3) && + !strcmp(ChrPtr(Buf), "000")) + { Done = 1; if (state < 2) { if (Msg->MsgBody->Data == NULL) @@ -82,52 +84,53 @@ int load_message(message_summary * Msg, StrBuf * FoundCharset, StrBuf ** Error) break; } switch (state) { - case 0: /* Citadel Message Headers */ + case 0:/* Citadel Message Headers */ if (StrLength(Buf) == 0) { - state++; + state ++; break; } StrBufExtract_token(HdrToken, Buf, 0, '='); StrBufCutLeft(Buf, StrLength(HdrToken) + 1); - + /* look up one of the examine_* functions to parse the content */ - rc = EvaluateMsgHdr(SKEY(HdrToken), Msg, Buf, FoundCharset); + 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", - ChrPtr(HdrToken)); + else LogError(Target, + __FUNCTION__, + "don't know how to handle message header[%s]\n", + ChrPtr(HdrToken)); */ break; - case 1: /* Message Mime Header */ + case 1:/* Message Mime Header */ if (StrLength(Buf) == 0) { state++; if (Msg->MsgBody->ContentType == NULL) - /* end of header or no header? */ + /* end of header or no header? */ Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/plain")); - /* usual end of mime header */ + /* usual end of mime header */ } - else { + else + { StrBufExtract_token(HdrToken, Buf, 0, ':'); if (StrLength(HdrToken) > 0) { StrBufCutLeft(Buf, StrLength(HdrToken) + 1); /* the examine*'s know how to do with mime headers too... */ EvaluateMsgHdr(SKEY(HdrToken), Msg, Buf, FoundCharset); - + break; } } - case 2: /* Message Body */ - + case 2: /* Message Body */ + if (Msg->MsgBody->size_known > 0) { StrBuf_ServGetBLOBBuffered(Msg->MsgBody->Data, Msg->MsgBody->length); - state++; + state ++; /*/ todo: check next line, if not 000, append following lines */ } - else if (1) { + else if (1){ if (StrLength(Msg->MsgBody->Data) > 0) StrBufAppendBufPlain(Msg->MsgBody->Data, "\n", 1, 0); StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0); @@ -140,10 +143,10 @@ int load_message(message_summary * Msg, StrBuf * FoundCharset, StrBuf ** Error) } if (Msg->AllAttach == NULL) - Msg->AllAttach = NewHash(1, NULL); + Msg->AllAttach = NewHash(1,NULL); /* now we put the body mimepart we read above into the mimelist */ Put(Msg->AllAttach, SKEY(Msg->MsgBody->PartNum), Msg->MsgBody, DestroyMime); - + FreeStrBuf(&Buf); FreeStrBuf(&HdrToken); return 1; @@ -157,11 +160,10 @@ int load_message(message_summary * Msg, StrBuf * FoundCharset, StrBuf ** Error) * 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, - WCTemplputParams * TP) { +int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, const StrBuf *PartNum, const StrBuf **OutMime, WCTemplputParams *TP) { StrBuf *Buf; StrBuf *FoundCharset; - HashPos *it; + HashPos *it; void *vMime; message_summary *Msg = NULL; void *vHdr; @@ -176,14 +178,14 @@ int read_message(StrBuf * Target, const char *tmpl, long tmpllen, long msgnum, c Buf = NewStrBuf(); FoundCharset = NewStrBuf(); - Msg = (message_summary *) malloc(sizeof(message_summary)); + Msg = (message_summary *)malloc(sizeof(message_summary)); if (!Msg) { syslog(LOG_DEBUG, "malloc() error"); } memset(Msg, 0, sizeof(message_summary)); Msg->msgnum = msgnum; Msg->PartNum = PartNum; - Msg->MsgBody = (wc_mime_attachment *) malloc(sizeof(wc_mime_attachment)); + Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment)); if (!Msg->MsgBody) { syslog(LOG_DEBUG, "malloc() error"); } @@ -203,31 +205,33 @@ int read_message(StrBuf * Target, const char *tmpl, long tmpllen, long msgnum, c 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) && (vHdr != NULL)) { + if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) && + (vHdr != NULL)) { RenderMimeFuncStruct *Render; - + StackContext(&SuperTP, &SubTP, Msg->MsgBody, CTX_MIME_ATACH, 0, NULL); { - Render = (RenderMimeFuncStruct *) vHdr; + Render = (RenderMimeFuncStruct*)vHdr; Render->f(Target, &SubTP, FoundCharset); } UnStackContext(&SubTP); } - - if (StrLength(Msg->reply_references) > 0) { + + if (StrLength(Msg->reply_references)> 0) { /* Trim down excessively long lists of thread references. We eliminate the * second one in the list so that the thread root remains intact. */ int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|'); int rrlen = StrLength(Msg->reply_references); - if (((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10)) { + if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) { StrBufRemove_token(Msg->reply_references, 1, '|'); } } /* now check if we need to translate some mimeparts, and remove the duplicate */ it = GetNewHashPos(Msg->AllAttach, 0); - while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) && (vMime != NULL)) { + while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) && + (vMime != NULL)) { StackContext(&SuperTP, &SubTP, vMime, CTX_MIME_ATACH, 0, NULL); { evaluate_mime_part(Target, &SubTP); @@ -248,18 +252,20 @@ int read_message(StrBuf * Target, const char *tmpl, long tmpllen, long msgnum, c long HttpStatus(long CitadelStatus) { long httpstatus = 502; - - switch (MAJORCODE(CitadelStatus)) { + + switch (MAJORCODE(CitadelStatus)) + { case LISTING_FOLLOWS: case CIT_OK: httpstatus = 201; break; case ERROR: - switch (MINORCODE(CitadelStatus)) { + switch (MINORCODE(CitadelStatus)) + { case INTERNAL_ERROR: httpstatus = 403; break; - + case TOO_BIG: case ILLEGAL_VALUE: case HIGHER_ACCESS_REQUIRED: @@ -299,11 +305,11 @@ long HttpStatus(long CitadelStatus) { default: case BINARY_FOLLOWS: case SEND_BINARY: - case START_CHAT_MODE: + case SEND_THEN_RECV: case ASYNC_MSG: case MORE_DATA: case SEND_LISTING: - httpstatus = 502; /* aeh... whut? */ + httpstatus = 502; /* aeh... whut? */ break; } @@ -335,22 +341,23 @@ void handle_one_message(void) { msgnum = atol(pMsg + 1); StrBufCutAt(WC->Hdr->HR.ReqLine, 0, pMsg); gotoroom(WC->Hdr->HR.ReqLine); - switch (WC->Hdr->HR.eReqType) { + switch (WC->Hdr->HR.eReqType) + { case eGET: case ePOST: Tmpl = sbstr("template"); - if (StrLength(Tmpl) > 0) + if (StrLength(Tmpl) > 0) read_message(WC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime, NULL); - else + else read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime, NULL); http_transmit_thing(ChrPtr(Mime), 0); break; case eDELETE: - CmdBuf = NewStrBuf(); + CmdBuf = NewStrBuf (); if ((WC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */ - serv_printf("DELE %ld", msgnum); + serv_printf("DELE %ld", msgnum); } - else { /* Otherwise move it to Trash */ + else { /* Otherwise move it to Trash */ serv_printf("MOVE %ld|_TRASH_|0", msgnum); } StrBuf_ServGetln(CmdBuf); @@ -360,8 +367,9 @@ void handle_one_message(void) { case eCOPY: CopyMessage = 1; case eMOVE: - if (GetHash(WC->Hdr->HTTPHeaders, HKEY("DESTINATION"), &vLine) && (vLine != NULL)) { - Destination = (StrBuf *) vLine; + if (GetHash(WC->Hdr->HTTPHeaders, HKEY("DESTINATION"), &vLine) && + (vLine!=NULL)) { + Destination = (StrBuf*) vLine; serv_printf("MOVE %ld|%s|%d", msgnum, ChrPtr(Destination), CopyMessage); StrBuf_ServGetln(CmdBuf); GetServerStatusMsg(CmdBuf, NULL, 1, 0); @@ -389,25 +397,25 @@ void embed_message(void) { StrBuf *CmdBuf = NULL; msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/'); - if (msgnum <= 0) - return; + if (msgnum <= 0) return; - switch (WC->Hdr->HR.eReqType) { + switch (WC->Hdr->HR.eReqType) + { case eGET: case ePOST: Tmpl = sbstr("template"); - if (StrLength(Tmpl) > 0) + if (StrLength(Tmpl) > 0) read_message(WC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime, NULL); - else + else read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime, NULL); http_transmit_thing(ChrPtr(Mime), 0); break; case eDELETE: - CmdBuf = NewStrBuf(); + CmdBuf = NewStrBuf (); if ((WC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */ - serv_printf("DELE %ld", msgnum); + serv_printf("DELE %ld", msgnum); } - else { /* Otherwise move it to Trash */ + else { /* Otherwise move it to Trash */ serv_printf("MOVE %ld|_TRASH_|0", msgnum); } StrBuf_ServGetln(CmdBuf); @@ -430,7 +438,9 @@ void print_message(void) { msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/'); output_headers(0, 0, 0, 0, 0, 0); - hprintf("Content-type: text/html\r\n" "Server: " PACKAGE_STRING "\r\n" "Connection: close\r\n"); + hprintf("Content-type: text/html\r\n" + "Server: " PACKAGE_STRING "\r\n" + "Connection: close\r\n"); begin_burst(); @@ -450,7 +460,10 @@ void display_headers(void) { msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/'); output_headers(0, 0, 0, 0, 0, 0); - hprintf("Content-type: text/plain\r\n" "Server: %s\r\n" "Connection: close\r\n", PACKAGE_STRING); + hprintf("Content-type: text/plain\r\n" + "Server: %s\r\n" + "Connection: close\r\n", + PACKAGE_STRING); begin_burst(); serv_printf("MSG2 %ld|1", msgnum); @@ -472,10 +485,14 @@ void display_headers(void) { */ int load_msg_ptrs(const char *servcmd, const char *filter, - StrBuf * FoundCharset, - SharedMessageStatus * Stat, + StrBuf *FoundCharset, + SharedMessageStatus *Stat, void **ViewSpecific, - load_msg_ptrs_detailheaders LH, StrBuf * FetchMessageList, eMessageField * MessageFieldList, long HeaderCount) { + load_msg_ptrs_detailheaders LH, + StrBuf *FetchMessageList, + eMessageField *MessageFieldList, + long HeaderCount) +{ message_summary *Msg; StrBuf *Buf, *Buf2; long len; @@ -491,7 +508,7 @@ int load_msg_ptrs(const char *servcmd, DeleteHash(&WC->summ); } WC->summ = NewHash(1, Flathash); - + Buf = NewStrBuf(); serv_puts(servcmd); StrBuf_ServGetln(Buf); @@ -502,7 +519,7 @@ int load_msg_ptrs(const char *servcmd, case 8: if (filter != NULL) { serv_puts(filter); - serv_puts("000"); + serv_puts("000"); break; } else if (FetchMessageList != NULL) { @@ -518,11 +535,11 @@ int load_msg_ptrs(const char *servcmd, return (Stat->nummsgs); } Buf2 = NewStrBuf(); - while (len = StrBuf_ServGetln(Buf), ((len >= 0) && ((len != 3) || strcmp(ChrPtr(Buf), "000") != 0))) { + while (len = StrBuf_ServGetln(Buf), ((len >= 0) && ((len != 3) || strcmp(ChrPtr(Buf), "000")!= 0))) { if (Stat->nummsgs < Stat->maxload) { skipit = 0; Ptr = NULL; - Msg = (message_summary *) malloc(sizeof(message_summary)); + Msg = (message_summary*)malloc(sizeof(message_summary)); if (!Msg) { syslog(LOG_DEBUG, "malloc() error"); } @@ -560,17 +577,17 @@ int load_msg_ptrs(const char *servcmd, */ if (Msg->date == 0) { Msg->date = Stat->nummsgs; - if (StrLength(Buf) < 32) + if (StrLength(Buf) < 32) skipit = 1; } if ((!skipit) && (LH != NULL)) { - if (!LH(Buf, &Ptr, Msg, Buf2, ViewSpecific)) { + if (!LH(Buf, &Ptr, Msg, Buf2, ViewSpecific)){ free(Msg); continue; - } + } } n = Msg->msgnum; - Put(WC->summ, (const char *) &n, sizeof(n), Msg, DestroyMessageSummary); + Put(WC->summ, (const char *)&n, sizeof(n), Msg, DestroyMessageSummary); } Stat->nummsgs++; } @@ -586,7 +603,7 @@ int load_msg_ptrs(const char *servcmd, * MatchMSet: MSet we want to flag * FlagToSet: Flag to set on each BasicMsgStruct->Flags if in MSet */ -long 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; @@ -597,7 +614,7 @@ long SetFlagsFromMSet(HashList * ScanMe, MSet * MatchMSet, int FlagToSet, int Re at = GetNewHashPos(ScanMe, 0); while (GetNextHashPos(ScanMe, at, &HKLen, &HashKey, &vMsg)) { /* Are you a new message, or an old message? */ - Msg = (message_summary *) vMsg; + Msg = (message_summary*) vMsg; if (Reverse && IsInMSetList(MatchMSet, Msg->msgnum)) { Msg->Flags = Msg->Flags | FlagToSet; count++; @@ -628,7 +645,8 @@ long load_seen_flags(void) { return 0; } - if (ParseMSet(&MatchMSet, OldMsg)) { + if (ParseMSet(&MatchMSet, OldMsg)) + { count = SetFlagsFromMSet(WC->summ, MatchMSet, MSGFLAG_READ, 0); } DeleteMSet(&MatchMSet); @@ -638,11 +656,11 @@ long load_seen_flags(void) { extern readloop_struct rlid[]; -typedef struct _RoomRenderer { +typedef struct _RoomRenderer{ int RoomType; GetParamsGetServerCall_func GetParamsGetServerCall; - + PrintViewHeader_func PrintPageHeader; PrintViewHeader_func PrintViewHeader; LoadMsgFromServer_func LoadMsgFromServer; @@ -689,36 +707,41 @@ void readloop(long oper, eCustomRoomRenderer ForceRenderer) { Stat.highest_found = (-1); if (ForceRenderer == eUseDefault) GetHash(ReadLoopHandler, IKEY(WC->CurRoom.view), &vViewMsg); - else + else GetHash(ReadLoopHandler, IKEY(ForceRenderer), &vViewMsg); if (vViewMsg == NULL) { WC->CurRoom.view = VIEW_BBS; GetHash(ReadLoopHandler, IKEY(WC->CurRoom.view), &vViewMsg); } if (vViewMsg == NULL) { - return; /* TODO: print message */ + return; /* TODO: print message */ } - ViewMsg = (RoomRenderer *) vViewMsg; + ViewMsg = (RoomRenderer*) vViewMsg; if (ViewMsg->PrintPageHeader == NULL) output_headers(1, 1, 1, 0, 0, 0); - else + else ViewMsg->PrintPageHeader(&Stat, ViewSpecific); if (ViewMsg->GetParamsGetServerCall != NULL) { - r = ViewMsg->GetParamsGetServerCall(&Stat, &ViewSpecific, oper, cmd, sizeof(cmd), filter, sizeof(filter) - ); - } - else { + r = ViewMsg->GetParamsGetServerCall( + &Stat, + &ViewSpecific, + oper, + cmd, sizeof(cmd), + filter, sizeof(filter) + ); + } else { r = 0; } - switch (r) { + switch(r) + { case 400: case 404: return; - case 300: /* the callback hook should do the work for us here, since he knows what to do. */ + case 300: /* the callback hook should do the work for us here, since he knows what to do. */ return; case 200: default: @@ -737,7 +760,9 @@ void readloop(long oper, eCustomRoomRenderer ForceRenderer) { &Stat, &ViewSpecific, ViewMsg->LHParse, - ViewMsg->FetchMessageList, ViewMsg->MessageFieldList, ViewMsg->HeaderCount); + ViewMsg->FetchMessageList, + ViewMsg->MessageFieldList, + ViewMsg->HeaderCount); FreeStrBuf(&FoundCharset); } @@ -745,42 +770,44 @@ void readloop(long oper, eCustomRoomRenderer ForceRenderer) { CompareFunc SortIt; StackContext(NULL, &SubTP, NULL, CTX_MAILSUM, 0, NULL); { - SortIt = RetrieveSort(&SubTP, NULL, 0, HKEY("date"), Stat.defaultsortorder); + SortIt = RetrieveSort(&SubTP, + NULL, 0, + HKEY("date"), + Stat.defaultsortorder); } UnStackContext(&SubTP); if (SortIt != NULL) SortByPayload(WC->summ, SortIt); } if (Stat.startmsg < 0) { - Stat.startmsg = 0; + Stat.startmsg = 0; } - if (Stat.load_seen) - Stat.numNewmsgs = load_seen_flags(); - - /* + if (Stat.load_seen) Stat.numNewmsgs = load_seen_flags(); + + /* * Print any inforation above the message list... */ if (ViewMsg->PrintViewHeader != NULL) ViewMsg->PrintViewHeader(&Stat, &ViewSpecific); - WC->startmsg = Stat.startmsg; + WC->startmsg = Stat.startmsg; WC->maxmsgs = Stat.maxmsgs; WC->num_displayed = 0; /* Put some helpful data in vars for mailsummary_json */ { StrBuf *Foo; - - Foo = NewStrBuf(); + + 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. */ } /* @@ -790,11 +817,15 @@ void readloop(long oper, eCustomRoomRenderer ForceRenderer) { if ((ViewMsg->LoadMsgFromServer != NULL) && (!IsEmptyStr(cmd))) { at = GetNewHashPos(WC->summ, 0); Stat.num_displayed = i = 0; - while (GetNextHashPos(WC->summ, at, &HKLen, &HashKey, &vMsg)) { - Msg = (message_summary *) vMsg; + while ( GetNextHashPos(WC->summ, at, &HKLen, &HashKey, &vMsg)) { + Msg = (message_summary*) vMsg; if ((Msg->msgnum >= Stat.startmsg) && (Stat.num_displayed <= Stat.maxmsgs)) { - ViewMsg->LoadMsgFromServer(&Stat, &ViewSpecific, Msg, (Msg->Flags & MSGFLAG_READ) != 0, i); - } + ViewMsg->LoadMsgFromServer(&Stat, + &ViewSpecific, + Msg, + (Msg->Flags & MSGFLAG_READ) != 0, + i); + } i++; } DeleteHashPos(&at); @@ -831,8 +862,16 @@ void post_mime_to_server(void) { char *txtmail = NULL; int include_text_alt = 0; /* Set to nonzero to include multipart/alternative text/plain */ - sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x", ChrPtr(WC->serv_info->serv_fqdn), getpid(), ++seq); - sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x", ChrPtr(WC->serv_info->serv_fqdn), getpid(), ++seq); + sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x", + ChrPtr(WC->serv_info->serv_fqdn), + getpid(), + ++seq + ); + sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x", + ChrPtr(WC->serv_info->serv_fqdn), + getpid(), + ++seq + ); /* RFC2045 requires this, and some clients look for it... */ serv_puts("MIME-Version: 1.0"); @@ -866,11 +905,11 @@ void post_mime_to_server(void) { serv_puts("Content-type: text/plain; charset=utf-8"); serv_puts("Content-Transfer-Encoding: quoted-printable"); serv_puts(""); - txtmail = html_to_ascii(bstr("msgtext"), 0, 80); + txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0); Buf = NewStrBufPlain(txtmail, -1); - free(txtmail); + free(txtmail); - text_to_server_qp(Buf); /* Transmit message in quoted-printable encoding */ + text_to_server_qp(Buf); /* Transmit message in quoted-printable encoding */ FreeStrBuf(&Buf); serv_printf("\n--%s", alt_boundary); } @@ -879,23 +918,25 @@ void post_mime_to_server(void) { serv_puts("Content-Transfer-Encoding: quoted-printable"); serv_puts(""); serv_puts("
\r\n"); - text_to_server_qp(sbstr("msgtext")); /* Transmit message in quoted-printable encoding */ + if (havebstr("msgtext")) { + text_to_server_qp(sbstr("msgtext")); /* Transmit message in quoted-printable encoding */ + } serv_puts("\r\n"); if (include_text_alt) { serv_printf("--%s--", alt_boundary); } - + if (is_multipart) { long len; - const char *Key; + const char *Key; void *vAtt; - HashPos *it; + HashPos *it; /* Add in the attachments */ it = GetNewHashPos(WC->attachments, 0); while (GetNextHashPos(WC->attachments, it, &len, &Key, &vAtt)) { - att = (wc_mime_attachment *) vAtt; + att = (wc_mime_attachment *)vAtt; if (att->length == 0) continue; @@ -948,7 +989,7 @@ void post_message(void) { int is_anonymous = 0; const StrBuf *display_name = NULL; StrBuf *Buf; - + if (havebstr("force_room")) { gotoroom(sbstr("force_room")); } @@ -963,13 +1004,13 @@ void post_message(void) { if (!strcasecmp(bstr("submit_action"), "cancel")) { AppendImportantMessage(_("Cancelled. Message was not posted."), -1); - } - else if (lbstr("postseq") == dont_post) { - AppendImportantMessage(_("Automatically cancelled because you have already " "saved this message."), -1); - } - else { + } else if (lbstr("postseq") == dont_post) { + AppendImportantMessage( + _("Automatically cancelled because you have already " + "saved this message."), -1); + } else { const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s"; - StrBuf *Recp = NULL; + StrBuf *Recp = NULL; StrBuf *Cc = NULL; StrBuf *Bcc = NULL; StrBuf *wikipage = NULL; @@ -983,8 +1024,8 @@ void post_message(void) { Buf = NewStrBuf(); if (saving_to_drafts) { - /* temporarily change to the drafts room */ - serv_puts("GOTO _DRAFTS_"); + /* temporarily change to the drafts room */ + serv_puts("GOTO _DRAFTS_"); StrBuf_ServGetln(Buf); if (GetServerStatusMsg(Buf, NULL, 1, 2) != 2) { /* You probably don't even have a dumb Drafts folder */ @@ -996,7 +1037,8 @@ void post_message(void) { } } - if (havebstr("references")) { + if (havebstr("references")) + { const StrBuf *ref = sbstr("references"); references = NewStrBufDup(ref); if (*ChrPtr(references) == '|') { /* remove leading '|' if present */ @@ -1011,7 +1053,7 @@ void post_message(void) { * plus the QP header */ Subj = sbstr("subject"); - + StrBufRFC2047encode(&encoded_subject, Subj); } UserName = NewStrBuf(); @@ -1029,29 +1071,38 @@ void post_message(void) { wikipage = NewStrBufDup(sbstr("page")); str_wiki_index(wikipage); my_email_addr = sbstr("my_email_addr"); - - HeaderLen = StrLength(Recp) + - StrLength(encoded_subject) + - StrLength(Cc) + StrLength(Bcc) + StrLength(wikipage) + StrLength(my_email_addr) + StrLength(references); - CmdBuf = NewStrBufPlain(NULL, sizeof(CMD) + HeaderLen); - StrBufPrintf(CmdBuf, + + HeaderLen = StrLength(Recp) + + StrLength(encoded_subject) + + StrLength(Cc) + + StrLength(Bcc) + + StrLength(wikipage) + + StrLength(my_email_addr) + + StrLength(references); + CmdBuf = NewStrBufPlain(NULL, sizeof (CMD) + HeaderLen); + StrBufPrintf(CmdBuf, CMD, - saving_to_drafts ? "" : ChrPtr(Recp), + saving_to_drafts?"":ChrPtr(Recp), is_anonymous, ChrPtr(encoded_subject), ChrPtr(display_name), - saving_to_drafts ? "" : ChrPtr(Cc), - saving_to_drafts ? "" : ChrPtr(Bcc), ChrPtr(wikipage), ChrPtr(my_email_addr), ChrPtr(references)); + saving_to_drafts?"":ChrPtr(Cc), + saving_to_drafts?"":ChrPtr(Bcc), + ChrPtr(wikipage), + ChrPtr(my_email_addr), + ChrPtr(references)); FreeStrBuf(&references); FreeStrBuf(&encoded_subject); free(wikipage); - if ((HeaderLen + StrLength(sbstr("msgtext")) < 10) && (GetCount(WC->attachments) == 0)) { + if ((HeaderLen + StrLength(sbstr("msgtext")) < 10) && + (GetCount(WC->attachments) == 0)){ AppendImportantMessage(_("Refusing to post empty message.\n"), -1); FreeStrBuf(&CmdBuf); - + } - else { + else + { syslog(LOG_DEBUG, "%s\n", ChrPtr(CmdBuf)); serv_puts(ChrPtr(CmdBuf)); FreeStrBuf(&CmdBuf); @@ -1059,15 +1110,14 @@ void post_message(void) { StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 4) { if (saving_to_drafts) { - if ((havebstr("recp")) - || (havebstr("cc")) - || (havebstr("bcc"))) { + if ( (havebstr("recp")) + || (havebstr("cc" )) + || (havebstr("bcc" )) ) { /* save recipient headers or room to post to */ serv_printf("To: %s", ChrPtr(Recp)); serv_printf("Cc: %s", ChrPtr(Cc)); serv_printf("Bcc: %s", ChrPtr(Bcc)); - } - else { + } else { serv_printf("X-Citadel-Room: %s", ChrPtr(WC->CurRoom.name)); } } @@ -1079,24 +1129,21 @@ void post_message(void) { readloop(readnew, eUseDefault); FreeStrBuf(&Buf); return; - } - else if ((havebstr("recp")) - || (havebstr("cc")) - || (havebstr("bcc")) - ) { + } else if ( (havebstr("recp")) + || (havebstr("cc" )) + || (havebstr("bcc" )) + ) { AppendImportantMessage(_("Message has been sent.\n"), -1); } else { AppendImportantMessage(_("Message has been posted.\n"), -1); } dont_post = lbstr("postseq"); - } - else { + } else { syslog(LOG_DEBUG, "%s:%d: server post error: %s", __FILE__, __LINE__, ChrPtr(Buf) + 4); AppendImportantMessage(ChrPtr(Buf) + 4, StrLength(Buf) - 4); display_enter(); - if (saving_to_drafts) - gotoroom(WC->CurRoom.name); + if (saving_to_drafts) gotoroom(WC->CurRoom.name); FreeStrBuf(&Recp); FreeStrBuf(&Buf); FreeStrBuf(&Cc); @@ -1178,11 +1225,11 @@ void upload_attachment(void) { wc_printf("Client is uploading %d bytes