1 /* append.h -- Description of messages to be copied 2 * 3 * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in 14 * the documentation and/or other materials provided with the 15 * distribution. 16 * 17 * 3. The name "Carnegie Mellon University" must not be used to 18 * endorse or promote products derived from this software without 19 * prior written permission. For permission or any legal 20 * details, please contact 21 * Carnegie Mellon University 22 * Center for Technology Transfer and Enterprise Creation 23 * 4615 Forbes Avenue 24 * Suite 302 25 * Pittsburgh, PA 15213 26 * (412) 268-7393, fax: (412) 268-7395 27 * innovation@andrew.cmu.edu 28 * 29 * 4. Redistributions of any form whatsoever must retain the following 30 * acknowledgment: 31 * "This product includes software developed by Computing Services 32 * at Carnegie Mellon University (http://www.cmu.edu/computing/)." 33 * 34 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO 35 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 36 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE 37 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 38 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 39 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 40 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 41 */ 42 43 #ifndef INCLUDED_APPEND_H 44 #define INCLUDED_APPEND_H 45 46 #include "mailbox.h" 47 #include "mboxevent.h" 48 #include "message.h" 49 #include "prot.h" 50 #include "sequence.h" 51 #include "strarray.h" 52 #include "annotate.h" 53 #include "conversations.h" 54 55 /* it's ridiculous i have to expose this structure if i want to allow 56 clients to stack-allocate it */ 57 struct appendstate { 58 /* mailbox we're appending to */ 59 struct mailbox *mailbox; 60 /* do we own it? */ 61 int close_mailbox_when_done:1; 62 int myrights; 63 char userid[MAX_MAILBOX_BUFFER]; 64 65 enum { APPEND_READY, APPEND_DONE } s; 66 /* current state of append */ 67 68 int nummsg; /* number of messages appended pending commit. 69 from as->baseuid ... m.baseuid + nummsg - 1 */ 70 unsigned baseuid; 71 72 /* set seen on these message on commit */ 73 int internalseen; 74 struct seqset *seen_seq; 75 76 /* for annotations */ 77 const struct namespace *namespace; 78 const struct auth_state *auth_state; 79 int isadmin; 80 81 /* one event notification to send per appended message */ 82 enum event_type event_type; 83 struct mboxevent *mboxevents; 84 }; 85 86 /* add helper function to determine uid range appended? */ 87 88 struct stagemsg; 89 90 extern int append_check(const char *name, 91 struct auth_state *auth_state, 92 long aclcheck, 93 const quota_t quotacheck[QUOTA_NUMRESOURCES]); 94 95 /* appendstate must be allocated by client */ 96 extern int append_setup(struct appendstate *as, const char *name, 97 const char *userid, const struct auth_state *auth_state, 98 long aclcheck, 99 const quota_t quotacheck[QUOTA_NUMRESOURCES], 100 const struct namespace *, int isadmin, enum event_type event_type); 101 extern int append_setup_mbox(struct appendstate *as, struct mailbox *mailbox, 102 const char *userid, 103 const struct auth_state *auth_state, 104 long aclcheck, 105 const quota_t quotacheck[QUOTA_NUMRESOURCES], 106 const struct namespace *namespace, 107 int isadmin, enum event_type event_type); 108 109 extern uint32_t append_uidvalidity(struct appendstate *as); 110 111 extern int append_commit(struct appendstate *as); 112 extern int append_abort(struct appendstate *as); 113 114 /* creates a new stage and returns stage file corresponding to mailboxname */ 115 extern FILE *append_newstage_full(const char *mailboxname, time_t internaldate, 116 int msgnum, struct stagemsg **stagep, 117 const char *sourcefile); 118 #define append_newstage(m, i, n, s) append_newstage_full((m), (i), (n), (s), NULL) 119 120 /* adds a new mailbox to the stage initially created by append_newstage() */ 121 extern int append_fromstage_full(struct appendstate *mailbox, struct body **body, 122 struct stagemsg *stage, 123 time_t internaldate, time_t savedate, 124 modseq_t createdmodseq, 125 const strarray_t *flags, int nolink, 126 struct entryattlist **annotations); 127 #define append_fromstage(m, b, s, i, c, f, n, a) \ 128 append_fromstage_full((m), (b), (s), (i), 0, (c), (f), (n), (a)) 129 130 /* removes the stage (frees memory, deletes the staging files) */ 131 extern int append_removestage(struct stagemsg *stage); 132 133 extern int append_fromstream(struct appendstate *as, struct body **body, 134 struct protstream *messagefile, 135 unsigned long size, time_t internaldate, 136 const strarray_t *flags); 137 138 extern int append_copy(struct mailbox *mailbox, 139 struct appendstate *append_mailbox, 140 ptrarray_t *msgrecs, 141 int nolink, int is_same_user); 142 143 extern int append_collectnews(struct appendstate *mailbox, 144 const char *group, unsigned long feeduid); 145 146 #define append_getuidvalidity(as) ((as)->m.uidvalidity) 147 #define append_getlastuid(as) ((as)->m.last_uid) 148 149 extern int append_run_annotator(struct appendstate *as, 150 msgrecord_t *msgrec); 151 152 extern const char *append_stagefname(struct stagemsg *stage); 153 154 #endif /* INCLUDED_APPEND_H */ 155