6 int pastel_palette[9][3] = {
20 * Fetch a message from the server and extract a vNote from it
22 struct vnote *vnote_new_from_msg(long msgnum,int unread)
28 char uid_from_headers[256];
29 char mime_partnum[256];
30 char mime_filename[256];
31 char mime_content_type[256];
32 char mime_disposition[256];
33 char relevant_partnum[256];
34 int phase = 0; /* 0 = citadel headers, 1 = mime headers, 2 = body */
35 char msg4_content_type[256] = "";
36 char msg4_content_encoding[256] = "";
37 int msg4_content_length = 0;
38 struct vnote *vnote_from_body = NULL;
39 int vnote_inline = 0; /* 1 = MSG4 gave us a text/x-vnote top level */
41 relevant_partnum[0] = '\0';
42 serv_printf("MSG4 %ld", msgnum); /* we need the mime headers */
44 StrBuf_ServGetln(Buf);
45 if (GetServerStatus(Buf, NULL) != 1) {
49 while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
50 if ( (StrLength(Buf)==3) &&
51 !strcmp(ChrPtr(Buf), "000")) {
58 if (!strncasecmp(bptr, "exti=", 5)) {
59 safestrncpy(uid_from_headers, &(ChrPtr(Buf)[5]), sizeof uid_from_headers);
61 else if (!strncasecmp(bptr, "part=", 5)) {
62 extract_token(mime_filename, &bptr[5], 1, '|', sizeof mime_filename);
63 extract_token(mime_partnum, &bptr[5], 2, '|', sizeof mime_partnum);
64 extract_token(mime_disposition, &bptr[5], 3, '|', sizeof mime_disposition);
65 extract_token(mime_content_type, &bptr[5], 4, '|', sizeof mime_content_type);
67 if (!strcasecmp(mime_content_type, "text/vnote")) {
68 strcpy(relevant_partnum, mime_partnum);
71 else if ((phase == 0) && (!strncasecmp(bptr, "text", 4))) {
76 if (!IsEmptyStr(bptr)) {
77 if (!strncasecmp(bptr, "Content-type: ", 14)) {
78 safestrncpy(msg4_content_type, &bptr[14], sizeof msg4_content_type);
79 striplt(msg4_content_type);
81 else if (!strncasecmp(bptr, "Content-transfer-encoding: ", 27)) {
82 safestrncpy(msg4_content_encoding, &bptr[27], sizeof msg4_content_encoding);
83 striplt(msg4_content_type);
85 else if ((!strncasecmp(bptr, "Content-length: ", 16))) {
86 msg4_content_length = atoi(&bptr[16]);
92 if ((msg4_content_length > 0)
93 && ( !strcasecmp(msg4_content_encoding, "7bit"))
94 && (!strcasecmp(msg4_content_type, "text/vnote"))
101 Data = NewStrBufPlain(NULL, msg4_content_length * 2);
102 if (msg4_content_length > 0) {
103 StrBuf_ServGetBLOBBuffered(Data, msg4_content_length);
107 StrBufAppendBuf(Data, Buf, 0);
108 StrBufAppendBufPlain(Data, "\r\n", 1, 0);
113 StrBufAppendBuf(Data, Buf, 0);
119 /* If MSG4 didn't give us the part we wanted, but we know that we can find it
120 * as one of the other MIME parts, attempt to load it now.
122 if ((!vnote_inline) && (!IsEmptyStr(relevant_partnum))) {
123 Data = load_mimepart(msgnum, relevant_partnum);
126 if (StrLength(Data) > 0) {
127 if (IsEmptyStr(uid_from_headers)) {
128 /* Convert an old-style note to a vNote */
129 vnote_from_body = vnote_new();
130 vnote_from_body->uid = strdup(uid_from_headers);
131 vnote_from_body->color_red = pastel_palette[3][0];
132 vnote_from_body->color_green = pastel_palette[3][1];
133 vnote_from_body->color_blue = pastel_palette[3][2];
134 vnote_from_body->body = malloc(StrLength(Data) + 1);
135 vnote_from_body->body[0] = 0;
136 memcpy(vnote_from_body->body, ChrPtr(Data), StrLength(Data) + 1);
138 return vnote_from_body;
141 char *Buf = SmashStrBuf(&Data);
143 struct vnote *v = vnote_new_from_str(Buf);
154 * Serialize a vnote and write it to the server
156 void write_vnote_to_server(struct vnote *v)
163 snprintf(boundary, sizeof boundary, "Citadel--Multipart--%s--%04x--%04x",
164 ChrPtr(WC->serv_info->serv_fqdn),
169 serv_puts("ENT0 1|||4");
170 serv_getln(buf, sizeof buf);
172 /* Remember, serv_printf() appends an extra newline */
173 serv_printf("Content-type: multipart/alternative; "
174 "boundary=\"%s\"\n", boundary);
175 serv_printf("This is a multipart message in MIME format.\n");
176 serv_printf("--%s", boundary);
178 serv_puts("Content-type: text/plain; charset=utf-8");
179 serv_puts("Content-Transfer-Encoding: 7bit");
184 serv_printf("--%s", boundary);
185 serv_puts("Content-type: text/vnote");
186 serv_puts("Content-Transfer-Encoding: 7bit");
188 pch = vnote_serialize(v);
191 serv_printf("--%s--", boundary);
200 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
202 void ajax_update_note(void) {
206 struct vnote *v = NULL;
208 if (!havebstr("note_uid")) {
209 begin_ajax_response();
210 wc_printf("Received ajax_update_note() request without a note UID.");
215 serv_printf("EUID %s", bstr("note_uid"));
216 serv_getln(buf, sizeof buf);
218 begin_ajax_response();
219 wc_printf("Cannot find message containing vNote with the requested uid!");
223 msgnum = atol(&buf[4]);
225 /* Was this request a delete operation? If so, nuke it... */
226 if (havebstr("deletenote")) {
227 if (!strcasecmp(bstr("deletenote"), "yes")) {
228 serv_printf("DELE %d", msgnum);
229 serv_getln(buf, sizeof buf);
230 begin_ajax_response();
231 wc_printf("%s", buf);
237 /* If we get to this point it's an update, not a delete */
238 v = vnote_new_from_msg(msgnum, 0);
240 begin_ajax_response();
241 wc_printf("Cannot locate a vNote within message %d\n", msgnum);
246 /* Make any requested changes */
247 if (havebstr("top")) {
248 v->pos_top = atoi(bstr("top"));
250 if (havebstr("left")) {
251 v->pos_left = atoi(bstr("left"));
253 if (havebstr("height")) {
254 v->pos_height = atoi(bstr("height"));
256 if (havebstr("width")) {
257 v->pos_width = atoi(bstr("width"));
259 if (havebstr("red")) {
260 v->color_red = atoi(bstr("red"));
262 if (havebstr("green")) {
263 v->color_green = atoi(bstr("green"));
265 if (havebstr("blue")) {
266 v->color_blue = atoi(bstr("blue"));
268 if (havebstr("value")) { /* I would have preferred 'body' but InPlaceEditor hardcodes 'value' */
269 if (v->body) free(v->body);
270 v->body = strdup(bstr("value"));
273 /* Serialize it and save it to the message base. Server will delete the old one. */
274 write_vnote_to_server(v);
276 begin_ajax_response();
289 * display sticky notes
291 * msgnum = Message number on the local server of the note to be displayed
293 /*TODO: wrong hook */
294 int notes_LoadMsgFromServer(SharedMessageStatus *Stat,
296 message_summary* Msg,
303 memset(&TP, 0, sizeof(WCTemplputParams));
304 TP.Filter.ContextType = CTX_VNOTE;
305 v = vnote_new_from_msg(Msg->msgnum, is_new);
308 DoTemplate(HKEY("vnoteitem"),
312 /* uncomment these lines to see ugly debugging info
313 StrBufAppendPrintf(WC->trailing_javascript,
314 "document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
315 StrBufAppendPrintf(WC->trailing_javascript,
316 "document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
317 StrBufAppendPrintf(WC->trailing_javascript,
318 "document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
319 StrBufAppendPrintf(WC->trailing_javascript,
320 "document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
333 void add_new_note(void) {
338 v->uid = malloc(128);
339 generate_uuid(v->uid);
340 v->color_red = pastel_palette[3][0];
341 v->color_green = pastel_palette[3][1];
342 v->color_blue = pastel_palette[3][2];
343 v->body = strdup(_("Click on any note to edit it."));
344 write_vnote_to_server(v);
348 readloop(readfwd, eUseDefault);
352 void tmpl_vcard_put_posleft(StrBuf *Target, WCTemplputParams *TP)
354 struct vnote *v = (struct vnote *) CTX;
355 StrBufAppendPrintf(Target, "%d", v->pos_left);
358 void tmpl_vcard_put_postop(StrBuf *Target, WCTemplputParams *TP)
360 struct vnote *v = (struct vnote *) CTX;
361 StrBufAppendPrintf(Target, "%d", v->pos_top);
364 void tmpl_vcard_put_poswidth(StrBuf *Target, WCTemplputParams *TP)
366 struct vnote *v = (struct vnote *) CTX;
367 StrBufAppendPrintf(Target, "%d", v->pos_width);
370 void tmpl_vcard_put_posheight(StrBuf *Target, WCTemplputParams *TP)
372 struct vnote *v = (struct vnote *) CTX;
373 StrBufAppendPrintf(Target, "%d", v->pos_height);
376 void tmpl_vcard_put_posheight2(StrBuf *Target, WCTemplputParams *TP)
378 struct vnote *v = (struct vnote *) CTX;
379 StrBufAppendPrintf(Target, "%d", (v->pos_height / 16) - 5);
382 void tmpl_vcard_put_width2(StrBuf *Target, WCTemplputParams *TP)
384 struct vnote *v = (struct vnote *) CTX;
385 StrBufAppendPrintf(Target, "%d", (v->pos_width / 9) - 1);
388 void tmpl_vcard_put_color(StrBuf *Target, WCTemplputParams *TP)
390 struct vnote *v = (struct vnote *) CTX;
391 StrBufAppendPrintf(Target, "%02X%02X%02X", v->color_red, v->color_green, v->color_blue);
394 void tmpl_vcard_put_bgcolor(StrBuf *Target, WCTemplputParams *TP)
396 struct vnote *v = (struct vnote *) CTX;
397 StrBufAppendPrintf(Target, "%02X%02X%02X", v->color_red/2, v->color_green/2, v->color_blue/2);
400 void tmpl_vcard_put_message(StrBuf *Target, WCTemplputParams *TP)
402 struct vnote *v = (struct vnote *) CTX;
403 StrEscAppend(Target, NULL, v->body, 0, 0); /*TODO?*/
406 void tmpl_vcard_put_uid(StrBuf *Target, WCTemplputParams *TP)
408 struct vnote *v = (struct vnote *) CTX;
409 StrBufAppendBufPlain(Target, v->uid, -1, 0);
415 int notes_GetParamsGetServerCall(SharedMessageStatus *Stat,
423 strcpy(cmd, "MSGS ALL");
424 Stat->maxmsgs = 32767;
425 wc_printf("<div id=\"new_notes_here\"></div>\n");
430 int notes_Cleanup(void **ViewSpecific)
441 RegisterReadLoopHandlerset(
443 notes_GetParamsGetServerCall,
447 notes_LoadMsgFromServer,
451 WebcitAddUrlHandler(HKEY("add_new_note"), "", 0, add_new_note, 0);
452 WebcitAddUrlHandler(HKEY("ajax_update_note"), "", 0, ajax_update_note, 0);
454 RegisterNamespace("VNOTE:POS:LEFT", 0, 0, tmpl_vcard_put_posleft, NULL, CTX_VNOTE);
455 RegisterNamespace("VNOTE:POS:TOP", 0, 0, tmpl_vcard_put_postop, NULL, CTX_VNOTE);
456 RegisterNamespace("VNOTE:POS:WIDTH", 0, 0, tmpl_vcard_put_poswidth, NULL, CTX_VNOTE);
457 RegisterNamespace("VNOTE:POS:HEIGHT", 0, 0, tmpl_vcard_put_posheight, NULL, CTX_VNOTE);
458 RegisterNamespace("VNOTE:POS:HEIGHT2", 0, 0, tmpl_vcard_put_posheight2, NULL, CTX_VNOTE);
459 RegisterNamespace("VNOTE:POS:WIDTH2", 0, 0, tmpl_vcard_put_width2, NULL, CTX_VNOTE);
460 RegisterNamespace("VNOTE:COLOR", 0, 0, tmpl_vcard_put_color, NULL, CTX_VNOTE);
461 RegisterNamespace("VNOTE:BGCOLOR", 0, 0,tmpl_vcard_put_bgcolor, NULL, CTX_VNOTE);
462 RegisterNamespace("VNOTE:MSG", 0, 1, tmpl_vcard_put_message, NULL, CTX_VNOTE);
463 RegisterNamespace("VNOTE:UID", 0, 0, tmpl_vcard_put_uid, NULL, CTX_VNOTE);