1 /* 2 * mailbox and message representations 3 * 4 * these structures are allocated with emalloc and must be explicitly freed 5 */ 6 typedef struct Box Box; 7 typedef struct Header Header; 8 typedef struct MAddr MAddr; 9 typedef struct MbLock MbLock; 10 typedef struct MimeHdr MimeHdr; 11 typedef struct Msg Msg; 12 typedef struct NamedInt NamedInt; 13 typedef struct Pair Pair; 14 15 enum 16 { 17 StrAlloc = 32, /* characters allocated at a time */ 18 BufSize = 8*1024, /* size of transfer block */ 19 NDigest = 40, /* length of digest string */ 20 NUid = 10, /* length of .imp uid string */ 21 NFlags = 8, /* length of .imp flag string */ 22 LockSecs = 5 * 60, /* seconds to wait for acquiring a locked file */ 23 MboxNameLen = 256, /* max. length of upas/fs mbox name */ 24 MsgNameLen = 32, /* max. length of a file in a upas/fs mbox */ 25 UserNameLen = 64, /* max. length of user's name */ 26 27 MUtf7Max = 6, /* max length for a modified utf7 character: &bbbb- */ 28 29 /* 30 * message flags 31 */ 32 MSeen = 1 << 0, 33 MAnswered = 1 << 1, 34 MFlagged = 1 << 2, 35 MDeleted = 1 << 3, 36 MDraft = 1 << 4, 37 MRecent = 1 << 5, 38 39 /* 40 * message bogus flags 41 */ 42 NotBogus = 0, /* the message is displayable */ 43 BogusHeader = 1, /* the header had bad characters */ 44 BogusBody = 2, /* the body had bad characters */ 45 BogusTried = 4, /* attempted to open the fake message */ 46 }; 47 48 struct Box 49 { 50 char *name; /* path name of mailbox */ 51 char *fs; /* fs name of mailbox */ 52 char *fsDir; /* /mail/fs/box->fs */ 53 char *imp; /* path name of .imp file */ 54 uchar writable; /* can write back messages? */ 55 uchar dirtyImp; /* .imp file needs to be written? */ 56 uchar sendFlags; /* need flags update */ 57 Qid qid; /* qid of fs mailbox */ 58 Qid impQid; /* qid of .imp when last synched */ 59 long mtime; /* file mtime when last read */ 60 ulong max; /* maximum msgs->seq, same as number of messages */ 61 ulong toldMax; /* last value sent to client */ 62 ulong recent; /* number of recently received messaged */ 63 ulong toldRecent; /* last value sent to client */ 64 ulong uidnext; /* next uid value assigned to a message */ 65 ulong uidvalidity; /* uid of mailbox */ 66 Msg *msgs; 67 }; 68 69 /* 70 * fields of Msg->info 71 */ 72 enum 73 { 74 /* 75 * read from upasfs 76 */ 77 IFrom, 78 ITo, 79 ICc, 80 IReplyTo, 81 IUnixDate, 82 ISubject, 83 IType, 84 IDisposition, 85 IFilename, 86 IDigest, 87 IBcc, 88 IInReplyTo, /* aka internal date */ 89 IDate, 90 ISender, 91 IMessageId, 92 ILines, /* number of lines of raw body */ 93 94 IMax 95 }; 96 97 struct Header 98 { 99 char *buf; /* header, including terminating \r\n */ 100 ulong size; /* strlen(buf) */ 101 ulong lines; /* number of \n characters in buf */ 102 103 /* 104 * pre-parsed mime headers 105 */ 106 MimeHdr *type; /* content-type */ 107 MimeHdr *id; /* content-id */ 108 MimeHdr *description; /* content-description */ 109 MimeHdr *encoding; /* content-transfer-encoding */ 110 MimeHdr *md5; /* content-md5 */ 111 MimeHdr *disposition; /* content-disposition */ 112 MimeHdr *language; /* content-language */ 113 }; 114 115 struct Msg 116 { 117 Msg *next; 118 Msg *prev; 119 Msg *kids; 120 Msg *parent; 121 char *fsDir; /* box->fsDir of enclosing message */ 122 Header head; /* message header */ 123 Header mime; /* mime header from enclosing multipart spec */ 124 int flags; 125 uchar sendFlags; /* flags value needs to be sent to client */ 126 uchar expunged; /* message actually expunged, but not yet reported to client */ 127 uchar matched; /* search succeeded? */ 128 uchar bogus; /* implies the message is invalid, ie contains nulls; see flags above */ 129 ulong uid; /* imap unique identifier */ 130 ulong seq; /* position in box; 1 is oldest */ 131 ulong id; /* number of message directory in upas/fs */ 132 char *fs; /* name of message directory */ 133 char *efs; /* pointer after / in fs; enough space for file name */ 134 135 ulong size; /* size of fs/rawbody, in bytes, with \r added before \n */ 136 ulong lines; /* number of lines in rawbody */ 137 138 char *iBuf; 139 char *info[IMax]; /* all info about message */ 140 141 char *unixDate; 142 MAddr *unixFrom; 143 144 MAddr *to; /* parsed out address lines */ 145 MAddr *from; 146 MAddr *replyTo; 147 MAddr *sender; 148 MAddr *cc; 149 MAddr *bcc; 150 }; 151 152 /* 153 * pre-parsed header lines 154 */ 155 struct MAddr 156 { 157 char *personal; 158 char *box; 159 char *host; 160 MAddr *next; 161 }; 162 163 struct MimeHdr 164 { 165 char *s; 166 char *t; 167 MimeHdr *next; 168 }; 169 170 /* 171 * mapping of integer & names 172 */ 173 struct NamedInt 174 { 175 char *name; 176 int v; 177 }; 178 179 /* 180 * lock for all mail file operations 181 */ 182 struct MbLock 183 { 184 int fd; 185 }; 186 187 /* 188 * parse nodes for imap4rev1 protocol 189 * 190 * important: all of these items are allocated 191 * in one can, so they can be tossed out at the same time. 192 * this allows leakless parse error recovery by simply tossing the can away. 193 * however, it means these structures cannot be mixed with the mailbox structures 194 */ 195 196 typedef struct Fetch Fetch; 197 typedef struct NList NList; 198 typedef struct SList SList; 199 typedef struct MsgSet MsgSet; 200 typedef struct Store Store; 201 typedef struct Search Search; 202 203 /* 204 * parse tree for fetch command 205 */ 206 enum 207 { 208 FEnvelope, 209 FFlags, 210 FInternalDate, 211 FRfc822, 212 FRfc822Head, 213 FRfc822Size, 214 FRfc822Text, 215 FBodyStruct, 216 FUid, 217 FBody, /* BODY */ 218 FBodySect, /* BODY [...] */ 219 FBodyPeek, 220 221 FMax 222 }; 223 224 enum 225 { 226 FPAll, 227 FPHead, 228 FPHeadFields, 229 FPHeadFieldsNot, 230 FPMime, 231 FPText, 232 233 FPMax 234 }; 235 236 struct Fetch 237 { 238 uchar op; /* F.* operator */ 239 uchar part; /* FP.* subpart for body[] & body.peek[]*/ 240 uchar partial; /* partial fetch? */ 241 long start; /* partial fetch amounts */ 242 long size; 243 NList *sect; 244 SList *hdrs; 245 Fetch *next; 246 }; 247 248 /* 249 * status items 250 */ 251 enum{ 252 SMessages = 1 << 0, 253 SRecent = 1 << 1, 254 SUidNext = 1 << 2, 255 SUidValidity = 1 << 3, 256 SUnseen = 1 << 4, 257 }; 258 259 /* 260 * parse tree for store command 261 */ 262 enum 263 { 264 STFlags, 265 STFlagsSilent, 266 267 STMax 268 }; 269 270 struct Store 271 { 272 uchar sign; 273 uchar op; 274 int flags; 275 }; 276 277 /* 278 * parse tree for search command 279 */ 280 enum 281 { 282 SKNone, 283 284 SKCharset, 285 286 SKAll, 287 SKAnswered, 288 SKBcc, 289 SKBefore, 290 SKBody, 291 SKCc, 292 SKDeleted, 293 SKDraft, 294 SKFlagged, 295 SKFrom, 296 SKHeader, 297 SKKeyword, 298 SKLarger, 299 SKNew, 300 SKNot, 301 SKOld, 302 SKOn, 303 SKOr, 304 SKRecent, 305 SKSeen, 306 SKSentBefore, 307 SKSentOn, 308 SKSentSince, 309 SKSet, 310 SKSince, 311 SKSmaller, 312 SKSubject, 313 SKText, 314 SKTo, 315 SKUid, 316 SKUnanswered, 317 SKUndeleted, 318 SKUndraft, 319 SKUnflagged, 320 SKUnkeyword, 321 SKUnseen, 322 323 SKMax 324 }; 325 326 struct Search 327 { 328 int key; 329 char *s; 330 char *hdr; 331 ulong num; 332 int year; 333 int mon; 334 int mday; 335 MsgSet *set; 336 Search *left; 337 Search *right; 338 Search *next; 339 }; 340 341 struct NList 342 { 343 ulong n; 344 NList *next; 345 }; 346 347 struct SList 348 { 349 char *s; 350 SList *next; 351 }; 352 353 struct MsgSet 354 { 355 ulong from; 356 ulong to; 357 MsgSet *next; 358 }; 359 360 struct Pair 361 { 362 ulong start; 363 ulong stop; 364 }; 365 366 #include "bin.h" 367 368 extern Bin *parseBin; 369 extern Biobuf bout; 370 extern Biobuf bin; 371 extern char username[UserNameLen]; 372 extern char mboxDir[MboxNameLen]; 373 extern char *fetchPartNames[FPMax]; 374 extern char *site; 375 extern char *remote; 376 extern int debug; 377 378 #include "fns.h" 379