imap4d.h 6.5 KB

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