* 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)
+int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, const StrBuf *PartNum, const StrBuf **OutMime)
{
StrBuf *Buf;
StrBuf *FoundCharset;
memset(&SubTP, 0, sizeof(WCTemplputParams));
SubTP.Filter.ContextType = CTX_MAILSUM;
SubTP.Context = Msg;
- DoTemplate(tmpl, tmpllen, Target, &SubTP);
+ *OutMime = DoTemplate(tmpl, tmpllen, Target, &SubTP);
DestroyMessageSummary(Msg);
FreeStrBuf(&FoundCharset);
+void
+HttpStatus(long CitadelStatus)
+{
+ long httpstatus = 502;
+ long MajorStat = MAJORCODE(CitadelStatus);
+ long MinorStat = MINORCODE(CitadelStatus);
+
+ switch (MAJORCODE(CitadelStatus))
+ {
+ case LISTING_FOLLOWS:
+ case CIT_OK:
+ httpstatus = 201;
+ break;
+ case ERROR:
+ switch (MINORCODE(CitadelStatus))
+ {
+ case INTERNAL_ERROR:
+ httpstatus = 403;
+ break;
+
+ case TOO_BIG:
+ case ILLEGAL_VALUE:
+ case HIGHER_ACCESS_REQUIRED:
+ case MAX_SESSIONS_EXCEEDED:
+ case RESOURCE_BUSY:
+ case RESOURCE_NOT_OPEN:
+ case NOT_HERE:
+ case INVALID_FLOOR_OPERATION:
+ case FILE_NOT_FOUND:
+ case ROOM_NOT_FOUND:
+ httpstatus = 409;
+ break;
+
+ case MESSAGE_NOT_FOUND:
+ case ALREADY_EXISTS:
+ httpstatus = 403;
+ break;
+
+ case NO_SUCH_SYSTEM:
+ httpstatus = 502;
+ break;
+
+ default:
+ case CMD_NOT_SUPPORTED:
+ case PASSWORD_REQUIRED:
+ case ALREADY_LOGGED_IN:
+ case USERNAME_REQUIRED:
+ case NOT_LOGGED_IN:
+ case SERVER_SHUTTING_DOWN:
+ case NO_SUCH_USER:
+ case ASYNC_GEXP:
+ httpstatus = 502;
+ break;
+ }
+ break;
+ default:
+ case BINARY_FOLLOWS:
+ case SEND_BINARY:
+ case START_CHAT_MODE:
+ case ASYNC_MSG:
+ case MORE_DATA:
+ case SEND_LISTING:
+ httpstatus = 502; /* aeh... whut? */
+ break;
+ }
+}
+
+/*
+ * Unadorned HTML output of an individual message, suitable
+ * for placing in a hidden iframe, for printing, or whatever
+ *
+ * msgnum_as_string == Message number, as a string instead of as a long int
+ */
+void handle_one_message(void)
+{
+ long CitStatus;
+ int CopyMessage = 0;
+ const StrBuf *Destination;
+ void *vLine;
+ const StrBuf *Mime;
+ long msgnum = 0L;
+ wcsession *WCC = WC;
+ const StrBuf *Tmpl;
+ StrBuf *CmdBuf = NULL;
+
+ //msgnum = StrTol(WCC->UrlFragment3);
+ //gotoroom(WCC->UrlFragment2);
+ switch (WCC->Hdr->eReqType)
+ {
+ case eGET:
+ case ePOST:
+ Tmpl = sbstr("template");
+ if (StrLength(Tmpl) > 0)
+ read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
+ else
+ read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
+ http_transmit_thing(ChrPtr(Mime), 0);
+ break;
+ case eDELETE:
+ CmdBuf = NewStrBuf ();
+ if (WCC->wc_is_trash) { /** Delete from Trash is a real delete */
+ serv_printf("DELE %ld", msgnum);
+ }
+ else { /** Otherwise move it to Trash */
+ serv_printf("MOVE %ld|_TRASH_|0", msgnum);
+ }
+ StrBuf_ServGetln(CmdBuf);
+ FlushStrBuf(WCC->ImportantMsg);
+ StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
+ GetServerStatus(CmdBuf, &CitStatus);
+ HttpStatus(CitStatus);
+ break;
+ case eCOPY:
+ CopyMessage = 1;
+ case eMOVE:
+ if (GetHash(WCC->Hdr->HTTPHeaders, HKEY("DESTINATION"), &vLine) &&
+ (vLine!=NULL)) {
+ Destination = (StrBuf*) vLine;
+ serv_printf("MOVE %ld|%s|%d", msgnum, ChrPtr(Destination), CopyMessage);
+ StrBuf_ServGetln(CmdBuf);
+ FlushStrBuf(WCC->ImportantMsg);
+ StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
+ GetServerStatus(CmdBuf, &CitStatus);
+ HttpStatus(CitStatus);
+ }
+ else
+ HttpStatus(500);
+ break;
+ default:
+ break;
+
+ }
+}
/*
* Unadorned HTML output of an individual message, suitable
* for placing in a hidden iframe, for printing, or whatever
* msgnum_as_string == Message number, as a string instead of as a long int
*/
void embed_message(void) {
+ const StrBuf *Mime;
long msgnum = 0L;
wcsession *WCC = WC;
- const StrBuf *Tmpl = sbstr("template");
+ const StrBuf *Tmpl;
+ StrBuf *CmdBuf = NULL;
- msgnum = StrTol(WCC->UrlFragment2);
- if (StrLength(Tmpl) > 0)
- read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL);
- else
- read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL);
+ msgnum = StrBufExtract_long(WCC->Hdr->ReqLine, 0, '/');
+ switch (WCC->Hdr->eReqType)
+ {
+ case eGET:
+ case ePOST:
+ Tmpl = sbstr("template");
+ if (StrLength(Tmpl) > 0)
+ read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
+ else
+ read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
+ http_transmit_thing(ChrPtr(Mime), 0);
+ break;
+ case eDELETE:
+ CmdBuf = NewStrBuf ();
+ if (WCC->wc_is_trash) { /** Delete from Trash is a real delete */
+ serv_printf("DELE %ld", msgnum);
+ }
+ else { /** Otherwise move it to Trash */
+ serv_printf("MOVE %ld|_TRASH_|0", msgnum);
+ }
+ StrBuf_ServGetln(CmdBuf);
+ FlushStrBuf(WCC->ImportantMsg);
+ StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
+ break;
+ default:
+ break;
+
+ }
}
*/
void print_message(void) {
long msgnum = 0L;
+ const StrBuf *Mime;
- msgnum = StrTol(WC->UrlFragment2);
+ msgnum = StrBufExtract_long(WC->Hdr->ReqLine, 0, '/');
output_headers(0, 0, 0, 0, 0, 0);
hprintf("Content-type: text/html\r\n"
begin_burst();
- read_message(WC->WBuf, HKEY("view_message_print"), msgnum, NULL);
+ read_message(WC->WBuf, HKEY("view_message_print"), msgnum, NULL, &Mime);
wDumpContent(0);
}
*
* @param msg_num_as_string Message number as a string instead of as a long int
*/
-void mobile_message_view(void) {
- long msgnum = 0L;
- msgnum = StrTol(WC->UrlFragment2);
- output_headers(1, 0, 0, 0, 0, 1);
- begin_burst();
- do_template("msgcontrols", NULL);
- read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL);
- wDumpContent(0);
+void mobile_message_view(void)
+{
+ long msgnum = 0L;
+ const StrBuf *Mime;
+
+ msgnum = StrBufExtract_long(WC->Hdr->ReqLine, 0, '/');
+ output_headers(1, 0, 0, 0, 0, 1);
+ begin_burst();
+ do_template("msgcontrols", NULL);
+ read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
+ wDumpContent(0);
}
/**
long msgnum = 0L;
char buf[1024];
- msgnum = StrTol(WC->UrlFragment2);
+ msgnum = StrBufExtract_long(WC->Hdr->ReqLine, 0, '/');
output_headers(0, 0, 0, 0, 0, 0);
hprintf("Content-type: text/plain\r\n"
int defaultsortorder = 0;
WCTemplputParams SubTP;
char *ab_name;
+ const StrBuf *Mime;
if (havebstr("is_summary") && (1 == (ibstr("is_summary"))))
WCC->wc_view = VIEW_MAILBOX;
/** if we do a split bbview in the future, begin messages div here */
for (a=0; a<num_displayed; ++a) {
- read_message(WCC->WBuf, HKEY("view_message"), displayed_msgs[a], NULL);
+ read_message(WCC->WBuf, HKEY("view_message"), displayed_msgs[a], NULL, &Mime);
}
/** if we do a split bbview in the future, end messages div here */
break;
case VIEW_ADDRESSBOOK:
if (is_singlecard)
- read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL);
+ read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
else
do_addrbook_view(addrbook, num_ab); /** Render the address book */
break;
*/
void mimepart(int force_download)
{
+ long msgnum, att;
wcsession *WCC = WC;
StrBuf *Buf;
off_t bytes;
StrBuf *ContentType = NewStrBufPlain(HKEY("application/octet-stream"));
const char *CT;
+ msgnum = StrBufExtract_long(WCC->Hdr->ReqLine, 0, '/');
+ att = StrBufExtract_long(WCC->Hdr->ReqLine, 1, '/');
+
Buf = NewStrBuf();
- serv_printf("OPNA %s|%s", ChrPtr(WCC->UrlFragment2), ChrPtr(WCC->UrlFragment3));
+ serv_printf("OPNA %ld|%ld", msgnum, att);
StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) == 2) {
StrBufCutLeft(Buf, 4);
if (!force_download) {
if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
- CT = GuessMimeByFilename(SKEY(WCC->UrlFragment4));
+ StrBufExtract_token(Buf, WCC->Hdr->ReqLine, 2, '/');
+ CT = GuessMimeByFilename(SKEY(Buf));
}
if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
CT = GuessMimeType(SKEY(WCC->WBuf));
}
void view_postpart(void) {
- postpart(WC->UrlFragment2,
- WC->UrlFragment3,
- 0);
+ StrBuf *filename = NewStrBuf();
+ StrBuf *partnum = NewStrBuf();
+
+ StrBufExtract_token(partnum, WC->Hdr->ReqLine, 0, '/');
+ StrBufExtract_token(filename, WC->Hdr->ReqLine, 1, '/');
+
+ postpart(partnum, filename, 0);
+
+ FreeStrBuf(&filename);
+ FreeStrBuf(&partnum);
}
void download_postpart(void) {
- postpart(WC->UrlFragment2,
- WC->UrlFragment3,
- 1);
+ StrBuf *filename = NewStrBuf();
+ StrBuf *partnum = NewStrBuf();
+
+ StrBufExtract_token(partnum, WC->Hdr->ReqLine, 0, '/');
+ StrBufExtract_token(filename, WC->Hdr->ReqLine, 1, '/');
+
+ postpart(partnum, filename, 1);
+
+ FreeStrBuf(&filename);
+ FreeStrBuf(&partnum);
}
void h_readnew(void) { readloop(readnew);}
WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
- WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL|AJAX);
+ WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL);
+ WebcitAddUrlHandler(HKEY("message"), handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);