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