e1fb6ecdc8eb981a4628fd908f6e371cc914e3fb
[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 {
7         if (WCC->ConvertBuf1 == NULL)
8                 WCC->ConvertBuf1 = NewStrBuf();
9         if (WCC->ConvertBuf2 == NULL)
10                 WCC->ConvertBuf2 = NewStrBuf();
11 }
12
13 int ParseMessageListHeaders_Detail(StrBuf *Line, 
14                                    const char **pos, 
15                                    message_summary *Msg, 
16                                    StrBuf *ConversionBuffer)
17 {
18         wcsession *WCC = WC;
19         long len;
20         long totallen;
21
22         CheckConvertBufs(WCC);
23
24         totallen = StrLength(Line);
25         Msg->from = NewStrBufPlain(NULL, totallen);
26         len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
27         if (len > 0) {
28                 /* Handle senders with RFC2047 encoding */
29                 StrBuf_RFC822_2_Utf8(Msg->from, 
30                                      ConversionBuffer, 
31                                      WCC->DefaultCharset, 
32                                      NULL, 
33                                      WCC->ConvertBuf1,
34                                      WCC->ConvertBuf2);
35         }
36                         
37         /* node name */
38         len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
39         if ((len > 0 ) &&
40             ( ((WCC->CurRoom.QRFlags & QR_NETWORK)
41                || ((strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_nodename))
42                     && (strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_fqdn))))))))
43         {
44                 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
45                 StrBufAppendBuf(Msg->from, ConversionBuffer, 0);
46         }
47
48         /* Internet address (not used)
49          *      StrBufExtract_token(Msg->inetaddr, Line, 4, '|');
50          */
51         StrBufSkip_NTokenS(Line, pos, '|', 1);
52         Msg->subj = NewStrBufPlain(NULL, totallen);
53
54         FlushStrBuf(ConversionBuffer);
55         /* we assume the subject is the last parameter inside of the list; 
56          * thus we don't use the tokenizer to fetch it, since it will hick up 
57          * on tokenizer chars inside of the subjects
58         StrBufExtract_NextToken(ConversionBuffer,  Line, pos, '|');
59         */
60         len = 0;
61         if (*pos != StrBufNOTNULL) {
62                 len = totallen - (*pos - ChrPtr(Line));
63                 StrBufPlain(ConversionBuffer, *pos, len);
64                 *pos = StrBufNOTNULL;
65                 if ((len > 0) &&
66                     (*(ChrPtr(ConversionBuffer) + len - 1) == '|'))
67                         StrBufCutRight(ConversionBuffer, 1);
68         }
69
70         if (len == 0)
71                 StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0);
72         else {
73                 StrBuf_RFC822_2_Utf8(Msg->subj, 
74                                      ConversionBuffer, 
75                                      WCC->DefaultCharset, 
76                                      NULL,
77                                      WCC->ConvertBuf1,
78                                      WCC->ConvertBuf2);
79         }
80
81         return 1;
82 }
83
84
85 int mailview_GetParamsGetServerCall(SharedMessageStatus *Stat, 
86                                     void **ViewSpecific, 
87                                     long oper, 
88                                     char *cmd, 
89                                     long len,
90                                     char *filter,
91                                     long flen)
92 {
93         DoTemplate(HKEY("msg_listview"),NULL,&NoCtx);
94
95         return 200;
96 }
97
98 int mailview_Cleanup(void **ViewSpecific)
99 {
100         /* Note: wDumpContent() will output one additional </div> tag. */
101         /* We ought to move this out into template */
102         wDumpContent(1);
103
104         return 0;
105 }
106
107 void 
108 InitModule_MAILVIEW_RENDERERS
109 (void)
110 {
111         RegisterCTX(CTX_MIME_ATACH);
112         RegisterReadLoopHandlerset(
113                 VIEW_MAILBOX,
114                 mailview_GetParamsGetServerCall,
115                 NULL, /* TODO: is this right? */
116                 NULL,
117                 ParseMessageListHeaders_Detail,
118                 NULL,
119                 NULL,
120                 mailview_Cleanup);
121
122 }