]> code.citadel.org Git - citadel.git/blobdiff - webcit/notes.c
* split tasks view into its own file
[citadel.git] / webcit / notes.c
index 988e110958d76e7930aa58f63f6662aee5d406e3..d9a50bc68791217c8ccab47a00cedde5a0b3237b 100644 (file)
@@ -41,6 +41,7 @@ struct vnote *vnote_new_from_msg(long msgnum,int unread)
        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 */
@@ -94,26 +95,29 @@ struct vnote *vnote_new_from_msg(long msgnum,int unread)
                        }
                        else {
                                phase++;
-                               
                                if ((msg4_content_length > 0)
                                    && ( !strcasecmp(msg4_content_encoding, "7bit"))
-                                   && (!strcasecmp(mime_content_type, "text/vnote"))
+                                   && (!strcasecmp(msg4_content_type, "text/vnote"))
                                ) { 
-                                       /* shouldn't we do something here? */
+                                       vnote_inline = 1;
                                }
                        }
-               //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);
+               case 2:
+                       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);
+                               }
+                       }
+               case 3:
+                       if (vnote_inline) {
+                               StrBufAppendBuf(Data, Buf, 0);
+                       }
                }
        }
        FreeStrBuf(&Buf);
@@ -121,7 +125,7 @@ struct vnote *vnote_new_from_msg(long msgnum,int unread)
        /* 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);
        }
 
@@ -157,15 +161,38 @@ void write_vnote_to_server(struct vnote *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("Content-Transfer-Encoding: 7bit");
                serv_puts("");
                pch = vnote_serialize(v);
                serv_puts(pch);
                free(pch);
+               serv_printf("--%s--", boundary);
                serv_puts("000");
        }
 }
@@ -269,13 +296,19 @@ void ajax_update_note(void) {
  *
  * msgnum = Message number on the local server of the note to be displayed
  */
-void display_note(message_summary *Msg, int unread) {
+////TODO: falscher hook
+int notes_LoadMsgFromServer(SharedMessageStatus *Stat, 
+                           void **ViewSpecific, 
+                           message_summary* Msg, 
+                           int is_new, 
+                           int i)
+{
        struct vnote *v;
        WCTemplputParams TP;
 
        memset(&TP, 0, sizeof(WCTemplputParams));
        TP.Filter.ContextType = CTX_VNOTE;
-       v = vnote_new_from_msg(Msg->msgnum, unread);
+       v = vnote_new_from_msg(Msg->msgnum, is_new);
        if (v) {
                TP.Context = v;
                DoTemplate(HKEY("vnoteitem"),
@@ -295,6 +328,7 @@ void display_note(message_summary *Msg, int unread) {
 
                vnote_free(v);
        }
+       return 0;
 }
 
 
@@ -381,10 +415,41 @@ void tmpl_vcard_put_uid(StrBuf *Target, WCTemplputParams *TP)
        StrBufAppendBufPlain(Target, v->uid, -1, 0);
 }
 
+
+
+
+int notes_GetParamsGetServerCall(SharedMessageStatus *Stat, 
+                                void **ViewSpecific, 
+                                long oper, 
+                                char *cmd, 
+                                long len)
+{
+       strcpy(cmd, "MSGS ALL");
+       Stat->maxmsgs = 32767;
+       wprintf("<div id=\"new_notes_here\"></div>\n");
+       return 200;
+
+}
+
+int notes_Cleanup(void **ViewSpecific)
+{
+       end_burst();
+       return 0;
+}
+
+
 void 
 InitModule_NOTES
 (void)
 {
+       RegisterReadLoopHandlerset(
+               VIEW_NOTES,
+               notes_GetParamsGetServerCall,
+               NULL,
+               notes_LoadMsgFromServer,
+               NULL,
+               notes_Cleanup);
+
        WebcitAddUrlHandler(HKEY("add_new_note"), add_new_note, 0);
        WebcitAddUrlHandler(HKEY("ajax_update_note"), ajax_update_note, 0);