}
-/**
- * \brief display the adressbook overview
- * \param msgnum the citadel message number
- * \param alpha what????
- */
-void display_addressbook(long msgnum, char alpha) {
- //char buf[SIZ];
- /* char mime_partnum[SIZ]; */
-/* char mime_filename[SIZ]; */
-/* char mime_content_type[SIZ]; */
- ///char mime_disposition[SIZ];
- //int mime_length;
- char vcard_partnum[SIZ];
- char *vcard_source = NULL;
- message_summary summ;////TODO: this will leak
-
- memset(&summ, 0, sizeof(summ));
- ///safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
-///Load Message headers
-// Msg =
- if (!IsEmptyStr(vcard_partnum)) {
- vcard_source = load_mimepart(msgnum, vcard_partnum);
- if (vcard_source != NULL) {
-
- /** Display the summary line */
- display_vcard(WC->WBuf, vcard_source, alpha, 0, NULL,msgnum);
-
- /** If it's my vCard I can edit it */
- if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
- || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
- || (WC->wc_view == VIEW_ADDRESSBOOK)
- ) {
- wprintf("<a href=\"edit_vcard?"
- "msgnum=%ld&partnum=%s\">",
- msgnum, vcard_partnum);
- wprintf("[%s]</a>", _("edit"));
- }
-
- free(vcard_source);
- }
- }
-
-}
-
-
-
-/**
- * \brief If it's an old "Firstname Lastname" style record, try to convert it.
- * \param namebuf name to analyze, reverse if nescessary
- */
-void lastfirst_firstlast(char *namebuf) {
- char firstname[SIZ];
- char lastname[SIZ];
- int i;
-
- if (namebuf == NULL) return;
- if (strchr(namebuf, ';') != NULL) return;
-
- i = num_tokens(namebuf, ' ');
- if (i < 2) return;
-
- extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
- remove_token(namebuf, i-1, ' ');
- strcpy(firstname, namebuf);
- sprintf(namebuf, "%s; %s", lastname, firstname);
-}
-
-/**
- * \brief fetch what??? name
- * \param msgnum the citadel message number
- * \param namebuf where to put the name in???
- */
-void fetch_ab_name(message_summary *Msg, char *namebuf) {
- char buf[SIZ];
- char mime_partnum[SIZ];
- char mime_filename[SIZ];
- char mime_content_type[SIZ];
- char mime_disposition[SIZ];
- int mime_length;
- char vcard_partnum[SIZ];
- char *vcard_source = NULL;
- int i, len;
- message_summary summ;/// TODO this will lak
-
- if (namebuf == NULL) return;
- strcpy(namebuf, "");
-
- memset(&summ, 0, sizeof(summ));
- //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
-
- sprintf(buf, "MSG0 %ld|0", Msg->msgnum); /** unfortunately we need the mime info now */
- serv_puts(buf);
- serv_getln(buf, sizeof buf);
- if (buf[0] != '1') return;
-
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- if (!strncasecmp(buf, "part=", 5)) {
- extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
- extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
- extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
- extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
- mime_length = extract_int(&buf[5], 5);
-
- if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
- || (!strcasecmp(mime_content_type, "text/vcard")) ) {
- strcpy(vcard_partnum, mime_partnum);
- }
-
- }
- }
-
- if (!IsEmptyStr(vcard_partnum)) {
- vcard_source = load_mimepart(Msg->msgnum, vcard_partnum);
- if (vcard_source != NULL) {
-
- /* Grab the name off the card */
- display_vcard(WC->WBuf, vcard_source, 0, 0, namebuf, Msg->msgnum);
-
- free(vcard_source);
- }
- }
-
- lastfirst_firstlast(namebuf);
- striplt(namebuf);
- len = strlen(namebuf);
- for (i=0; i<len; ++i) {
- if (namebuf[i] != ';') return;
- }
- strcpy(namebuf, _("(no name)"));
-}
-
-
wDumpContent(1);
}
+
+/*
+ * Generic function to output an arbitrary MIME attachment from
+ * message being composed
+ *
+ * partnum The MIME part to be output
+ * filename Fake filename to give
+ * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
+ */
+void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
+{
+ void *vPart;
+ StrBuf *content_type;
+ wc_mime_attachment *part;
+
+ if (GetHash(WC->attachments, SKEY(partnum), &vPart) &&
+ (vPart != NULL)) {
+ part = (wc_mime_attachment*) vPart;
+ if (force_download) {
+ content_type = NewStrBufPlain(HKEY("application/octet-stream"));
+ }
+ else {
+ content_type = NewStrBufDup(part->ContentType);
+ }
+ output_headers(0, 0, 0, 0, 0, 0);
+ StrBufAppendBuf(WC->WBuf, part->Data, 0);
+ http_transmit_thing(ChrPtr(content_type), 0);
+ } else {
+ hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
+ output_headers(0, 0, 0, 0, 0, 0);
+ hprintf("Content-Type: text/plain\r\n");
+ wprintf(_("An error occurred while retrieving this part: %s/%s\n"),
+ ChrPtr(partnum), ChrPtr(filename));
+ end_burst();
+ }
+ FreeStrBuf(&content_type);
+}
+
+
+/*
+ * Generic function to output an arbitrary MIME part from an arbitrary
+ * message number on the server.
+ *
+ * msgnum Number of the item on the citadel server
+ * partnum The MIME part to be output
+ * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
+ */
+void mimepart(const char *msgnum, const char *partnum, int force_download)
+{
+ char buf[256];
+ off_t bytes;
+ char content_type[256];
+
+ serv_printf("OPNA %s|%s", msgnum, partnum);
+ serv_getln(buf, sizeof buf);
+ if (buf[0] == '2') {
+ bytes = extract_long(&buf[4], 0);
+ if (force_download) {
+ strcpy(content_type, "application/octet-stream");
+ }
+ else {
+ extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
+ }
+ output_headers(0, 0, 0, 0, 0, 0);
+
+ read_server_binary(WC->WBuf, bytes);
+ serv_puts("CLOS");
+ serv_getln(buf, sizeof buf);
+ http_transmit_thing(content_type, 0);
+ } else {
+ hprintf("HTTP/1.1 404 %s\n", &buf[4]);
+ output_headers(0, 0, 0, 0, 0, 0);
+ hprintf("Content-Type: text/plain\r\n");
+ wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
+ end_burst();
+ }
+}
+
+
+/*
+ * Read any MIME part of a message, from the server, into memory.
+ */
+char *load_mimepart(long msgnum, char *partnum)
+{
+ char buf[SIZ];
+ off_t bytes;
+ char content_type[SIZ];
+ char *content;
+
+ serv_printf("DLAT %ld|%s", msgnum, partnum);
+ serv_getln(buf, sizeof buf);
+ if (buf[0] == '6') {
+ bytes = extract_long(&buf[4], 0);
+ extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
+
+ content = malloc(bytes + 2);
+ serv_read(content, bytes);
+
+ content[bytes] = 0; /* null terminate for good measure */
+ return(content);
+ }
+ else {
+ return(NULL);
+ }
+}
+
+/*
+ * Read any MIME part of a message, from the server, into memory.
+ */
+void MimeLoadData(wc_mime_attachment *Mime)
+{
+ char buf[SIZ];
+ off_t bytes;
+//// TODO: is there a chance the contenttype is different to the one we know?
+ serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
+ serv_getln(buf, sizeof buf);
+ if (buf[0] == '6') {
+ bytes = extract_long(&buf[4], 0);
+
+ if (Mime->Data == NULL)
+ Mime->Data = NewStrBufPlain(NULL, bytes);
+ StrBuf_ServGetBLOB(Mime->Data, bytes);
+
+ }
+ else {
+ FlushStrBuf(Mime->Data);
+ /// TODO XImportant message
+ }
+}
+
+
+
+
+void view_mimepart(void) {
+ mimepart(ChrPtr(WC->UrlFragment2),
+ ChrPtr(WC->UrlFragment3),
+ 0);
+}
+
+void download_mimepart(void) {
+ mimepart(ChrPtr(WC->UrlFragment2),
+ ChrPtr(WC->UrlFragment3),
+ 1);
+}
+
+void view_postpart(void) {
+ postpart(WC->UrlFragment2,
+ WC->UrlFragment3,
+ 0);
+}
+
+void download_postpart(void) {
+ postpart(WC->UrlFragment2,
+ WC->UrlFragment3,
+ 1);
+}
+
+
+
void h_readnew(void) { readloop(readnew);}
void h_readold(void) { readloop(readold);}
void h_readfwd(void) { readloop(readfwd);}
WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);
+ WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL);
+ WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL);
+ WebcitAddUrlHandler(HKEY("postpart"), view_postpart, NEED_URL);
+ WebcitAddUrlHandler(HKEY("postpart_download"), download_postpart, NEED_URL);
return ;
}