51cdc8960f7d9685dc57b170cf9d22ba42f92052
[citadel.git] / webcit / notes.c
1 /*
2  * $Id$
3  *
4  * Functions which handle "sticky notes"
5  *
6  */
7
8 #include "webcit.h"
9 #include "webserver.h"
10
11 void display_note(long msgnum) {
12         char buf[SIZ];
13         char notetext[SIZ];
14         char display_notetext[SIZ];
15         int in_text = 0;
16         int i;
17
18         wprintf("<IMG ALIGN=MIDDLE src=\"static/storenotes_48x.gif\">\n");
19
20         serv_printf("MSG0 %ld", msgnum);
21         serv_getln(buf, sizeof buf);
22         if (buf[0] != '1') {
23                 wprintf("%s<br />\n", &buf[4]);
24                 return;
25         }
26
27         strcpy(notetext, "");
28         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
29
30                 /* Fill the buffer to at least 256 characters */
31                 if ( (in_text) && (strlen(notetext) < 256) ) {
32                         strcat(notetext, buf);
33                 }
34
35                 if ( (!in_text) && (!strcasecmp(buf, "text")) ) {
36                         in_text = 1;
37                 }
38         }
39
40         /* Now sanitize the buffer, and shorten it to just a small snippet */
41         for (i=0; i<strlen(notetext); ++i) {
42                 if (isspace(notetext[i])) notetext[i] = ' ';
43         }
44         strcpy(&notetext[72], "...");
45
46         /* Make it HTML-happy and print it. */
47         stresc(display_notetext, notetext, 1, 1);
48         wprintf("%s<br />\n", display_notetext);
49 }