CtdlSerializeMessage() now returns struct smr_ret
[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 struct ser_ret CtdlSerializeMessage(struct CtdlMessage *);
124 struct CtdlMessage *CtdlDeserializeMessage(long msgnum, int with_body, const char *Buffer, long Length);
125 void ReplicationChecks(struct CtdlMessage *);
126 int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs,
127                               int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj
128 );
129 int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *msg);
130 long CtdlSaveThisMessage(struct CtdlMessage *msg, long msgid, int Reply);
131 char *CtdlReadMessageBody(char *terminator, long tlen, size_t maxlen, StrBuf *exist, int crlf);
132 StrBuf *CtdlReadMessageBodyBuf(
133                 char *terminator,       // token signalling EOT
134                 long tlen,
135                 size_t maxlen,          // maximum message length
136                 StrBuf *exist,          // if non-null, append to it; exist is ALWAYS freed
137                 int crlf                // CRLF newlines instead of LF
138 );
139
140 int CtdlOutputMsg(long msg_num,         // message number (local) to fetch
141                 int mode,               // how would you like that message?
142                 int headers_only,       // eschew the message body?
143                 int do_proto,           // do Citadel protocol responses?
144                 int crlf,               // 0=LF, 1=CRLF
145                 char *section,          // output a message/rfc822 section
146                 int flags,              // should the bessage be exported clean?
147                 char **Author,          // if you want to know the author of the message...
148                 char **Address,         // if you want to know the sender address of the message...
149                 char **MessageID        // if you want to know the Message-ID of the message...
150 );
151
152 // Flags which may be passed to CtdlOutputMsg() and CtdlOutputPreLoadedMsg()
153 #define QP_EADDR        (1<<0)          // quoted-printable encode email addresses
154 #define CRLF            (1<<1)
155 #define ESC_DOT         (1<<2)          // output a line containing only "." as ".." instead
156 #define SUPPRESS_ENV_TO (1<<3)          // suppress Envelope-to: header (warning: destructive!)
157
158 int CtdlOutputPreLoadedMsg(struct CtdlMessage *,
159                            int mode,            // how would you like that message?
160                            int headers_only,    // eschew the message body?
161                            int do_proto,        // do Citadel protocol responses?
162                            int crlf,            // 0=LF, 1=CRLF
163                            int flags            // should the bessage be exported clean?
164 );
165
166
167 // values for which_set
168 enum {
169         ctdlsetseen_seen,
170         ctdlsetseen_answered
171 };
172
173 void CtdlSetSeen(long *target_msgnums, int num_target_msgnums,
174         int target_setting, int which_set,
175         struct ctdluser *which_user, struct ctdlroom *which_room
176 );
177
178 void CtdlGetSeen(char *buf, int which_set);
179
180
181 struct CtdlMessage *CtdlMakeMessage(
182         struct ctdluser *author,        // author's user structure
183         char *recipient,                // NULL if it's not mail
184         char *recp_cc,                  // NULL if it's not mail
185         char *room,                     // room where it's going
186         int type,                       // see MES_ types in header file
187         int format_type,                // variformat, plain text, MIME...
188         char *fake_name,                // who we're masquerading as
189         char *my_email,                 // which of my email addresses to use (empty is ok)
190         char *subject,                  // Subject (optional)
191         char *supplied_euid,            // ...or NULL if this is irrelevant
192         char *preformatted_text,        // ...or NULL to read text from client
193         char *references                // Thread references
194 );
195
196 struct CtdlMessage *CtdlMakeMessageLen(
197         struct ctdluser *author,        // author's user structure
198         char *recipient,                // NULL if it's not mail
199         long rcplen,
200         char *recp_cc,                  // NULL if it's not mail
201         long cclen,
202         char *room,                     // room where it's going
203         long roomlen,
204         int type,                       // see MES_ types in header file
205         int format_type,                // variformat, plain text, MIME...
206         char *fake_name,                // who we're masquerading as
207         long fnlen,
208         char *my_email,                 // which of my email addresses to use (empty is ok)
209         long myelen,
210         char *subject,                  // Subject (optional)
211         long subjlen,
212         char *supplied_euid,            // ...or NULL if this is irrelevant
213         long euidlen,
214         char *preformatted_text,        // ...or NULL to read text from client
215         long textlen,
216         char *references,               // Thread references
217         long reflen
218 );
219
220 void AdjRefCountList(long *msgnum, long nmsg, int incr);
221
222 #endif