356e0ff9c9a30d932552a00c86e0bdab670aa7cb
[citadel.git] / citadel / server / msgbase.h
1
2 #ifndef MSGBASE_H
3 #define MSGBASE_H
4
5 enum {
6         MSGS_ALL,
7         MSGS_OLD,
8         MSGS_NEW,
9         MSGS_FIRST,
10         MSGS_LAST,
11         MSGS_GT,
12         MSGS_EQ,
13         MSGS_SEARCH,
14         MSGS_LT
15 };
16
17 enum {
18         MSG_HDRS_BRIEF = 0,
19         MSG_HDRS_ALL = 1,
20         MSG_HDRS_EUID = 4,
21         MSG_HDRS_BRIEFFILTER = 8,
22         MSG_HDRS_THREADS = 9
23 };
24
25 // Possible return codes from CtdlOutputMsg()
26 enum {
27         om_ok,
28         om_not_logged_in,
29         om_no_such_msg,
30         om_mime_error,
31         om_access_denied
32 };
33
34 // Values of "headers_only" when calling message output routines
35 #define HEADERS_ALL     0       // Headers and body
36 #define HEADERS_ONLY    1       // Headers only
37 #define HEADERS_NONE    2       // Body only
38 #define HEADERS_FAST    3       // Headers only with no MIME info
39
40
41 struct ma_info {
42         int is_ma;              // Set to 1 if we are using this stuff
43         int freeze;             // Freeze the replacement chain because we're digging through a subsection
44         int did_print;          // One alternative has been displayed
45         char chosen_part[128];  // Which part of a m/a did we choose?
46         int chosen_pref;        // Chosen part preference level (lower is better)
47         int use_fo_hooks;       // Use fixed output hooks
48         int dont_decode;        // should we call the decoder or not?
49 };
50
51
52 struct repl {                   // Info for replication checking
53         char exclusive_id[SIZ];
54         time_t highest;
55 };
56
57
58 // This is a list of "harvested" email addresses that we might want to
59 // stick into someone's address book.  But we defer this operaiton so
60 // it can be done asynchronously.
61 struct addresses_to_be_filed {
62         struct addresses_to_be_filed *next;
63         char *roomname;
64         char *collected_addresses;
65 };
66
67 extern struct addresses_to_be_filed *atbf;
68
69 int GetFieldFromMnemonic(eMsgField *f, const char* c);
70 void memfmout (char *mptr, const char *nl);
71 void output_mime_parts(char *);
72 long send_message (struct CtdlMessage *);
73 void loadtroom (void);
74 long CtdlSubmitMsg(struct CtdlMessage *, struct recptypes *, const char *);
75 long quickie_message(char *from, char *fromaddr, char *to, char *room, char *text, int format_type, char *subject);
76 void GetMetaData(struct MetaData *, long);
77 void PutMetaData(struct MetaData *);
78 void AdjRefCount(long, int);
79 void TDAP_AdjRefCount(long, int);
80 int TDAP_ProcessAdjRefCountQueue(void);
81 void simple_listing(long, void *);
82 int CtdlMsgCmp(struct CtdlMessage *msg, struct CtdlMessage *template);
83 typedef void (*ForEachMsgCallback)(long MsgNumber, void *UserData);
84 int CtdlForEachMessage(int mode,
85                         long ref,
86                         char *searchstring,
87                         char *content_type,
88                         struct CtdlMessage *compare,
89                         ForEachMsgCallback CallBack,
90                         void *userdata);
91 int CtdlDeleteMessages(const char *, long *, int, char *);
92 long CtdlWriteObject(char *req_room,                    // Room to stuff it in
93                         char *content_type,             // MIME type of this object
94                         char *raw_message,              // Data to be written
95                         off_t raw_length,               // Size of raw_message
96                         struct ctdluser *is_mailbox,    // Mailbox room?
97                         int is_binary,                  // Is encoding necessary?
98                         unsigned int flags              // Internal save flags
99 );
100 struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body);
101 struct CtdlMessage * CM_Duplicate
102                        (struct CtdlMessage *OrgMsg);
103 int  CM_IsEmpty        (struct CtdlMessage *Msg, eMsgField which);
104 void CM_SetField       (struct CtdlMessage *Msg, eMsgField which, const char *buf);
105 void CM_SetFieldLONG   (struct CtdlMessage *Msg, eMsgField which, long lvalue);
106 void CM_CopyField      (struct CtdlMessage *Msg, eMsgField WhichToPutTo, eMsgField WhichtToCopy);
107 void CM_CutFieldAt     (struct CtdlMessage *Msg, eMsgField WhichToCut, long maxlen);
108 void CM_FlushField     (struct CtdlMessage *Msg, eMsgField which);
109 void CM_Flush          (struct CtdlMessage *Msg);
110 void CM_SetAsField     (struct CtdlMessage *Msg, eMsgField which, char **buf, long length);
111 void CM_SetAsFieldSB   (struct CtdlMessage *Msg, eMsgField which, StrBuf **buf);
112 void CM_GetAsField     (struct CtdlMessage *Msg, eMsgField which, char **ret, long *retlen);
113 void CM_PrependToField (struct CtdlMessage *Msg, eMsgField which, const char *buf, long length);
114
115 void CM_Free           (struct CtdlMessage *msg);
116 void CM_FreeContents   (struct CtdlMessage *msg);
117 int  CM_IsValidMsg     (struct CtdlMessage *msg);
118
119 #define CM_KEY(Message, Which) Message->cm_fields[Which], Message->cm_lengths[Which]
120 #define CM_RANGE(Message, Which) Message->cm_fields[Which], \
121                 Message->cm_fields[Which] + Message->cm_lengths[Which]
122
123 // Serialization routines use this struct to return a pointer and a length
124 struct ser_ret {
125         size_t len;
126         unsigned char *ser;
127 };
128
129 struct ser_ret CtdlSerializeMessage(struct CtdlMessage *);
130 struct CtdlMessage *CtdlDeserializeMessage(long msgnum, int with_body, const char *Buffer, long Length);
131 void ReplicationChecks(struct CtdlMessage *);
132 int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs,
133                               int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj
134 );
135 int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *msg);
136 long CtdlSaveThisMessage(struct CtdlMessage *msg, long msgid, int Reply);
137 char *CtdlReadMessageBody(char *terminator, long tlen, size_t maxlen, StrBuf *exist, int crlf);
138 StrBuf *CtdlReadMessageBodyBuf(
139                 char *terminator,       // token signalling EOT
140                 long tlen,
141                 size_t maxlen,          // maximum message length
142                 StrBuf *exist,          // if non-null, append to it; exist is ALWAYS freed
143                 int crlf                // CRLF newlines instead of LF
144 );
145
146 int CtdlOutputMsg(long msg_num,         // message number (local) to fetch
147                 int mode,               // how would you like that message?
148                 int headers_only,       // eschew the message body?
149                 int do_proto,           // do Citadel protocol responses?
150                 int crlf,               // 0=LF, 1=CRLF
151                 char *section,          // output a message/rfc822 section
152                 int flags,              // should the bessage be exported clean?
153                 char **Author,          // if you want to know the author of the message...
154                 char **Address,         // if you want to know the sender address of the message...
155                 char **MessageID        // if you want to know the Message-ID of the message...
156 );
157
158 // Flags which may be passed to CtdlOutputMsg() and CtdlOutputPreLoadedMsg()
159 #define QP_EADDR        (1<<0)          // quoted-printable encode email addresses
160 #define CRLF            (1<<1)
161 #define ESC_DOT         (1<<2)          // output a line containing only "." as ".." instead
162 #define SUPPRESS_ENV_TO (1<<3)          // suppress Envelope-to: header (warning: destructive!)
163
164 int CtdlOutputPreLoadedMsg(struct CtdlMessage *,
165                            int mode,            // how would you like that message?
166                            int headers_only,    // eschew the message body?
167                            int do_proto,        // do Citadel protocol responses?
168                            int crlf,            // 0=LF, 1=CRLF
169                            int flags            // should the bessage be exported clean?
170 );
171
172
173 // values for which_set
174 enum {
175         ctdlsetseen_seen,
176         ctdlsetseen_answered
177 };
178
179 void CtdlSetSeen(long *target_msgnums, int num_target_msgnums,
180         int target_setting, int which_set,
181         struct ctdluser *which_user, struct ctdlroom *which_room
182 );
183
184 void CtdlGetSeen(char *buf, int which_set);
185
186
187 struct CtdlMessage *CtdlMakeMessage(
188         struct ctdluser *author,        // author's user structure
189         char *recipient,                // NULL if it's not mail
190         char *recp_cc,                  // NULL if it's not mail
191         char *room,                     // room where it's going
192         int type,                       // see MES_ types in header file
193         int format_type,                // variformat, plain text, MIME...
194         char *fake_name,                // who we're masquerading as
195         char *my_email,                 // which of my email addresses to use (empty is ok)
196         char *subject,                  // Subject (optional)
197         char *supplied_euid,            // ...or NULL if this is irrelevant
198         char *preformatted_text,        // ...or NULL to read text from client
199         char *references                // Thread references
200 );
201
202 struct CtdlMessage *CtdlMakeMessageLen(
203         struct ctdluser *author,        // author's user structure
204         char *recipient,                // NULL if it's not mail
205         long rcplen,
206         char *recp_cc,                  // NULL if it's not mail
207         long cclen,
208         char *room,                     // room where it's going
209         long roomlen,
210         int type,                       // see MES_ types in header file
211         int format_type,                // variformat, plain text, MIME...
212         char *fake_name,                // who we're masquerading as
213         long fnlen,
214         char *my_email,                 // which of my email addresses to use (empty is ok)
215         long myelen,
216         char *subject,                  // Subject (optional)
217         long subjlen,
218         char *supplied_euid,            // ...or NULL if this is irrelevant
219         long euidlen,
220         char *preformatted_text,        // ...or NULL to read text from client
221         long textlen,
222         char *references,               // Thread references
223         long reflen
224 );
225
226 void AdjRefCountList(long *msgnum, long nmsg, int incr);
227
228 #endif