dat.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. typedef struct Message Message;
  2. struct Message
  3. {
  4. int id;
  5. int refs;
  6. int subname;
  7. char name[Elemlen];
  8. // pointers into message
  9. char *start; // start of message
  10. char *end; // end of message
  11. char *header; // start of header
  12. char *hend; // end of header
  13. int hlen; // length of header minus ignored fields
  14. char *mheader; // start of mime header
  15. char *mhend; // end of mime header
  16. char *body; // start of body
  17. char *bend; // end of body
  18. char *rbody; // raw (unprocessed) body
  19. char *rbend; // end of raw (unprocessed) body
  20. char *lim;
  21. char deleted;
  22. char inmbox;
  23. char mallocd; // message is malloc'd
  24. char ballocd; // body is malloc'd
  25. char hallocd; // header is malloce'd
  26. // mail info
  27. String *unixheader;
  28. String *unixfrom;
  29. String *unixdate;
  30. String *from822;
  31. String *sender822;
  32. String *to822;
  33. String *bcc822;
  34. String *cc822;
  35. String *replyto822;
  36. String *date822;
  37. String *inreplyto822;
  38. String *subject822;
  39. String *messageid822;
  40. String *addrs;
  41. String *mimeversion;
  42. String *sdigest;
  43. // mime info
  44. String *boundary;
  45. String *type;
  46. int encoding;
  47. int disposition;
  48. String *charset;
  49. String *filename;
  50. int converted;
  51. int decoded;
  52. char lines[10]; // number of lines in rawbody
  53. Message *next; // same level
  54. Message *part; // down a level
  55. Message *whole; // up a level
  56. uchar digest[SHA1dlen];
  57. vlong imapuid; // used by imap4
  58. char uidl[80]; // used by pop3
  59. int mesgno;
  60. };
  61. enum
  62. {
  63. // encodings
  64. Enone= 0,
  65. Ebase64,
  66. Equoted,
  67. // disposition possibilities
  68. Dnone= 0,
  69. Dinline,
  70. Dfile,
  71. Dignore,
  72. PAD64= '=',
  73. };
  74. typedef struct Mailbox Mailbox;
  75. struct Mailbox
  76. {
  77. QLock;
  78. int refs;
  79. Mailbox *next;
  80. int id;
  81. int dolock; // lock when syncing?
  82. int std;
  83. char name[Elemlen];
  84. char path[Pathlen];
  85. Dir *d;
  86. Message *root;
  87. int vers; // goes up each time mailbox is read
  88. ulong waketime;
  89. char *(*sync)(Mailbox*, int);
  90. void (*close)(Mailbox*);
  91. char *(*fetch)(Mailbox*, Message*);
  92. char *(*ctl)(Mailbox*, int, char**);
  93. void *aux; // private to Mailbox implementation
  94. };
  95. typedef char *Mailboxinit(Mailbox*, char*);
  96. extern Message *root;
  97. extern Mailboxinit plan9mbox;
  98. extern Mailboxinit pop3mbox;
  99. extern Mailboxinit imap4mbox;
  100. char* syncmbox(Mailbox*, int);
  101. char* geterrstr(void);
  102. void* emalloc(ulong);
  103. void* erealloc(void*, ulong);
  104. Message* newmessage(Message*);
  105. void delmessage(Mailbox*, Message*);
  106. void delmessages(int, char**);
  107. int newid(void);
  108. void mailplumb(Mailbox*, Message*, int);
  109. char* newmbox(char*, char*, int);
  110. void freembox(char*);
  111. void logmsg(char*, Message*);
  112. void msgincref(Message*);
  113. void msgdecref(Mailbox*, Message*);
  114. void mboxincref(Mailbox*);
  115. void mboxdecref(Mailbox*);
  116. void convert(Message*);
  117. void decode(Message*);
  118. int cistrncmp(char*, char*, int);
  119. int cistrcmp(char*, char*);
  120. int decquoted(char*, char*, char*, int);
  121. int xtoutf(char*, char**, char*, char*);
  122. void countlines(Message*);
  123. int headerlen(Message*);
  124. void parse(Message*, int, Mailbox*, int);
  125. void parseheaders(Message*, int, Mailbox*, int);
  126. void parsebody(Message*, Mailbox*);
  127. void parseunix(Message*);
  128. String* date822tounix(char*);
  129. int fidmboxrefs(Mailbox*);
  130. int hashmboxrefs(Mailbox*);
  131. void checkmboxrefs(void);
  132. extern int debug;
  133. extern int fflag;
  134. extern int logging;
  135. extern char user[Elemlen];
  136. extern char stdmbox[Pathlen];
  137. extern QLock mbllock;
  138. extern Mailbox *mbl;
  139. extern char *mntpt;
  140. extern int biffing;
  141. extern int plumbing;
  142. extern char* Enotme;
  143. enum
  144. {
  145. /* mail subobjects */
  146. Qbody,
  147. Qbcc,
  148. Qcc,
  149. Qdate,
  150. Qdigest,
  151. Qdisposition,
  152. Qfilename,
  153. Qfrom,
  154. Qheader,
  155. Qinreplyto,
  156. Qlines,
  157. Qmimeheader,
  158. Qmessageid,
  159. Qraw,
  160. Qrawbody,
  161. Qrawheader,
  162. Qrawunix,
  163. Qreplyto,
  164. Qsender,
  165. Qsubject,
  166. Qto,
  167. Qtype,
  168. Qunixheader,
  169. Qinfo,
  170. Qunixdate,
  171. Qmax,
  172. /* other files */
  173. Qtop,
  174. Qmbox,
  175. Qdir,
  176. Qctl,
  177. Qmboxctl,
  178. };
  179. #define PATH(id, f) ((((id)&0xfffff)<<10) | (f))
  180. #define FILE(p) ((p) & 0x3ff)
  181. char *dirtab[];
  182. // hash table to aid in name lookup, all files have an entry
  183. typedef struct Hash Hash;
  184. struct Hash {
  185. Hash *next;
  186. char *name;
  187. ulong ppath;
  188. Qid qid;
  189. Mailbox *mb;
  190. Message *m;
  191. };
  192. Hash *hlook(ulong, char*);
  193. void henter(ulong, char*, Qid, Message*, Mailbox*);
  194. void hfree(ulong, char*);
  195. ulong msgallocd, msgfreed;