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