dat.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 latin1toutf(char*, char*, char*);
  121. int windows1257toutf(char*, char*, char*);
  122. int decquoted(char*, char*, char*, int);
  123. int xtoutf(char*, char**, char*, char*);
  124. void countlines(Message*);
  125. int headerlen(Message*);
  126. void parse(Message*, int, Mailbox*, int);
  127. void parseheaders(Message*, int, Mailbox*, int);
  128. void parsebody(Message*, Mailbox*);
  129. void parseunix(Message*);
  130. String* date822tounix(char*);
  131. int fidmboxrefs(Mailbox*);
  132. int hashmboxrefs(Mailbox*);
  133. void checkmboxrefs(void);
  134. extern int debug;
  135. extern int fflag;
  136. extern int logging;
  137. extern char user[Elemlen];
  138. extern char stdmbox[Pathlen];
  139. extern QLock mbllock;
  140. extern Mailbox *mbl;
  141. extern char *mntpt;
  142. extern int biffing;
  143. extern int plumbing;
  144. extern char* Enotme;
  145. enum
  146. {
  147. /* mail subobjects */
  148. Qbody,
  149. Qbcc,
  150. Qcc,
  151. Qdate,
  152. Qdigest,
  153. Qdisposition,
  154. Qfilename,
  155. Qfrom,
  156. Qheader,
  157. Qinreplyto,
  158. Qlines,
  159. Qmimeheader,
  160. Qmessageid,
  161. Qraw,
  162. Qrawbody,
  163. Qrawheader,
  164. Qrawunix,
  165. Qreplyto,
  166. Qsender,
  167. Qsubject,
  168. Qto,
  169. Qtype,
  170. Qunixheader,
  171. Qinfo,
  172. Qunixdate,
  173. Qmax,
  174. /* other files */
  175. Qtop,
  176. Qmbox,
  177. Qdir,
  178. Qctl,
  179. Qmboxctl,
  180. };
  181. #define PATH(id, f) ((((id)&0xfffff)<<10) | (f))
  182. #define FILE(p) ((p) & 0x3ff)
  183. char *dirtab[];
  184. // hash table to aid in name lookup, all files have an entry
  185. typedef struct Hash Hash;
  186. struct Hash {
  187. Hash *next;
  188. char *name;
  189. ulong ppath;
  190. Qid qid;
  191. Mailbox *mb;
  192. Message *m;
  193. };
  194. Hash *hlook(ulong, char*);
  195. void henter(ulong, char*, Qid, Message*, Mailbox*);
  196. void hfree(ulong, char*);
  197. ulong msgallocd, msgfreed;