10 static int file_size(int fd
)
17 static int read_file(int fd
, char *buf
, int len
)
21 int ret
= read(fd
, buf
+ nr
, len
- nr
);
22 if (ret
== -1 && (errno
== EAGAIN
|| errno
== EINTR
))
31 static char *mail_start(char *r
)
35 if (!strncmp("From ", s
, 5) && (s
== r
|| *(s
- 1) == '\n'))
37 s
= strchr(s
+ 1, 'F');
42 static char *mail_hdrs(struct mail
*mail
, char *s
)
44 while (s
&& *s
&& *s
!= '\r' && *s
!= '\n') {
45 if (!strncmp("Subject:", s
, 5))
47 s
= strchr(s
+ 1, '\n');
53 static char *mail_read(struct mail
*mail
, char *s
)
57 s
= mail_hdrs(mail
, s
);
59 mail
->len
= end
- mail
->head
;
63 static void read_mails(struct mbox
*mbox
)
67 s
= mail_read(&mbox
->mails
[mbox
->n
++], s
);
70 struct mbox
*mbox_alloc(char *filename
)
73 int fd
= open(filename
, O_RDONLY
);
77 mbox
= malloc(sizeof(*mbox
));
78 memset(mbox
, 0, sizeof(*mbox
));
80 mbox
->mbox
= malloc(len
+ 1);
81 mbox
->len
= read_file(fd
, mbox
->mbox
, len
);
82 mbox
->mbox
[len
] = '\0';
88 void mbox_free(struct mbox
*mbox
)