1 /* iterate messages in mbox
2 * Copyright (C) 2012 Kirill Smelkov <kirr@navytux.spb.ru>
4 * This program is free software: you can Use, Study, Modify and Redistribute it
5 * under the terms of the GNU General Public License version 2. This program is
6 * distributed WITHOUT ANY WARRANTY. See COPYING file for full License terms.
10 #include "navymail/mbox-walk.h"
14 void prepare_mbox_walk(struct mbox_walk
*m
, FILE *fmbox
)
17 strbuf_init(&m
->msg
, 0);
18 strbuf_init(&m
->line
, 0);
23 /* see if line is an mbox(5) "From " line */
24 static int is_from_line(struct strbuf
*line
)
28 * 2) envelope sender-addr ; addr-spec as per RFC 2822 3.4.1
30 * 4) timestamp ; date-time as output by asctime(3)
34 * From example@example.com Fri Jun 23 02:56:55 2000
37 int envelope_ok
, date_ok
;
41 if (strncmp(line
->buf
, "From ", 5))
47 for (q
=p
; *q
&& !isspace(*q
); ++q
)
49 envelope_ok
= (q
!=p
); /* simply check whether it is present */
52 for (; isspace(*q
); ++q
)
56 date_ok
= !parse_date_basic(q
, /* timestamp,offset = */NULL
,NULL
);
58 if (!envelope_ok
|| !date_ok
)
59 warning("mbox: Strange From_ line \"%s\"--%s%s\n",
61 !envelope_ok
? " !envelope_ok" : "",
62 !date_ok
? " !date_ok" : "");
68 int next_mbox_entry(struct mbox_walk
*m
)
72 strbuf_reset(&m
->msg
);
75 strbuf_addbuf(&m
->msg
, &m
->line
);
77 eof
= strbuf_getwholeline(&m
->line
, m
->fmbox
, '\n');
81 if (is_from_line(&m
->line
)) {
85 /* this was first From_ line - continue
86 * NOTE: we are skipping everything before first From_ !
92 entry_ok
= (m
->msg
.len
!= 0);
94 /* free msg & line on stop */
95 strbuf_release(&m
->msg
);
96 strbuf_release(&m
->line
);