10 int pastel_palette[9][3] = {
24 * Fetch a message from the server and extract a vNote from it
26 struct vnote *vnote_new_from_msg(long msgnum,int unread)
32 char uid_from_headers[256];
33 char mime_partnum[256];
34 char mime_filename[256];
35 char mime_content_type[256];
36 char mime_disposition[256];
38 char relevant_partnum[256];
39 int phase = 0; /* 0 = citadel headers, 1 = mime headers, 2 = body */
40 char msg4_content_type[256] = "";
41 char msg4_content_encoding[256] = "";
42 int msg4_content_length = 0;
43 struct vnote *vnote_from_body = NULL;
44 int vnote_inline = 0; /* 1 = MSG4 gave us a text/x-vnote top level */
46 relevant_partnum[0] = '\0';
47 serv_printf("MSG4 %ld", msgnum); /* we need the mime headers */
49 StrBuf_ServGetln(Buf);
50 if (GetServerStatus(Buf, NULL) != 1) {
54 while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
55 if ( (StrLength(Buf)==3) &&
56 !strcmp(ChrPtr(Buf), "000")) {
63 if (!strncasecmp(bptr, "exti=", 5)) {
64 safestrncpy(uid_from_headers, &(ChrPtr(Buf)[5]), sizeof uid_from_headers);
66 else if (!strncasecmp(bptr, "part=", 5)) {
67 extract_token(mime_filename, &bptr[5], 1, '|', sizeof mime_filename);
68 extract_token(mime_partnum, &bptr[5], 2, '|', sizeof mime_partnum);
69 extract_token(mime_disposition, &bptr[5], 3, '|', sizeof mime_disposition);
70 extract_token(mime_content_type, &bptr[5], 4, '|', sizeof mime_content_type);
71 mime_length = extract_int(&bptr[5], 5);
73 if (!strcasecmp(mime_content_type, "text/vnote")) {
74 strcpy(relevant_partnum, mime_partnum);
77 else if ((phase == 0) && (!strncasecmp(bptr, "text", 4))) {
82 if (!IsEmptyStr(bptr)) {
83 if (!strncasecmp(bptr, "Content-type: ", 14)) {
84 safestrncpy(msg4_content_type, &bptr[14], sizeof msg4_content_type);
85 striplt(msg4_content_type);
87 else if (!strncasecmp(bptr, "Content-transfer-encoding: ", 27)) {
88 safestrncpy(msg4_content_encoding, &bptr[27], sizeof msg4_content_encoding);
89 striplt(msg4_content_type);
91 else if ((!strncasecmp(bptr, "Content-length: ", 16))) {
92 msg4_content_length = atoi(&bptr[16]);
98 if ((msg4_content_length > 0)
99 && ( !strcasecmp(msg4_content_encoding, "7bit"))
100 && (!strcasecmp(msg4_content_type, "text/vnote"))
107 Data = NewStrBufPlain(NULL, msg4_content_length * 2);
108 if (msg4_content_length > 0) {
109 StrBuf_ServGetBLOBBuffered(Data, msg4_content_length);
113 StrBufAppendBuf(Data, Buf, 0);
114 StrBufAppendBufPlain(Data, "\r\n", 1, 0);
119 StrBufAppendBuf(Data, Buf, 0);
125 /* If MSG4 didn't give us the part we wanted, but we know that we can find it
126 * as one of the other MIME parts, attempt to load it now.
128 if ((!vnote_inline) && (!IsEmptyStr(relevant_partnum))) {
129 Data = load_mimepart(msgnum, relevant_partnum);
132 if (StrLength(Data) > 0) {
133 if (IsEmptyStr(uid_from_headers)) {
134 /* Convert an old-style note to a vNote */
135 vnote_from_body = vnote_new();
136 vnote_from_body->uid = strdup(uid_from_headers);
137 vnote_from_body->color_red = pastel_palette[3][0];
138 vnote_from_body->color_green = pastel_palette[3][1];
139 vnote_from_body->color_blue = pastel_palette[3][2];
140 vnote_from_body->body = malloc(StrLength(Data) + 1);
141 vnote_from_body->body[0] = 0;
142 memcpy(vnote_from_body->body, ChrPtr(Data), StrLength(Data) + 1);
144 return vnote_from_body;
147 char *Buf = SmashStrBuf(&Data);
149 struct vnote *v = vnote_new_from_str(Buf);
160 * Serialize a vnote and write it to the server
162 void write_vnote_to_server(struct vnote *v)
169 snprintf(boundary, sizeof boundary, "Citadel--Multipart--%s--%04x--%04x",
170 ChrPtr(WC->serv_info->serv_fqdn),
175 serv_puts("ENT0 1|||4");
176 serv_getln(buf, sizeof buf);
178 /* Remember, serv_printf() appends an extra newline */
179 serv_printf("Content-type: multipart/alternative; "
180 "boundary=\"%s\"\n", boundary);
181 serv_printf("This is a multipart message in MIME format.\n");
182 serv_printf("--%s", boundary);
184 serv_puts("Content-type: text/plain; charset=utf-8");
185 serv_puts("Content-Transfer-Encoding: 7bit");
190 serv_printf("--%s", boundary);
191 serv_puts("Content-type: text/vnote");
192 serv_puts("Content-Transfer-Encoding: 7bit");
194 pch = vnote_serialize(v);
197 serv_printf("--%s--", boundary);
206 * Background ajax call to receive updates from the browser when a note is moved, resized, or updated.
208 void ajax_update_note(void) {
212 struct vnote *v = NULL;
214 if (!havebstr("note_uid")) {
215 begin_ajax_response();
216 wc_printf("Received ajax_update_note() request without a note UID.");
221 serv_printf("EUID %s", bstr("note_uid"));
222 serv_getln(buf, sizeof buf);
224 begin_ajax_response();
225 wc_printf("Cannot find message containing vNote with the requested uid!");
229 msgnum = atol(&buf[4]);
231 /* Was this request a delete operation? If so, nuke it... */
232 if (havebstr("deletenote")) {
233 if (!strcasecmp(bstr("deletenote"), "yes")) {
234 serv_printf("DELE %d", msgnum);
235 serv_getln(buf, sizeof buf);
236 begin_ajax_response();
237 wc_printf("%s", buf);
243 /* If we get to this point it's an update, not a delete */
244 v = vnote_new_from_msg(msgnum, 0);
246 begin_ajax_response();
247 wc_printf("Cannot locate a vNote within message %d\n", msgnum);
252 /* Make any requested changes */
253 if (havebstr("top")) {
254 v->pos_top = atoi(bstr("top"));
256 if (havebstr("left")) {
257 v->pos_left = atoi(bstr("left"));
259 if (havebstr("height")) {
260 v->pos_height = atoi(bstr("height"));
262 if (havebstr("width")) {
263 v->pos_width = atoi(bstr("width"));
265 if (havebstr("red")) {
266 v->color_red = atoi(bstr("red"));
268 if (havebstr("green")) {
269 v->color_green = atoi(bstr("green"));
271 if (havebstr("blue")) {
272 v->color_blue = atoi(bstr("blue"));
274 if (havebstr("value")) { /* I would have preferred 'body' but InPlaceEditor hardcodes 'value' */
275 if (v->body) free(v->body);
276 v->body = strdup(bstr("value"));
279 /* Serialize it and save it to the message base. Server will delete the old one. */
280 write_vnote_to_server(v);
282 begin_ajax_response();
295 * display sticky notes
297 * msgnum = Message number on the local server of the note to be displayed
299 ////TODO: falscher hook
300 int notes_LoadMsgFromServer(SharedMessageStatus *Stat,
302 message_summary* Msg,
309 memset(&TP, 0, sizeof(WCTemplputParams));
310 TP.Filter.ContextType = CTX_VNOTE;
311 v = vnote_new_from_msg(Msg->msgnum, is_new);
314 DoTemplate(HKEY("vnoteitem"),
318 /* uncomment these lines to see ugly debugging info
319 StrBufAppendPrintf(WC->trailing_javascript,
320 "document.write('L: ' + $('note-%s').style.left + '; ');", v->uid);
321 StrBufAppendPrintf(WC->trailing_javascript,
322 "document.write('T: ' + $('note-%s').style.top + '; ');", v->uid);
323 StrBufAppendPrintf(WC->trailing_javascript,
324 "document.write('W: ' + $('note-%s').style.width + '; ');", v->uid);
325 StrBufAppendPrintf(WC->trailing_javascript,
326 "document.write('H: ' + $('note-%s').style.height + '<br>');", v->uid);
339 void add_new_note(void) {
344 v->uid = malloc(128);
345 generate_uuid(v->uid);
346 v->color_red = pastel_palette[3][0];
347 v->color_green = pastel_palette[3][1];
348 v->color_blue = pastel_palette[3][2];
349 v->body = strdup(_("Click on any note to edit it."));
350 write_vnote_to_server(v);
354 readloop(readfwd, eUseDefault);
358 void tmpl_vcard_put_posleft(StrBuf *Target, WCTemplputParams *TP)
360 struct vnote *v = (struct vnote *) CTX;
361 StrBufAppendPrintf(Target, "%d", v->pos_left);
364 void tmpl_vcard_put_postop(StrBuf *Target, WCTemplputParams *TP)
366 struct vnote *v = (struct vnote *) CTX;
367 StrBufAppendPrintf(Target, "%d", v->pos_top);
370 void tmpl_vcard_put_poswidth(StrBuf *Target, WCTemplputParams *TP)
372 struct vnote *v = (struct vnote *) CTX;
373 StrBufAppendPrintf(Target, "%d", v->pos_width);
376 void tmpl_vcard_put_posheight(StrBuf *Target, WCTemplputParams *TP)
378 struct vnote *v = (struct vnote *) CTX;
379 StrBufAppendPrintf(Target, "%d", v->pos_height);
382 void tmpl_vcard_put_posheight2(StrBuf *Target, WCTemplputParams *TP)
384 struct vnote *v = (struct vnote *) CTX;
385 StrBufAppendPrintf(Target, "%d", (v->pos_height / 16) - 5);
388 void tmpl_vcard_put_width2(StrBuf *Target, WCTemplputParams *TP)
390 struct vnote *v = (struct vnote *) CTX;
391 StrBufAppendPrintf(Target, "%d", (v->pos_width / 9) - 1);
394 void tmpl_vcard_put_color(StrBuf *Target, WCTemplputParams *TP)
396 struct vnote *v = (struct vnote *) CTX;
397 StrBufAppendPrintf(Target, "%02X%02X%02X", v->color_red, v->color_green, v->color_blue);
400 void tmpl_vcard_put_bgcolor(StrBuf *Target, WCTemplputParams *TP)
402 struct vnote *v = (struct vnote *) CTX;
403 StrBufAppendPrintf(Target, "%02X%02X%02X", v->color_red/2, v->color_green/2, v->color_blue/2);
406 void tmpl_vcard_put_message(StrBuf *Target, WCTemplputParams *TP)
408 struct vnote *v = (struct vnote *) CTX;
409 StrEscAppend(Target, NULL, v->body, 0, 0); ///TODO?
412 void tmpl_vcard_put_uid(StrBuf *Target, WCTemplputParams *TP)
414 struct vnote *v = (struct vnote *) CTX;
415 StrBufAppendBufPlain(Target, v->uid, -1, 0);
421 int notes_GetParamsGetServerCall(SharedMessageStatus *Stat,
427 strcpy(cmd, "MSGS ALL");
428 Stat->maxmsgs = 32767;
429 wc_printf("<div id=\"new_notes_here\"></div>\n");
434 int notes_Cleanup(void **ViewSpecific)
445 RegisterReadLoopHandlerset(
447 notes_GetParamsGetServerCall,
450 notes_LoadMsgFromServer,
454 WebcitAddUrlHandler(HKEY("add_new_note"), "", 0, add_new_note, 0);
455 WebcitAddUrlHandler(HKEY("ajax_update_note"), "", 0, ajax_update_note, 0);
457 RegisterNamespace("VNOTE:POS:LEFT", 0, 0, tmpl_vcard_put_posleft, NULL, CTX_VNOTE);
458 RegisterNamespace("VNOTE:POS:TOP", 0, 0, tmpl_vcard_put_postop, NULL, CTX_VNOTE);
459 RegisterNamespace("VNOTE:POS:WIDTH", 0, 0, tmpl_vcard_put_poswidth, NULL, CTX_VNOTE);
460 RegisterNamespace("VNOTE:POS:HEIGHT", 0, 0, tmpl_vcard_put_posheight, NULL, CTX_VNOTE);
461 RegisterNamespace("VNOTE:POS:HEIGHT2", 0, 0, tmpl_vcard_put_posheight2, NULL, CTX_VNOTE);
462 RegisterNamespace("VNOTE:POS:WIDTH2", 0, 0, tmpl_vcard_put_width2, NULL, CTX_VNOTE);
463 RegisterNamespace("VNOTE:COLOR", 0, 0, tmpl_vcard_put_color, NULL, CTX_VNOTE);
464 RegisterNamespace("VNOTE:BGCOLOR", 0, 0,tmpl_vcard_put_bgcolor, NULL, CTX_VNOTE);
465 RegisterNamespace("VNOTE:MSG", 0, 1, tmpl_vcard_put_message, NULL, CTX_VNOTE);
466 RegisterNamespace("VNOTE:UID", 0, 0, tmpl_vcard_put_uid, NULL, CTX_VNOTE);