indent -kr -i8 -brf -bbb -fnc -l132 -nce on all of webcit-classic
[citadel.git] / webcit / mailview_renderer.c
1 #include "webcit.h"
2 #include "webserver.h"
3 #include "dav.h"
4
5 static inline void CheckConvertBufs(struct wcsession *WCC) {
6         if (WCC->ConvertBuf1 == NULL)
7                 WCC->ConvertBuf1 = NewStrBuf();
8         if (WCC->ConvertBuf2 == NULL)
9                 WCC->ConvertBuf2 = NewStrBuf();
10 }
11
12 int ParseMessageListHeaders_Detail(StrBuf * Line,
13                                    const char **pos, message_summary * Msg, StrBuf * ConversionBuffer, void **ViewSpecific) {
14         wcsession *WCC = WC;
15         long len;
16         long totallen;
17
18         CheckConvertBufs(WCC);
19
20         totallen = StrLength(Line);
21         Msg->from = NewStrBufPlain(NULL, totallen);
22         len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
23         if (len > 0) {
24                 /* Handle senders with RFC2047 encoding */
25                 StrBuf_RFC822_2_Utf8(Msg->from, ConversionBuffer, WCC->DefaultCharset, NULL, WCC->ConvertBuf1, WCC->ConvertBuf2);
26         }
27
28         /* node name */
29         len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
30         if ((len > 0) && (((WCC->CurRoom.QRFlags & QR_NETWORK)
31                            || ((strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_nodename))
32                                 && (strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_fqdn)))))))) {
33                 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
34                 StrBufAppendBuf(Msg->from, ConversionBuffer, 0);
35         }
36
37         /* Internet address (not used)
38          *      StrBufExtract_token(Msg->inetaddr, Line, 4, '|');
39          */
40         StrBufSkip_NTokenS(Line, pos, '|', 1);
41         Msg->subj = NewStrBufPlain(NULL, totallen);
42
43         FlushStrBuf(ConversionBuffer);
44         /* we assume the subject is the last parameter inside of the list; 
45          * thus we don't use the tokenizer to fetch it, since it will hick up 
46          * on tokenizer chars inside of the subjects
47          StrBufExtract_NextToken(ConversionBuffer,  Line, pos, '|');
48          */
49         len = 0;
50         if (*pos != StrBufNOTNULL) {
51                 len = totallen - (*pos - ChrPtr(Line));
52                 StrBufPlain(ConversionBuffer, *pos, len);
53                 *pos = StrBufNOTNULL;
54                 if ((len > 0) && (*(ChrPtr(ConversionBuffer) + len - 1) == '|'))
55                         StrBufCutRight(ConversionBuffer, 1);
56         }
57
58         if (len == 0)
59                 StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1, 0);
60         else {
61                 StrBuf_RFC822_2_Utf8(Msg->subj, ConversionBuffer, WCC->DefaultCharset, NULL, WCC->ConvertBuf1, WCC->ConvertBuf2);
62         }
63
64         return 1;
65 }
66
67
68 int mailview_GetParamsGetServerCall(SharedMessageStatus * Stat,
69                                     void **ViewSpecific, long oper, char *cmd, long len, char *filter, long flen) {
70         DoTemplate(HKEY("msg_listview"), NULL, &NoCtx);
71
72         return 200;
73 }
74
75 int mailview_Cleanup(void **ViewSpecific) {
76         /* Note: wDumpContent() will output one additional </div> tag. */
77         /* We ought to move this out into template */
78         wDumpContent(1);
79
80         return 0;
81 }
82
83 void InitModule_MAILVIEW_RENDERERS(void) {
84         RegisterCTX(CTX_MIME_ATACH);
85         RegisterReadLoopHandlerset(VIEW_MAILBOX, mailview_GetParamsGetServerCall, NULL, /* TODO: is this right? */
86                                    NULL, ParseMessageListHeaders_Detail, NULL, NULL, mailview_Cleanup, NULL);
87
88 }