* as one of the other MIME parts, attempt to load it now.
*/
if ((Data == NULL) && (!IsEmptyStr(relevant_partnum))) {
- relevant_source = load_mimepart(msgnum, relevant_partnum);
+ Data = load_mimepart(msgnum, relevant_partnum);
}
- if ((relevant_source != NULL) || (Data != NULL)) {
+ if (Data != NULL) {
relevant_source = (char*) ChrPtr(Data);
process_ical_object(msgnum, unread,
from,
which_kind,
CallBack,
calv);
- if (Data != NULL)
- FreeStrBuf (&Data);
- else
- free(relevant_source);
-
+ FreeStrBuf (&Data);
}
icalmemory_free_ring();
/*
* Read any MIME part of a message, from the server, into memory.
*/
-char *load_mimepart(long msgnum, char *partnum)
+StrBuf *load_mimepart(long msgnum, char *partnum)
{
- char buf[SIZ];
off_t bytes;
- char content_type[SIZ];
- char *content;
+ StrBuf *Buf;
+ Buf = NewStrBuf();
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);
+ StrBuf_ServGetlnBuffered(Buf);
+ if (GetServerStatus(Buf, NULL) == 6) {
+ StrBufCutLeft(Buf, 4);
+ bytes = StrBufExtract_long(Buf, 0, '|');
- content[bytes] = 0; /* null terminate for good measure */
- return(content);
+ StrBuf_ServGetBLOBBuffered(Buf, bytes);
+ return(Buf);
}
else {
+ FreeStrBuf(&Buf);
return(NULL);
}
}
}
/* In all cases, display the full card */
- display_vcard(Buf, ChrPtr(Mime->Data), 0, 1, NULL, Mime->msgnum);
+ display_vcard(Buf, Mime->Data, 0, 1, NULL, Mime->msgnum);
FreeStrBuf(&Mime->Data);
Mime->Data = Buf;
}
/*
* Fetch a message from the server and extract a vNote from it
*/
-struct vnote *vnote_new_from_msg(long msgnum) {
- char buf[1024];
+struct vnote *vnote_new_from_msg(long msgnum,int unread)
+{
+ StrBuf *Buf;
+ StrBuf *Data;
+ const char *bptr;
+ int Done = 0;
+ char from[128] = "";
+ char uid_from_headers[256];
char mime_partnum[256];
char mime_filename[256];
char mime_content_type[256];
char mime_disposition[256];
int mime_length;
char relevant_partnum[256];
- char *relevant_source = NULL;
- char uid_from_headers[256];
- int in_body = 0;
- int body_line_len = 0;
- int body_len = 0;
+ int phase = 0; /* 0 = citadel headers, 1 = mime headers, 2 = body */
+ char msg4_content_type[256] = "";
+ char msg4_content_encoding[256] = "";
+ int msg4_content_length = 0;
struct vnote *vnote_from_body = NULL;
- relevant_partnum[0] = 0;
- uid_from_headers[0] = 0;
- sprintf(buf, "MSG4 %ld", msgnum); /* we need the mime headers */
- serv_puts(buf);
- serv_getln(buf, sizeof buf);
- if (buf[0] != '1') return NULL;
-
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- if (!strncasecmp(buf, "exti=", 5)) {
- safestrncpy(uid_from_headers, &buf[5], sizeof uid_from_headers);
+ relevant_partnum[0] = '\0';
+ serv_printf("MSG4 %ld", msgnum); /* we need the mime headers */
+ Buf = NewStrBuf();
+ StrBuf_ServGetlnBuffered(Buf);
+ if (GetServerStatus(Buf, NULL) != 1) {
+ FreeStrBuf (&Buf);
+ return NULL;
+ }
+ while ((StrBuf_ServGetlnBuffered(Buf)>=0) && !Done) {
+ if ( (StrLength(Buf)==3) &&
+ !strcmp(ChrPtr(Buf), "000")) {
+ Done = 1;
+ break;
}
- else 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/vnote")) {
- strcpy(relevant_partnum, mime_partnum);
+ bptr = ChrPtr(Buf);
+ switch (phase) {
+ case 0:
+ if (!strncasecmp(bptr, "exti=", 5)) {
+ safestrncpy(uid_from_headers, &(ChrPtr(Buf)[5]), sizeof uid_from_headers);
}
- }
- else if ((in_body) && (IsEmptyStr(relevant_partnum)) && (!IsEmptyStr(uid_from_headers))) {
- // Convert an old-style note to a vNote
- if (!vnote_from_body) {
- vnote_from_body = vnote_new();
- vnote_from_body->uid = strdup(uid_from_headers);
- vnote_from_body->color_red = pastel_palette[3][0];
- vnote_from_body->color_green = pastel_palette[3][1];
- vnote_from_body->color_blue = pastel_palette[3][2];
- vnote_from_body->body = malloc(32768);
- vnote_from_body->body[0] = 0;
- body_len = 0;
+ else if (!strncasecmp(bptr, "part=", 5)) {
+ extract_token(mime_filename, &bptr[5], 1, '|', sizeof mime_filename);
+ extract_token(mime_partnum, &bptr[5], 2, '|', sizeof mime_partnum);
+ extract_token(mime_disposition, &bptr[5], 3, '|', sizeof mime_disposition);
+ extract_token(mime_content_type, &bptr[5], 4, '|', sizeof mime_content_type);
+ mime_length = extract_int(&bptr[5], 5);
+
+ if ( (!strcasecmp(mime_content_type, "text/calendar"))
+ || (!strcasecmp(mime_content_type, "application/ics"))
+ || (!strcasecmp(mime_content_type, "text/vtodo"))
+ ) {
+ strcpy(relevant_partnum, mime_partnum);
+ }
}
- body_line_len = strlen(buf);
- if ((body_len + body_line_len + 10) < 32768) {
- strcpy(&vnote_from_body->body[body_len++], " ");
- strcpy(&vnote_from_body->body[body_len], buf);
- body_len += body_line_len;
+ else if (!strncasecmp(bptr, "from=", 4)) {
+ extract_token(from, bptr, 1, '=', sizeof(from));
}
- }
- else if (IsEmptyStr(buf)) {
- in_body = 1;
+ else if ((phase == 0) && (!strncasecmp(bptr, "text", 4))) {
+ phase = 1;
+ }
+ break;
+ case 1:
+ if (!IsEmptyStr(bptr)) {
+ if (!strncasecmp(bptr, "Content-type: ", 14)) {
+ safestrncpy(msg4_content_type, &bptr[14], sizeof msg4_content_type);
+ striplt(msg4_content_type);
+ }
+ else if (!strncasecmp(bptr, "Content-transfer-encoding: ", 27)) {
+ safestrncpy(msg4_content_encoding, &bptr[27], sizeof msg4_content_encoding);
+ striplt(msg4_content_type);
+ }
+ else if ((!strncasecmp(bptr, "Content-length: ", 16))) {
+ msg4_content_length = atoi(&bptr[16]);
+ }
+ break;
+ }
+ else {
+ phase++;
+
+ if ((msg4_content_length > 0)
+ && ( !strcasecmp(msg4_content_encoding, "7bit"))
+ && ((!strcasecmp(mime_content_type, "text/calendar"))
+ || (!strcasecmp(mime_content_type, "application/ics"))
+ || (!strcasecmp(mime_content_type, "text/vtodo"))
+ )
+ )
+ {
+ }
+ }
+ case 2:
+ Data = NewStrBufPlain(NULL, msg4_content_length * 2);
+ if (msg4_content_length > 0) {
+ StrBuf_ServGetBLOBBuffered(Data, msg4_content_length);
+ phase ++;
+ }
+ else {
+ StrBufAppendBuf(Data, Buf, 0);
+ StrBufAppendBufPlain(Data, "\r\n", 1, 0);
+ }
+ case 3:
+ StrBufAppendBuf(Data, Buf, 0);
}
}
+ FreeStrBuf(&Buf);
- if (!IsEmptyStr(relevant_partnum)) {
- relevant_source = load_mimepart(msgnum, relevant_partnum);
- if (relevant_source != NULL) {
- struct vnote *v = vnote_new_from_str(relevant_source);
- free(relevant_source);
- return(v);
- }
+ /* If MSG4 didn't give us the part we wanted, but we know that we can find it
+ * as one of the other MIME parts, attempt to load it now.
+ */
+ if ((Data == NULL) && (!IsEmptyStr(relevant_partnum))) {
+ Data = load_mimepart(msgnum, relevant_partnum);
}
- if (vnote_from_body) {
- return(vnote_from_body);
+
+ if ((IsEmptyStr(relevant_partnum)) && (StrLength(Data) > 0 )) {
+ if (!IsEmptyStr(uid_from_headers)) {
+ // Convert an old-style note to a vNote
+ vnote_from_body = vnote_new();
+ vnote_from_body->uid = strdup(uid_from_headers);
+ vnote_from_body->color_red = pastel_palette[3][0];
+ vnote_from_body->color_green = pastel_palette[3][1];
+ vnote_from_body->color_blue = pastel_palette[3][2];
+ vnote_from_body->body = malloc(StrLength(Data) + 1);
+ vnote_from_body->body[0] = 0;
+ memcpy(vnote_from_body->body, ChrPtr(Data), StrLength(Data) + 1);
+ return vnote_from_body;
+ }
+ else {
+ struct vnote *v = vnote_new_from_str(ChrPtr(Data));
+ return(v);
+ }
}
return NULL;
}
+
/*
* Serialize a vnote and write it to the server
*/
}
// If we get to this point it's an update, not a delete
- v = vnote_new_from_msg(msgnum);
+ v = vnote_new_from_msg(msgnum, 0);
if (!v) {
begin_ajax_response();
wprintf("Cannot locate a vNote within message %d\n", msgnum);
memset(&TP, 0, sizeof(WCTemplputParams));
TP.Filter.ContextType = CTX_VNOTE;
- v = vnote_new_from_msg(Msg->msgnum);
+ v = vnote_new_from_msg(Msg->msgnum, unread);
if (v) {
// display_vnote_div(v);
TP.Context = v;
///char mime_disposition[SIZ];
//int mime_length;
char vcard_partnum[SIZ];
- char *vcard_source = NULL;
+ StrBuf *vcard_source = NULL;
message_summary summ;////TODO: this will leak
memset(&summ, 0, sizeof(summ));
wprintf("[%s]</a>", _("edit"));
}
- free(vcard_source);
+ FreeStrBuf(&vcard_source);
}
}
char mime_disposition[SIZ];
int mime_length;
char vcard_partnum[SIZ];
- char *vcard_source = NULL;
+ StrBuf *vcard_source = NULL;
int i, len;
message_summary summ;/// TODO this will lak
/* Grab the name off the card */
display_vcard(WC->WBuf, vcard_source, 0, 0, namebuf, Msg->msgnum);
- free(vcard_source);
+ FreeStrBuf(&vcard_source);
}
}
if (*namebuf != NULL) {
* \param msgnum Citadel message pointer
*/
void display_vcard(StrBuf *Target,
- const char *vcard_source,
+ StrBuf *vcard_source,
char alpha,
int full,
char **storename,
StrBuf *Buf2;
char this_alpha = 0;
- v = vcard_load((char*)vcard_source); ///TODO
+ v = VCardLoad(vcard_source);
if (v == NULL) return;
* to start with a blank card.
*/
void do_edit_vcard(long msgnum, char *partnum, char *return_to, const char *force_room) {
+ StrBuf *Buf;
char buf[SIZ];
- char *serialized_vcard = NULL;
+ StrBuf *serialized_vcard = NULL;
size_t total_len = 0;
struct vCard *v;
int i;
strcat(whatuser, &buf[5]);
}
}
-
- sprintf(buf, "DLAT %ld|%s", msgnum, partnum);
- serv_puts(buf);
- serv_getln(buf, sizeof buf);
- if (buf[0] != '6') {
- convenience_page("770000", "Error", &buf[4]);
+ Buf = NewStrBuf();
+ serv_printf(buf, "DLAT %ld|%s", msgnum, partnum);
+ StrBuf_ServGetlnBuffered(Buf);
+ if (GetServerStatus(Buf, NULL) != 6) {
+ convenience_page("770000", "Error", &(ChrPtr(Buf)[4]));
return;
}
-
- total_len = atoi(&buf[4]);
- serialized_vcard = malloc(total_len + 2);
+
+ StrBufCutLeft(Buf, 4);
+ total_len = StrBufExtract_long(Buf, 0, '|');
- serv_read(serialized_vcard, total_len);
- serialized_vcard[total_len] = 0;
+ StrBuf_ServGetBLOBBuffered(Buf, total_len);
- v = vcard_load(serialized_vcard);
- free(serialized_vcard);
+ v = VCardLoad(Buf);
+ FreeStrBuf(&Buf);
/* Populate the variables for our form */
i = 0;
while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
- value = vcard_get_prop(v, "", 0, i++, 0);
-
char prp[256]; /* property name */
char prm[256]; /* parameters */
+ value = vcard_get_prop(v, "", 0, i++, 0);
+
+
extract_token(prp, key, 0, ';', sizeof prp);
safestrncpy(prm, key, sizeof prm);
remove_token(prm, 0, ';');
struct vCard *v;
char *serialized_vcard;
char buf[SIZ];
+ StrBuf *Buf;
int i;
if (!havebstr("ok_button")) {
}
/** Make a vCard structure out of the data supplied in the form */
-
- snprintf(buf, sizeof buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
- bstr("extrafields")
+ Buf = NewStrBuf();
+ StrBufPrintf(Buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
+ bstr("extrafields")
);
- v = vcard_load(buf); /** Start with the extra fields */
+ v = VCardLoad(Buf); /** Start with the extra fields */
+ FreeStrBuf(&Buf);
if (v == NULL) {
safestrncpy(WC->ImportantMessage,
_("An error has occurred."),
void display_vcard_photo_img(void)
{
long msgnum = 0L;
- char *vcard;
+ StrBuf *vcard;
struct vCard *v;
char *photosrc;
const char *contentType;
msgnum = StrTol(WCC->UrlFragment2);
vcard = load_mimepart(msgnum,"1");
- v = vcard_load(vcard);
+ v = VCardLoad(vcard);
photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
FlushStrBuf(WCC->WBuf);
* titlebarmsg text to display in the title bar
* messagetext body of the box
*/
-void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
+void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext)
{
hprintf("HTTP/1.1 200 OK\n");
output_headers(1, 1, 2, 0, 0, 0);
void SetAccessCommand(long Oper);
void do_addrbook_view(addrbookent *addrbook, int num_ab);
void fetch_ab_name(message_summary *Msg, char **namebuf);
-void display_vcard(StrBuf *Target, const char *vcard_source, char alpha, int full, char **storename, long msgnum);
+void display_vcard(StrBuf *Target, StrBuf *vcard_source, char alpha, int full, char **storename, long msgnum);
void jsonMessageList(void);
void new_summary_view(void);
void getseen(void);
char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen);
long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
void remove_token(char *source, int parmnum, char separator);
-char *load_mimepart(long msgnum, char *partnum);
+StrBuf *load_mimepart(long msgnum, char *partnum);
void MimeLoadData(wc_mime_attachment *Mime);
int pattern2(char *search, char *patn);
void do_edit_vcard(long, char *, char *, const char *);
void display_addressbook(long msgnum, char alpha);
void offer_start_page(StrBuf *Target, WCTemplputParams *TP);
-void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext);
+void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext);
void output_html(const char *, int, int, StrBuf *, StrBuf *);
void do_listsub(void);
ssize_t write(int fd, const void *buf, size_t count);