struct vnote *vnote_new_from_msg(long msgnum,int unread)
{
StrBuf *Buf;
- StrBuf *Data;
+ StrBuf *Data = NULL;
const char *bptr;
int Done = 0;
- char from[128] = "";
char uid_from_headers[256];
char mime_partnum[256];
char mime_filename[256];
char msg4_content_encoding[256] = "";
int msg4_content_length = 0;
struct vnote *vnote_from_body = NULL;
+ int vnote_inline = 0; /* 1 = MSG4 gave us a text/x-vnote top level */
relevant_partnum[0] = '\0';
serv_printf("MSG4 %ld", msgnum); /* we need the mime headers */
Buf = NewStrBuf();
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) != 1) {
FreeStrBuf (&Buf);
return NULL;
}
- while ((StrBuf_ServGetlnBuffered(Buf)>=0) && !Done) {
+ while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
if ( (StrLength(Buf)==3) &&
!strcmp(ChrPtr(Buf), "000")) {
Done = 1;
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"))
- ) {
+ if (!strcasecmp(mime_content_type, "text/vnote")) {
strcpy(relevant_partnum, mime_partnum);
}
}
- else if (!strncasecmp(bptr, "from=", 4)) {
- extract_token(from, bptr, 1, '=', sizeof(from));
- }
else if ((phase == 0) && (!strncasecmp(bptr, "text", 4))) {
phase = 1;
}
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"))
- )
- )
- {
+ && (!strcasecmp(mime_content_type, "text/vnote"))
+ ) {
+ vnote_inline = 1;
}
}
case 2:
- Data = NewStrBufPlain(NULL, msg4_content_length * 2);
- if (msg4_content_length > 0) {
- StrBuf_ServGetBLOBBuffered(Data, msg4_content_length);
- phase ++;
+ if (vnote_inline) {
+ 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);
+ }
}
- else {
+ case 3:
+ if (vnote_inline) {
StrBufAppendBuf(Data, Buf, 0);
- StrBufAppendBufPlain(Data, "\r\n", 1, 0);
}
- case 3:
- StrBufAppendBuf(Data, Buf, 0);
}
}
FreeStrBuf(&Buf);
/* 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))) {
+ if ((!vnote_inline) && (!IsEmptyStr(relevant_partnum))) {
Data = load_mimepart(msgnum, relevant_partnum);
}
-
- if ((IsEmptyStr(relevant_partnum)) && (StrLength(Data) > 0 )) {
- if (!IsEmptyStr(uid_from_headers)) {
+ if (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->body = malloc(StrLength(Data) + 1);
vnote_from_body->body[0] = 0;
memcpy(vnote_from_body->body, ChrPtr(Data), StrLength(Data) + 1);
+ FreeStrBuf(&Data);
return vnote_from_body;
}
else {
struct vnote *v = vnote_new_from_str(ChrPtr(Data));
+ FreeStrBuf(&Data);
return(v);
}
}
{
char buf[1024];
char *pch;
+ char boundary[256];
+ static int seq = 0;
+
+ snprintf(boundary, sizeof boundary, "Citadel--Multipart--%s--%04x--%04x",
+ ChrPtr(WC->serv_info->serv_fqdn),
+ getpid(),
+ ++seq
+ );
serv_puts("ENT0 1|||4");
serv_getln(buf, sizeof buf);
if (buf[0] == '4') {
+ /* Remember, serv_printf() appends an extra newline */
+ serv_printf("Content-type: multipart/alternative; "
+ "boundary=\"%s\"\n", boundary);
+ serv_printf("This is a multipart message in MIME format.\n");
+ serv_printf("--%s", boundary);
+
+ serv_puts("Content-type: text/plain; charset=utf-8");
+ serv_puts("Content-Transfer-Encoding: 7bit");
+ serv_puts("");
+ serv_puts(v->body);
+ serv_puts("");
+
+ serv_printf("--%s", boundary);
serv_puts("Content-type: text/vnote");
serv_puts("");
pch = vnote_serialize(v);
serv_puts(pch);
free(pch);
+ serv_printf("--%s--", boundary);
serv_puts("000");
}
}