42#define WHO "ezmlm-get"
56 "from\\to\\subject\\reply-to\\date\\message-id\\cc\\"
57 "mime-version\\content-type\\content-transfer-encoding";
59static void die_usage() {
logmsg(
WHO,100,USAGE,
"ezmlm-get [-bBcClLpPsSvV] [-f fmt] [digestcode]"); }
62stralloc outhost = {0};
63stralloc outlocal = {0};
83unsigned long max = 0L;
87static char strnum[FMT_ULONG];
88char szmsgnum[FMT_ULONG];
211 if (sender && *sender) {
244 pos = scan_ulong(
num.s,&
max);
245 if (
num.s[pos] ==
':') pos++;
253 unsigned long retval;
258 scan_ulong(
num.s,&retval);
272 fd = open_trunc(
fnn);
276 if (buffer_put(&
bn,strnum,fmt_ulong(strnum,
num)) == -1)
278 if (buffer_puts(&
bn,
":") == -1)
280 if (buffer_put(&
bn,strnum,fmt_ulong(strnum,cum)) == -1)
283 if (buffer_puts(&
bn,
":") == -1)
285 if (buffer_put(&
bn,strnum,fmt_ulong(strnum,dat)) == -1)
288 if (buffer_puts(&
bn,
"\n") == -1)
290 if (buffer_flush(&
bn) == -1)
296 if (rename(
fnn,
fn) == -1)
313 hdr_adds(
"Content-Disposition: inline; filename=request.msg");
320 if (seek_begin(0) == -1)
322 if (buffer_copy(&
bq,&
bj) != 0)
364 if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,
from)))
die_nomem();
366 if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,
to)))
die_nomem();
391 qmail_puts(&
qq,
"\n----------------------------------------------------------------------\n");
407 qmail_puts(&
qq,
"\n***********************************\n");
426 case NATIVE: buffer_init(&bt,buffer_unixread,
fd,textbuf,
sizeof(textbuf));
428 if (getln(&bt,&line,&
match,
'\n') == -1)
438 case MIXED: flaginheader = 1; flaggoodfield = 0;
439 buffer_init(&bt,buffer_unixread,
fd,textbuf,
sizeof(textbuf));
441 if (getln(&bt,&line,&
match,
'\n') == -1)
448 }
else if (line.s[0] !=
' ' && line.s[0] !=
'\t') {
450 if (constmap(&
digheadersmap,line.s,byte_chr(line.s,line.len,
':')))
465 case RFC1153: flaginheader = 1;
469 buffer_init(&bt,buffer_unixread,
fd,textbuf,
sizeof(textbuf));
471 if (getln(&bt,&line,&
match,
'\n') == -1)
513 }
else if (line.s[0] ==
' ' || line.s[0] ==
'\t') {
523 default:
logmsg(
WHO,111,FATAL,
"Program error: Bad archive header type");
527 if (case_startb(line.s,line.len,
"cc:")) {
530 }
else if (case_startb(line.s,line.len,
"date:")) {
533 }
else if (case_startb(line.s,line.len,
"from:")) {
536 }
else if (case_startb(line.s,line.len,
"keywords:")) {
539 }
else if (case_startb(line.s,line.len,
"message-id:")) {
542 }
else if (case_startb(line.s,line.len,
"subject:")) {
545 }
else if (case_startb(line.s,line.len,
"to:")) {
550 }
else if (line.len == 1) {
566 default:
logmsg(
WHO,100,FATAL,
"Program error: bad format in copymsg()");
579 qmail_puts(&
qq,
"Content-Disposition: inline; filename=\"");
593void msgout(
unsigned long msg,
char format)
600 len = fmt_ulong(strnum, msg / 100);
603 len = fmt_uint0(strnum, (
unsigned int) (msg % 100),2);
617 }
else if (fstat(
fd,&st) == -1 || (!(st.st_mode & 0100))) {
623 qmail_puts(&
qq,
"Content-Disposition: inline; filename=\"");
643 if (fstat(
fd,&st) == -1 || (!(st.st_mode & 0100))) {
656 default:
logmsg(
WHO,100,FATAL,
"Program error: Unrecognized format in msgout");
break;
667 unsigned long from,
unsigned long to,stralloc *subj,
int factype,
char format)
675 unsigned long subnum;
684 subnum = (
unsigned long) (psubt - subtable +1);
686 if (pmsgt->
subnum == subnum) {
689 if (!stralloc_copys(&line,
"\n"))
die_nomem();
691 if (!stralloc_cats(&line,
"(null)\n"))
die_nomem();
695 if (!stralloc_copys(&line,
""))
die_nomem();
696 if (!stralloc_cats(&line,
"\t"))
die_nomem();
697 if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,msg)))
die_nomem();
707 if (!stralloc_cats(&line,
"\n"))
die_nomem();
720 subnum = (
unsigned long) (psubt - subtable +1);
722 if (pmsgt->
subnum == subnum)
734 int flaggoodfield,
match;
741 hdr_add2(
"List-ID: ",line.s,line.len);
755 if (getln(&
bi,&line,&
match,
'\n') == -1)
758 if (line.len == 1)
break;
759 if ((line.s[0] !=
' ') && (line.s[0] !=
'\t')) {
761 if (case_startb(line.s,line.len,
"mailing-list:"))
767 if (byte_equal(line.s,line.len,
mydtline.s))
769 if (case_startb(line.s,line.len,
"delivered-to:"))
771 if (case_startb(line.s,line.len,
"received:"))
793 unsigned long from, u,
to, issue, prevmax, mno;
796 unsigned int pos,pos1;
812 while ((
opt = getoptb(argc,argv,
"bBcCf:pPsSt:vV")) != opteof)
816 case 'c':
flagdo = 1;
break;
817 case 'C':
flagdo = 0;
break;
819 outformat = optarg[0];
827 default: die_usage();
830 dir = argv[optind++];
831 if (!
dir) die_usage();
832 if (chdir(
dir) == -1)
841 local = env_get(
"LOCAL");
842 def = env_get(
"DEFAULT");
843 sender = env_get(
"SENDER");
849 if (str_equal(sender,
"#@[]"))
851 if (!sender[str_chr(sender,
'@')])
864 if (case_starts(
action,
"dig")) {
907 if (*psz ==
'\\') *psz =
'\0';
930 if (line.len && line.s[0] ==
'/') {
974 if (!stralloc_cats(&outlocal,
"-digest"))
die_nomem();
977 scan_ulong(line.s,&chunk);
985 if (!stralloc_cats(&line,
"/0"))
die_nomem();
1020 pos = scan_ulong(
num.s,&prevmax);
1021 if (
num.s[pos] ==
':') pos++;
1023 if (
num.s[pos] ==
':') pos++;
1034 szmsgnum[fmt_ulong(szmsgnum,mno)] =
'\0';
1043 scan_ulong(
num.s,&issue);
1107 szmsgnum[fmt_ulong(szmsgnum,
max)] =
'\0';
1112 if (u == 0 &&
to == 0) {
1121 }
else if (u >
max) {
1162 szmsgnum[fmt_ulong(szmsgnum,
max)] =
'\0';
1175 if (u == 0 &&
to == 0) {
to =
max; u =
max - 100; }
1185 if (!stralloc_catb(&
fn,strnum,fmt_ulong(strnum,u)))
die_nomem();
1192 fd = open_read(
fn.s);
1194 if (errno != ENOENT)
1199 buffer_init(&bt,buffer_unixread,
fd,textbuf,
sizeof(textbuf));
1202 if (getln(&bt,&line,&
match,
'\n') == -1)
1205 if (line.s[0] !=
'\t') {
1206 pos = byte_chr(line.s,line.len,
' ');
1207 if (pos && pos != line.len && line.s[pos - 1] ==
':')
1209 if (pos1 >= line.len) {
1214 if (!stralloc_catb(&
line2,line.s + pos1,line.len - pos1))
die_nomem();
1216 pos = byte_chr(line.s,line.len,
';');
1217 if (pos +
HASHLEN + 1 < line.len && pos > 15 && line.s[pos + 1] !=
' ') {
1255 szmsgnum[fmt_ulong(szmsgnum,
max)] =
'\0';
1275 if(u == 0 || u >
max) {
1303 logmsg(
WHO,100,FATAL,
"Program error: I'm supposed to deal with this but I didn't");
1305 if (!stralloc_copy(&line,&outlocal))
die_nomem();
1308 if (!stralloc_cats(&line,
"-return-g-"))
die_nomem();
1310 if (!stralloc_cats(&line,
"-return-"))
die_nomem();
1311 strnum[fmt_ulong(strnum,mno)] =
'\0';
1312 if (!stralloc_cats(&line,strnum))
die_nomem();
1313 if (!stralloc_cats(&line,
"-@"))
die_nomem();
1315 if (!stralloc_cat(&line,&outhost))
die_nomem();
1316 if (!stralloc_cats(&line,
"-@[]"))
die_nomem();
1318 if (!stralloc_cats(&line,
"-return-@"))
die_nomem();
1319 if (!stralloc_cat(&line,&outhost))
die_nomem();
1328 if (!stralloc_copys(&line,
"T"))
die_nomem();
1329 if (!stralloc_cat(&line,&outlocal))
die_nomem();
1330 if (!stralloc_cats(&line,
"-s-d-"))
die_nomem();
1332 if (!stralloc_cats(&line,
"-"))
die_nomem();
1333 if (!stralloc_cats(&line,strnum))
die_nomem();
1334 if (!stralloc_cats(&line,
"-"))
die_nomem();
1340 for (i = 0; i <= 52; i += chunk) {
1342 schar[0] =
'0' + i / 10;
1343 schar[1] =
'0' + (i % 10);
1347 schar[0] =
'0' + j / 10;
1348 schar[1] =
'0' + (j % 10);
1370 logmsg(
WHO,goodexit,INFO,B(
"qp ",strnum));
#define TXT_ADMINISTRIVIA
void makehash(const char *indata, unsigned int inlen, char *hash)
int issub()
Returns (char *) to match if userhost is in the subscriber database dbname, 0 otherwise....
int quote2(stralloc *sa, const char *s)
int quote(stralloc *saout, const stralloc *sain)
const char auto_version[]
Error messages. If you translate these, I would urge you to keep the English version as well....
#define ERR_SUBSCRIBER_CAN
#define ERR_TMP_QMAIL_QUEUE
int lockfile(const char *)
const char * qmail_close(struct qmail *)
void qmail_puts(struct qmail *, const char *)
void qmail_put(struct qmail *, const char *, int)
void qmail_from(struct qmail *, const char *)
void qmail_to(struct qmail *, const char *)
unsigned long qmail_qp(struct qmail *)
int qmail_open(struct qmail *, const stralloc *)
charset, outhost, outlocal and flagcd are shared
const char * loginfo(const char *dir, unsigned long msgnum, unsigned long, unsigned long subs, int done)
void tagmsg(const char *dir, unsigned long msgnum, const char *seed, const char *action, char *hashout, unsigned long bodysize, unsigned long chunk)
void closesql(void)
close connection to SQL server, if open
unsigned long putsubs(const char *dir, unsigned long hash_lo, unsigned long hash_hi, int subwrite(), int flagsql)
int getconf(stralloc *sa, const char *fn, int flagrequired, const char *dir)
int getconf_line(stralloc *sa, const char *fn, int flagrequired, const char *dir)
void ezcopy(struct qmail *qqp, const char *fn, char q)
void set_cpoutlocal(const stralloc *ln)
void set_cpnum(const char *cf)
void set_cpouthost(const stralloc *ln)
void encode_qp(const char *indata, unsigned int n, stralloc *outdata)
void digest(msgentry *msgtable, subentry *subtable, authentry *authtable, unsigned long from, unsigned long to, stralloc *subj, int factype, char format)
void postmsg(char format)
void msgout(unsigned long msg, char format)
void mime_getbad(unsigned long msg)
void normal_bottom(char format)
void copymsg(unsigned long msg, int fd, char format)
int subto(char *s, unsigned int l)
void zapnonsub(char *szerr)
void write_ulong(unsigned long num, unsigned long cum, unsigned long dat, char *fn, char *fnn)
ssize_t qqwrite(int fd, char *buf, unsigned int len)
struct constmap digheadersmap
void postsub(int factype, char format)
void presub(unsigned long from, unsigned long to, stralloc *subject, int factype, char format)
void code_qput(char *s, unsigned int n)
void hdr_from(const char *append)
void hdr_boundary(int last)
void hdr_datemsgid(unsigned long when)
unsigned int date822fmt(char *s, const struct datetime *dt)
void idx_mkthread(msgentry **pmsgtable, subentry **psubtable, authentry **pauthtable, unsigned long msg_from, unsigned long msg_to, unsigned long msg_master, unsigned long msg_latest, int locked)
void idx_destroythread(msgentry *msgtable, subentry *subtable, authentry *authtable)
void idx_mklist(msgentry **pmsgtable, subentry **psubtable, authentry **pauthtable, unsigned long msg_from, unsigned long msg_to)
void idx_mkthreads(msgentry **pmsgtable, subentry **psubtable, authentry **pauthtable, dateentry **pdatetable, unsigned long msg_from, unsigned long msg_to, unsigned long msg_latest, int locked)
ssize_t qqwrite(int fd, char *buf, unsigned int len)
void hdr_transferenc(void)
void hdr_add2(const char *start, const char *value, unsigned int len)
void hdr_adds(const char *line)
void encode_b64(const unsigned char *indata, unsigned int n, stralloc *outdata, int control)
void datetime_tai(struct datetime *dt, datetime_sec t)
void hdr_ctype(enum ctype ctype)
void hdr_mime(enum ctype ctype)
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)