* NeedNewBuf() as CLANG indicates, this parameter should have a name
[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
29 typedef struct _message_summary {
30         time_t date;            /* its creation date */
31         long msgnum;            /* the message number on the citadel server */
32         int nhdr;
33         int format_type;
34         StrBuf *euid;
35         StrBuf *from;           /* the author */
36         StrBuf *to;             /* the recipient */
37         StrBuf *subj;           /* the title / subject */
38         StrBuf *reply_inreplyto;
39         StrBuf *reply_references;
40         StrBuf *reply_to;
41         StrBuf *cccc;
42         StrBuf *hnod;
43         StrBuf *AllRcpt;
44         StrBuf *Room;
45         StrBuf *Rfca;
46         StrBuf *OtherNode;
47         const StrBuf *PartNum;
48
49         HashList *Attachments;  /* list of attachments */
50         HashList *Submessages;
51         HashList *AttachLinks;
52
53         HashList *AllAttach;
54
55         int is_new;
56         int hasattachments;
57
58
59         /* The mime part of the message */
60         wc_mime_attachment *MsgBody;
61 } message_summary;
62 void DestroyMessageSummary(void *vMsg);
63
64
65
66 static inline message_summary* GetMessagePtrAt(int n, HashList *Summ)
67 {
68         const char *Key;
69         long HKLen;
70         void *vMsg;
71
72         if (Summ == NULL)
73                 return NULL;
74         GetHashAt(Summ, n, &HKLen, &Key, &vMsg);
75         return (message_summary*) vMsg;
76 }
77
78 typedef void (*ExamineMsgHeaderFunc)(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset);
79
80 void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime);
81
82
83 typedef enum _eCustomRoomRenderer {
84         eUseDefault = VIEW_JOURNAL + 100, 
85         eReadEUIDS
86 }eCustomRoomRenderer;
87
88 enum {
89         do_search,
90         headers,
91         readfwd,
92         readnew,
93         readold,
94         readgt,
95         readlt
96 };
97
98 /**
99  * @brief function to parse the | separated message headers list
100  * @param Line the raw line with your message data
101  * @param Msg put your parser results here...
102  * @param ConversionBuffer if you need some workbuffer, don't free me!
103  * @returns 0: failure, trash this message. 1: all right, store it
104  */
105 typedef int (*load_msg_ptrs_detailheaders) (StrBuf *Line, 
106                                             const char **pos, 
107                                             message_summary *Msg, 
108                                             StrBuf *ConversionBuffer);
109
110 typedef void (*readloop_servcmd)(char *buf, long bufsize);
111
112 typedef struct _readloopstruct {
113         ConstStr name;
114         readloop_servcmd cmd;
115 } readloop_struct;
116
117 extern readloop_struct rlid[];
118
119 void readloop(long oper, eCustomRoomRenderer ForceRenderer);
120 int read_message(StrBuf *Target, 
121                  const char *tmpl, long tmpllen, 
122                  long msgnum, 
123                  const StrBuf *section, 
124                  const StrBuf **OutMime);
125 int load_message(message_summary *Msg, 
126                  StrBuf *FoundCharset,
127                  StrBuf **Error);
128
129
130
131
132 typedef struct _SharedMessageStatus {
133         long load_seen;        /* should read information be loaded */
134         long sortit;           /* should we sort it using the standard sort API? */
135         long defaultsortorder; /* if we should sort it, which direction should be the default? */
136
137         long maxload;          /* how many headers should we accept from the server? defaults to 10k */
138         long maxmsgs;          /* how many message bodies do you want to load at most?*/
139
140         long startmsg;         /* which is the start message? */
141         long nummsgs;          /* How many messages are available to your view? */
142         long num_displayed;    /* counted up for LoadMsgFromServer */ /* TODO: unclear who should access this and why */
143
144         long lowest_found;     /* smallest Message ID found;  */
145         long highest_found;    /* highest Message ID found;  */
146
147 } SharedMessageStatus;
148
149 int load_msg_ptrs(const char *servcmd, 
150                   SharedMessageStatus *Stat, 
151                   load_msg_ptrs_detailheaders LH);
152
153 typedef int (*GetParamsGetServerCall_func)(SharedMessageStatus *Stat, 
154                                            void **ViewSpecific, 
155                                            long oper, 
156                                            char *cmd, 
157                                            long len);
158
159 typedef int (*PrintViewHeader_func)(SharedMessageStatus *Stat, void **ViewSpecific);
160
161 typedef int (*LoadMsgFromServer_func)(SharedMessageStatus *Stat, 
162                                       void **ViewSpecific, 
163                                       message_summary* Msg, 
164                                       int is_new, 
165                                       int i);
166
167 typedef int (*RenderView_or_Tail_func)(SharedMessageStatus *Stat, 
168                                        void **ViewSpecific, 
169                                        long oper);
170 typedef int (*View_Cleanup_func)(void **ViewSpecific);
171
172 void RegisterReadLoopHandlerset(
173         /**
174          * RoomType: which View definition are you going to be called for
175          */
176         int RoomType,
177
178         /**
179          * GetParamsGetServerCall should do the following:
180          *  * allocate your private context structure
181          *  * evaluate your commandline arguments, put results to your private struct.
182          *  * fill cmd with the command to load the message pointer list:
183          *    * might depend on bstr/oper depending on your needs
184          *    * might stay empty if no list should loaded and LoadMsgFromServer 
185          *      is skipped.
186          *  * influence the behaviour by presetting values on SharedMessageStatus
187          */
188         GetParamsGetServerCall_func GetParamsGetServerCall,
189
190         /**
191          * PrintViewHeader is here to print informations infront of your messages.
192          * The message list is already loaded & sorted (if) so you can evaluate 
193          * its result on the SharedMessageStatus struct.
194          */
195         PrintViewHeader_func PrintViewHeader,
196
197         /**
198          * LH is the function, you specify if you want to load more than just message
199          * numbers from the server during the listing fetch operation.
200          */
201         load_msg_ptrs_detailheaders LH,
202
203         /**
204          * LoadMsgFromServer is called for every message in the message list:
205          *  * which is 
206          *    * after 'startmsg'  
207          *    * up to 'maxmsgs' after your 'startmsg'
208          *  * it should load and parse messages from citserer.
209          *  * depending on your needs you might want to print your message here...
210          *  * if cmd was empty, its skipped alltogether.
211          */
212         LoadMsgFromServer_func LoadMsgFromServer,
213
214         /**
215          * RenderView_or_Tail is called last; 
216          *  * if you used PrintViewHeader to print messages, you might want to print 
217          *    trailing information here
218          *  * if you just pre-loaded your messages, put your render code here.
219          */
220         RenderView_or_Tail_func RenderView_or_Tail,
221
222         /**
223          * ViewCleanup should just clear your private data so all your mem can go back to 
224          * VALgrindHALLA.
225          * it also should release the content for delivery via end_burst() or wDumpContent(1);
226          */
227         View_Cleanup_func ViewCleanup
228         );
229 /*
230 GetParamsGetServerCall
231
232 PrintViewHeader
233
234 LoadMsgFromServer
235
236 RenderView_or_Tail
237 */
238
239
240 int ParseMessageListHeaders_Detail(StrBuf *Line, 
241                                    const char **pos, 
242                                    message_summary *Msg, 
243                                    StrBuf *ConversionBuffer);