plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

dat.h (4304B)


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