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