e8ba1a3f7afc67fa9eaf3e2bd213c3f2074d5cb7
[citadel.git] / webcit / messages.h
1 extern CtxType CTX_MAILSUM;
2 extern CtxType CTX_MIME_ATACH;
3 extern HashList *MsgHeaderHandler;
4 extern HashList *MimeRenderHandler;
5 extern HashList *ReadLoopHandler;
6 typedef struct wc_mime_attachment wc_mime_attachment;
7 typedef void (*RenderMimeFunc)(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset);
8 typedef struct _RenderMimeFuncStruct {
9         RenderMimeFunc f;
10 } RenderMimeFuncStruct;
11
12 struct wc_mime_attachment {
13         int level;
14         StrBuf *Name;
15         StrBuf *FileName;
16         StrBuf *PartNum;
17         StrBuf *Disposition;
18         StrBuf *ContentType;
19         StrBuf *Charset;
20         StrBuf *Data;
21         size_t length;          /* length of the mimeattachment */
22         long size_known;
23         long lvalue;            /* if we put a long... */
24         long msgnum;            /* the message number on the citadel server derived from message_summary */
25         const RenderMimeFuncStruct *Renderer;
26 };
27 void DestroyMime(void *vMime);
28
29 #define MSGFLAG_READ (1<<0)
30
31 typedef struct _message_summary {
32         long msgnum;            /* the message number on the citadel server */
33         int Flags;
34
35         time_t date;            /* its creation date */
36         int nhdr;
37         int format_type;
38         StrBuf *euid;
39         StrBuf *from;           /* the author */
40         StrBuf *to;             /* the recipient */
41         StrBuf *subj;           /* the title / subject */
42         StrBuf *reply_inreplyto;
43         StrBuf *reply_references;
44         StrBuf *ReplyTo;
45         StrBuf *cccc;
46         StrBuf *hnod;
47         StrBuf *AllRcpt;
48         StrBuf *Room;
49         StrBuf *Rfca;
50         StrBuf *OtherNode;
51         const StrBuf *PartNum;
52
53         HashList *Attachments;  /* list of attachments */
54         HashList *Submessages;
55         HashList *AttachLinks;
56
57         HashList *AllAttach;
58
59         int hasattachments;
60
61
62         /* The mime part of the message */
63         wc_mime_attachment *MsgBody;
64 } message_summary;
65 void DestroyMessageSummary(void *vMsg);
66
67
68
69 static inline message_summary* GetMessagePtrAt(int n, HashList *Summ)
70 {
71         const char *Key;
72         long HKLen;
73         void *vMsg;
74
75         if (Summ == NULL)
76                 return NULL;
77         GetHashAt(Summ, n, &HKLen, &Key, &vMsg);
78         return (message_summary*) vMsg;
79 }
80
81 typedef void (*ExamineMsgHeaderFunc)(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset);
82
83 void evaluate_mime_part(StrBuf *Target, WCTemplputParams *TP);
84
85
86 typedef enum _eCustomRoomRenderer {
87         eUseDefault = VIEW_JOURNAL + 100, 
88         eReadEUIDS
89 }eCustomRoomRenderer;
90
91 enum {
92         do_search,
93         headers,
94         readfwd,
95         readnew,
96         readold,
97         readgt,
98         readlt
99 };
100
101 /**
102  * @brief function to parse the | separated message headers list
103  * @param Line the raw line with your message data
104  * @param Msg put your parser results here...
105  * @param ConversionBuffer if you need some workbuffer, don't free me!
106  * @returns 0: failure, trash this message. 1: all right, store it
107  */
108 typedef int (*load_msg_ptrs_detailheaders) (StrBuf *Line, 
109                                             const char **pos, 
110                                             message_summary *Msg, 
111                                             StrBuf *ConversionBuffer);
112
113 typedef void (*readloop_servcmd)(char *buf, long bufsize);
114
115 typedef struct _readloopstruct {
116         ConstStr name;
117         readloop_servcmd cmd;
118 } readloop_struct;
119
120 extern readloop_struct rlid[];
121
122 void readloop(long oper, eCustomRoomRenderer ForceRenderer);
123 int read_message(StrBuf *Target, 
124                  const char *tmpl, long tmpllen, 
125                  long msgnum, 
126                  const StrBuf *section, 
127                  const StrBuf **OutMime);
128 int load_message(message_summary *Msg, 
129                  StrBuf *FoundCharset,
130                  StrBuf **Error);
131
132
133
134
135 typedef struct _SharedMessageStatus {
136         long load_seen;        /* should read information be loaded */
137         long sortit;           /* should we sort it using the standard sort API? */
138         long defaultsortorder; /* if we should sort it, which direction should be the default? */
139
140         long maxload;          /* how many headers should we accept from the server? defaults to 10k */
141         long maxmsgs;          /* how many message bodies do you want to load at most?*/
142
143         long startmsg;         /* which is the start message? */
144         long nummsgs;          /* How many messages are available to your view? */
145         long num_displayed;    /* counted up for LoadMsgFromServer */ /* TODO: unclear who should access this and why */
146
147         long lowest_found;     /* smallest Message ID found;  */
148         long highest_found;    /* highest Message ID found;  */
149
150 } SharedMessageStatus;
151
152 int load_msg_ptrs(const char *servcmd,
153                   const char *filter,
154                   SharedMessageStatus *Stat, 
155                   load_msg_ptrs_detailheaders LH);
156
157 typedef int (*GetParamsGetServerCall_func)(SharedMessageStatus *Stat, 
158                                            void **ViewSpecific, 
159                                            long oper, 
160                                            char *cmd, 
161                                            long len,
162                                            char *filter,
163                                            long flen);
164
165 typedef int (*PrintViewHeader_func)(SharedMessageStatus *Stat, void **ViewSpecific);
166
167 typedef int (*LoadMsgFromServer_func)(SharedMessageStatus *Stat, 
168                                       void **ViewSpecific, 
169                                       message_summary* Msg, 
170                                       int is_new, 
171                                       int i);
172
173 typedef int (*RenderView_or_Tail_func)(SharedMessageStatus *Stat, 
174                                        void **ViewSpecific, 
175                                        long oper);
176 typedef int (*View_Cleanup_func)(void **ViewSpecific);
177
178 void RegisterReadLoopHandlerset(
179         /**
180          * RoomType: which View definition are you going to be called for
181          */
182         int RoomType,
183
184         /**
185          * GetParamsGetServerCall should do the following:
186          *  * allocate your private context structure
187          *  * evaluate your commandline arguments, put results to your private struct.
188          *  * fill cmd with the command to load the message pointer list:
189          *    * might depend on bstr/oper depending on your needs
190          *    * might stay empty if no list should loaded and LoadMsgFromServer 
191          *      is skipped.
192          *  * influence the behaviour by presetting values on SharedMessageStatus
193          */
194         GetParamsGetServerCall_func GetParamsGetServerCall,
195
196         /**
197          * PrintpageHeader prints the surrounding information like iconbar, header etc.
198          * by default, output_headers() is called.
199          *
200          */
201         PrintViewHeader_func PrintPageHeader,
202
203         /**
204          * PrintViewHeader is here to print informations infront of your messages.
205          * The message list is already loaded & sorted (if) so you can evaluate 
206          * its result on the SharedMessageStatus struct.
207          */
208         PrintViewHeader_func PrintViewHeader,
209
210         /**
211          * LH is the function, you specify if you want to load more than just message
212          * numbers from the server during the listing fetch operation.
213          */
214         load_msg_ptrs_detailheaders LH,
215
216         /**
217          * LoadMsgFromServer is called for every message in the message list:
218          *  * which is 
219          *    * after 'startmsg'  
220          *    * up to 'maxmsgs' after your 'startmsg'
221          *  * it should load and parse messages from citserer.
222          *  * depending on your needs you might want to print your message here...
223          *  * if cmd was empty, its skipped alltogether.
224          */
225         LoadMsgFromServer_func LoadMsgFromServer,
226
227         /**
228          * RenderView_or_Tail is called last; 
229          *  * if you used PrintViewHeader to print messages, you might want to print 
230          *    trailing information here
231          *  * if you just pre-loaded your messages, put your render code here.
232          */
233         RenderView_or_Tail_func RenderView_or_Tail,
234
235         /**
236          * ViewCleanup should just clear your private data so all your mem can go back to 
237          * VALgrindHALLA.
238          * it also should release the content for delivery via end_burst() or wDumpContent(1);
239          */
240         View_Cleanup_func ViewCleanup
241         );
242 /*
243 GetParamsGetServerCall
244
245 PrintViewHeader
246
247 LoadMsgFromServer
248
249 RenderView_or_Tail
250 */
251
252
253 int ParseMessageListHeaders_Detail(StrBuf *Line, 
254                                    const char **pos, 
255                                    message_summary *Msg, 
256                                    StrBuf *ConversionBuffer);
257
258
259
260 /**
261  * @brief function to register the availability to render a specific message
262  * @param HeaderName Mimetype we know howto display
263  * @param HdrNLen length...
264  * @param InlineRenderable Should we announce to citserver that we want to receive these mimeparts immediately?
265  * @param Priority if multipart/alternative; which mimepart/Renderer should be prefered? (only applies if InlineRenderable)
266  */
267 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, 
268                           RenderMimeFunc MimeRenderer,
269                           int InlineRenderable,
270                           int Priority);