29#define WHO "ezmlm-idx"
38char strnum[FMT_ULONG];
58static char inbuf[1024];
74static void die_usage(
void) {
logmsg(
WHO,100,USAGE,
"ezmlm-idx [-dDF] [-f msg] dir"); }
102 if (getln(&
bi,&line,&
match,
'\n') == -1)
107 if (*line.s ==
' ' || *line.s ==
'\t') {
115 if (!foundsubject && case_startb(line.s,line.len,
"Subject:")) {
119 }
else if (!foundfrom && case_startb(line.s,line.len,
"From:")) {
123 }
else if (!
flagdate && !foundreceived &&
124 case_startb(line.s,line.len,
"Received:")) {
125 pos = byte_chr(line.s,line.len,
';');
127 if (!stralloc_copyb(&
received,line.s+pos+2,line.len - pos - 3))
130 }
else if (
flagdate && !foundreceived &&
131 case_startb(line.s,line.len,
"Date:")) {
132 if (line.len < 22)
continue;
133 pos = 6 + byte_chr(line.s+6,line.len-6,
',');
137 while (line.s[pos] ==
' ' || line.s[pos] ==
'\t') ++pos;
139 while (++pos1 < line.len && line.s[pos1] !=
' ');
141 if (!stralloc_copyb(&
received,line.s+pos,pos1 - pos))
143 if (pos1 + 2 < line.len) {
144 if (line.s[pos1 + 2] ==
' ') {
145 if (line.s[pos1] >=
'7') {
151 if (pos < line.len) {
152 pos += byte_chr(line.s+pos,line.len-pos,
' ');
153 if (pos < line.len) {
155 while (line.s[pos] !=
' ' && line.s[pos] !=
'\n') ++pos;
158 if (!stralloc_catb(&
received,line.s+pos1,pos - pos1))
186 unsigned long msgnum = 0L;
187 unsigned long msgmax;
190 while ((
opt = getoptb(argc,argv,
"dDf:FvV")) != opteof)
194 case 'f':
if (optarg) scan_ulong(optarg,&
msgnum);
break;
198 default: die_usage();
201 if (!
dir) die_usage();
203 if (chdir(
dir) == -1)
217 switch (openreadclose(
"num",&
num,32)) {
222 scan_ulong(
num.s,&msgmax);
223 if (
msgnum > msgmax) _exit(0);
227 while (++
msgnum <= msgmax) {
239 if (mkdir(
fnadir.s,0755) == -1)
254 if (!stralloc_catb(&
fnaf,strnum,
261 }
else if (fstat(
fd,&st) == -1 || (!(st.st_mode & 0100)))
270 if (!stralloc_copyb(&line,strnum,fmt_ulong(strnum,
msgnum)))
die_nomem();
271 if (!stralloc_cats(&line,
": "))
die_nomem();
274 if (!stralloc_cats(&line,
" "))
die_nomem();
276 if (!stralloc_cats(&line,
"Re: "))
die_nomem();
278 if (!stralloc_cats(&line,
"\n\t"))
die_nomem();
280 if (!stralloc_cats(&line,
";"))
die_nomem();
291 if (!stralloc_cats(&line,
" "))
die_nomem();
293 if (!stralloc_cats(&line,
"\n"))
die_nomem();
294 if (buffer_put(&
bx,line.s,line.len) == -1)
298 if (!((
msgnum + 1) % 100) ||
300 if (buffer_flush(&
bx) == -1)
312 fd = open_append(
"indexed");
void mkauthhash(const char *s, unsigned int len, char *h)
void makehash(const char *indata, unsigned int inlen, char *hash)
const char auto_version[]
int unfold_hdr(char *, unsigned long, stralloc *, const char *, stralloc *, int)
Error messages. If you translate these, I would urge you to keep the English version as well....
int lockfile(const char *)
int getconf_line(stralloc *sa, const char *fn, int flagrequired, const char *dir)
unsigned int author_name(char **sout, char *s, unsigned int l)
void concat_hdr(char *indata, unsigned int n, stralloc *outdata)
void decode_hdr(const char *indata, unsigned int n, stralloc *outdata)
int idx_get_trimsubject(void)
reads an open message from 'fd', extracts the subject (if any), and returns the subject in 'sub',...
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)