upas: convert to tmdate, change timezone format

Complete the conversion of upas to remove ctime,
use the new date library, and print time zones
in +hhmm format, instead of NNN format.

This may affect code that expects specific names
for timezones. Fix that code.
This commit is contained in:
Ori Bernstein 2020-09-26 11:20:42 -07:00
parent 9afa5550f7
commit d9f9e10e7b
30 changed files with 140 additions and 364 deletions

View file

@ -82,6 +82,7 @@ threadmain(int argc, char *argv[])
doquote = needsrcquote; doquote = needsrcquote;
quotefmtinstall(); quotefmtinstall();
tmfmtinstall();
/* open these early so we won't miss notification of new mail messages while we read mbox */ /* open these early so we won't miss notification of new mail messages while we read mbox */
plumbsendfd = plumbopen("send", OWRITE|OCEXEC); plumbsendfd = plumbopen("send", OWRITE|OCEXEC);

View file

@ -224,14 +224,13 @@ mesgadd(Message *mbox, char *dir, Dir *d, char *digest)
int int
thisyear(char *year) thisyear(char *year)
{ {
static char now[10]; Tzone *tz;
char *s; Tm tm;
if(now[0] == '\0'){ /* ignore errors: screwed means utc */
s = ctime(time(nil)); tz = tzload("local");
strcpy(now, s+24); tmnow(&tm, tz);
} return atoi(year) == (tm.year + 1900);
return strncmp(year, now, 4) == 0;
} }
char* char*

View file

@ -388,7 +388,9 @@ mesgsend(Message *m)
Channel *sync; Channel *sync;
Message *r; Message *r;
int first, nfld, delit, ofd; int first, nfld, delit, ofd;
char *copy, *fld[100], *now; char *copy, *fld[100];
Tzone *tz;
Tm now;
body = winreadbody(m->w, &n); body = winreadbody(m->w, &n);
/* assemble to: list from first line, to: line, and cc: line */ /* assemble to: list from first line, to: line, and cc: line */
@ -467,11 +469,12 @@ mesgsend(Message *m)
ofd = open(outgoing, OWRITE|OCEXEC); /* no error check necessary */ ofd = open(outgoing, OWRITE|OCEXEC); /* no error check necessary */
if(ofd >= 0){ if(ofd >= 0){
/* From dhog Fri Aug 24 22:13:00 EDT 2001 */ /* From dhog Fri Aug 24 22:13:00 +0500 2001 */
now = ctime(time(0)); tz = tzload("local");
fprint(ofd, "From %s %s", user, now); tmnow(&now, tz);
fprint(ofd, "From %s %τ", user, tmfmt(&now, "WW MMM _D hh:mm:ss Z YYYY"));
fprint(ofd, "From: %s\n", user); fprint(ofd, "From: %s\n", user);
fprint(ofd, "Date: %s", now); fprint(ofd, "Date: %τ", tmfmt(&now, "WW MMM _D hh:mm:ss Z YYYY"));
for(i=0; i<natt; i++) for(i=0; i<natt; i++)
if(included[i]) if(included[i])
fprint(ofd, "Include: %s\n", attlist[i]); fprint(ofd, "Include: %s\n", attlist[i]);

View file

@ -20,6 +20,7 @@ enum{
Fstored = 1<<6, /* S */ Fstored = 1<<6, /* S */
Nflags = 7, Nflags = 7,
}; };
#define Timefmt "WW MMM _D hh:mm:ss ?Z YYYY"
/* /*
* flag.c * flag.c

View file

@ -1,7 +1,5 @@
#include "common.h" #include "common.h"
#define Ctimefmt "WW MMM _D hh:mm:ss ?Z YYYY"
enum{ enum{
Mbox = 1, Mbox = 1,
Mdir, Mdir,
@ -186,22 +184,24 @@ mboxesc(Biobuf *in, Biobuf *out, int type)
int int
appendfolder(Biobuf *b, char *addr, int fd) appendfolder(Biobuf *b, char *addr, int fd)
{ {
char *s, *t; char *s;
int r; int r, n;
Biobuf bin; Biobuf bin;
Folder *f; Folder *f;
Tzone *tz;
Tm tm; Tm tm;
f = getfolder(b); f = getfolder(b);
Bseek(f->out, 0, 2); Bseek(f->out, 0, 2);
Binit(&bin, fd, OREAD); Binit(&bin, fd, OREAD);
s = Brdstr(&bin, '\n', 0); s = Brdstr(&bin, '\n', 0);
if(s == nil || strncmp(s, "From ", 5) != 0) n = strlen(s);
Bprint(f->out, "From %s %.28s\n", addr, ctime(f->t)); if(!s || strncmp(s, "From ", 5) != 0){
else if(strncmp(s, "From ", 5) == 0 tz = tzload("local");
&& (t = strchr(s + 5, ' ')) != nil tmtime(&tm, f->t, tz);
&& tmparse(&tm, Ctimefmt, t + 1, nil, nil) != nil) Bprint(f->out, "From %s %τ\n", addr, tmfmt(&tm, Timefmt));
f->t = tm2sec(&tm); }else if(n > 5 && tmparse(&tm, Timefmt, s + 5, nil, nil) != nil)
f->t = tmnorm(&tm);
if(s) if(s)
Bwrite(f->out, s, strlen(s)); Bwrite(f->out, s, strlen(s));
free(s); free(s);

View file

@ -5,14 +5,15 @@
/* /*
* return the date * return the date
*/ */
char* Tmfmt
thedate(void) thedate(Tm *tm)
{ {
static char now[64]; Tzone *tz;
strcpy(now, ctime(time(0))); /* if the local time is screwed, just do gmt */
now[28] = 0; tz = tzload("local");
return now; tmnow(tm, tz);
return tmfmt(tm, Timefmt);
} }
/* /*

View file

@ -35,7 +35,7 @@ char *alt_sysname_read(void);
char *domainname_read(void); char *domainname_read(void);
char **sysnames_read(void); char **sysnames_read(void);
char *getlog(void); char *getlog(void);
char *thedate(void); Tmfmt thedate(Tm*);
Biobuf *sysopen(char*, char*, ulong); Biobuf *sysopen(char*, char*, ulong);
int sysopentty(void); int sysopentty(void);
int sysclose(Biobuf*); int sysclose(Biobuf*);

View file

@ -14,13 +14,15 @@ usage(void)
void void
main(int argc, char **argv) main(int argc, char **argv)
{ {
char *to, *s; char *to;
Tmfmt tf;
Tm tm;
int r; int r;
long l;
Addr *a; Addr *a;
ARGBEGIN{ ARGBEGIN{
}ARGEND; }ARGEND;
tmfmtinstall();
if(argc != 3) if(argc != 3)
usage(); usage();
if(to = strrchr(argv[0], '!')) if(to = strrchr(argv[0], '!'))
@ -30,9 +32,9 @@ main(int argc, char **argv)
a = readaddrs(argv[1], nil); a = readaddrs(argv[1], nil);
if(a == nil) if(a == nil)
sysfatal("missing from address"); sysfatal("missing from address");
s = ctime(l = time(0)); tf = thedate(&tm);
werrstr(""); werrstr("");
r = fappendfolder(a->val, l, argv[2], 0); r = fappendfolder(a->val, tmnorm(&tm), argv[2], 0);
syslog(0, "mail", "delivered %s From %s %.28s (%s) %d %r", to, a->val, s, argv[0], r); syslog(0, "mail", "delivered %s From %s %τ (%s) %d %r", to, a->val, tf, argv[0], r);
exits(""); exits("");
} }

View file

@ -306,6 +306,7 @@ main(int argc, char **argv)
} ARGEND; } ARGEND;
quotefmtinstall(); quotefmtinstall();
tmfmtinstall();
if(argc < 3) if(argc < 3)
usage(); usage();

View file

@ -7,15 +7,15 @@
void void
append(int fd, char *mb, char *from, long t) append(int fd, char *mb, char *from, long t)
{ {
char *folder, *s; char *folder;
Tm tm;
int r; int r;
s = ctime(t);
folder = foldername(from, getuser(), mb); folder = foldername(from, getuser(), mb);
r = fappendfolder(0, t, folder, fd); r = fappendfolder(0, t, folder, fd);
if(r == 0) if(r == 0)
werrstr(""); werrstr("");
syslog(0, "mail", "mbappend %s %.28s (%s) %r", mb, s, folder); syslog(0, "mail", "mbappend %s %τ (%s) %r", mb, thedate(&tm), folder);
if(r) if(r)
exits("fail"); exits("fail");
} }
@ -36,6 +36,7 @@ main(int argc, char **argv)
from = nil; from = nil;
t = time(0); t = time(0);
tmfmtinstall();
ARGBEGIN{ ARGBEGIN{
case 't': case 't':
t = strtoul(EARGF(usage()), 0, 0); t = strtoul(EARGF(usage()), 0, 0);

View file

@ -24,6 +24,7 @@ main(int argc, char **argv)
}ARGEND }ARGEND
r = 0; r = 0;
tmfmtinstall();
for(; *argv; argv++) for(; *argv; argv++)
r |= f(getuser(), *argv); r |= f(getuser(), *argv);
if(r) if(r)

View file

@ -235,6 +235,7 @@ main(int argc, char **argv)
}ARGEND }ARGEND
r = 0; r = 0;
tmfmtinstall();
for(; *argv; argv++) for(; *argv; argv++)
r |= f(getuser(), *argv); r |= f(getuser(), *argv);
if(r) if(r)

View file

@ -62,6 +62,7 @@ main(int argc, char **argv)
ARGBEGIN { ARGBEGIN {
} ARGEND; } ARGEND;
tmfmtinstall();
switch(argc){ switch(argc){
case 2: case 2:
exits(check_token(argv[0], argv[1])); exits(check_token(argv[0], argv[1]));

View file

@ -8,9 +8,10 @@ main(int argc, char **argv)
ARGBEGIN{ ARGBEGIN{
}ARGEND }ARGEND
tmfmtinstall();
for(; *argv; argv++) for(; *argv; argv++)
if(strtotm(*argv, &tm) >= 0) if(strtotm(*argv, &tm) >= 0)
print("%s", asctime(&tm)); print("%τ\n", tmfmt(&tm, nil));
else else
print("bad\n"); print("bad\n");
exits(""); exits("");

View file

@ -174,16 +174,15 @@ Afmt(Fmt *f)
static int static int
Δfmt(Fmt *f) Δfmt(Fmt *f)
{ {
char buf[32];
uvlong v; uvlong v;
Tm tm;
v = va_arg(f->args, uvlong); v = va_arg(f->args, uvlong);
if(f->flags & FmtSharp) if(f->flags & FmtSharp)
if((v>>8) == 0) if((v>>8) == 0)
return fmtstrcpy(f, ""); return fmtstrcpy(f, "");
strcpy(buf, ctime(v>>8)); tmtime(&tm, v>>8, tzload("local"));
buf[28] = 0; return fmtprint(f, "", tmfmt(&tm, "WW MMM _D hh:mm:ss Z YYYY"));
return fmtstrcpy(f, buf);
} }
static int static int
@ -320,6 +319,7 @@ main(int argc, char *argv[])
fmtinstall(L'Δ', Δfmt); fmtinstall(L'Δ', Δfmt);
fmtinstall('F', fcallfmt); fmtinstall('F', fcallfmt);
fmtinstall('H', encodefmt); /* forces tls stuff */ fmtinstall('H', encodefmt); /* forces tls stuff */
tmfmtinstall();
quotefmtinstall(); quotefmtinstall();
if(pipe(p) < 0) if(pipe(p) < 0)
error("pipe failed"); error("pipe failed");

View file

@ -366,11 +366,11 @@ datesec(Mailbox *mb, Message *m)
if(m->fileid > 1000000ull<<8) if(m->fileid > 1000000ull<<8)
return; return;
if(m->unixdate && strtotm(m->unixdate, &tm) >= 0) if(m->unixdate && strtotm(m->unixdate, &tm) >= 0)
v = tm2sec(&tm); v = tmnorm(&tm);
else if(m->date822 && strtotm(m->date822, &tm) >= 0) else if(m->date822 && strtotm(m->date822, &tm) >= 0)
v = tm2sec(&tm); v = tmnorm(&tm);
else if(rxtotm(m, &tm) >= 0) else if(rxtotm(m, &tm) >= 0)
v = tm2sec(&tm); v = tmnorm(&tm);
else{ else{
logmsg(gettopmsg(mb, m), "%s:%s: datasec %s %s\n", mb->path, logmsg(gettopmsg(mb, m), "%s:%s: datasec %s %s\n", mb->path,
m->whole? m->whole->name: "?", m->whole? m->whole->name: "?",

View file

@ -34,7 +34,7 @@ chkunix0(char *s, int n)
return -1; return -1;
if(memtotm(p, n - (p - s), &tm) < 0) if(memtotm(p, n - (p - s), &tm) < 0)
return -1; return -1;
if(tm2sec(&tm) < 1000000) if(tmnorm(&tm) < 1000000)
return -1; return -1;
return 0; return 0;
} }

View file

@ -1,142 +1,10 @@
#include "imap4d.h" #include "imap4d.h"
static char *wdayname[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
static char *monname[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
/*
* zone : [A-Za-z][A-Za-z][A-Za-z] some time zone names
* | [A-IK-Z] military time; rfc1123 says the rfc822 spec is wrong.
* | "UT" universal time
* | [+-][0-9][0-9][0-9][0-9]
* zones is the rfc-822 list of time zone names
*/
static Namedint zones[] =
{
{"A", -1 * 3600},
{"B", -2 * 3600},
{"C", -3 * 3600},
{"CDT", -5 * 3600},
{"CST", -6 * 3600},
{"D", -4 * 3600},
{"E", -5 * 3600},
{"EDT", -4 * 3600},
{"EST", -5 * 3600},
{"F", -6 * 3600},
{"G", -7 * 3600},
{"GMT", 0},
{"H", -8 * 3600},
{"I", -9 * 3600},
{"K", -10 * 3600},
{"L", -11 * 3600},
{"M", -12 * 3600},
{"MDT", -6 * 3600},
{"MST", -7 * 3600},
{"N", +1 * 3600},
{"O", +2 * 3600},
{"P", +3 * 3600},
{"PDT", -7 * 3600},
{"PST", -8 * 3600},
{"Q", +4 * 3600},
{"R", +5 * 3600},
{"S", +6 * 3600},
{"T", +7 * 3600},
{"U", +8 * 3600},
{"UT", 0},
{"V", +9 * 3600},
{"W", +10 * 3600},
{"X", +11 * 3600},
{"Y", +12 * 3600},
{"Z", 0},
};
static void
zone2tm(Tm *tm, char *s)
{
int i;
Tm aux, *atm;
if(*s == '+' || *s == '-'){
i = strtol(s, &s, 10);
tm->tzoff = (i/100)*3600 + i%100;
strncpy(tm->zone, "", 4);
return;
}
/*
* look it up in the standard rfc822 table
*/
strncpy(tm->zone, s, 3);
tm->zone[3] = 0;
tm->tzoff = 0;
for(i = 0; i < nelem(zones); i++){
if(cistrcmp(zones[i].name, s) == 0){
tm->tzoff = zones[i].v;
return;
}
}
/*
* one last try: look it up in the current local timezone
* probe a couple of times to get daylight/standard time change.
*/
aux = *tm;
memset(aux.zone, 0, 4);
aux.hour--;
for(i = 0; i < 2; i++){
atm = localtime(tm2sec(&aux));
if(cistrcmp(tm->zone, atm->zone) == 0){
tm->tzoff = atm->tzoff;
return;
}
aux.hour++;
}
strncpy(tm->zone, "GMT", 4);
tm->tzoff = 0;
}
/*
* hh[:mm[:ss]]
*/
static void
time2tm(Tm *tm, char *s)
{
tm->hour = strtoul(s, &s, 10);
if(*s++ != ':')
return;
tm->min = strtoul(s, &s, 10);
if(*s++ != ':')
return;
tm->sec = strtoul(s, &s, 10);
}
static int
dateindex(char *d, char **tab, int n)
{
int i;
for(i = 0; i < n; i++)
if(cistrcmp(d, tab[i]) == 0)
return i;
return -1;
}
int int
imap4date(Tm *tm, char *date) imap4date(Tm *tm, char *date)
{ {
char *flds[4]; if(tmparse(tm, "DD-?MM-YYYY hh:mm:ss ?Z", date, nil, nil) == nil)
if(getfields(date, flds, 3, 0, "-") != 3)
return 0; return 0;
tm->mday = strtol(flds[0], nil, 10);
tm->mon = dateindex(flds[1], monname, 12);
tm->year = strtol(flds[2], nil, 10) - 1900;
return 1; return 1;
} }
@ -146,29 +14,17 @@ imap4date(Tm *tm, char *date)
ulong ulong
imap4datetime(char *date) imap4datetime(char *date)
{ {
char *flds[4], *sflds[4];
ulong t;
Tm tm; Tm tm;
vlong s;
if(getfields(date, flds, 4, 0, " ") != 3) s = -1;
if(tmparse(&tm, "?DD-?MM-YYYY hh:mm:ss ?Z", date, nil, nil) != nil)
s = tmnorm(&tm);
else if(tmparse(&tm, "?W, ?DD-?MM-YYYY hh:mm:ss ?Z", date, nil, nil) != nil)
s = tmnorm(&tm);
if(s > 0 && s < (1ULL<<31))
return s;
return ~0; return ~0;
if(!imap4date(&tm, flds[0]))
return ~0;
if(getfields(flds[1], sflds, 3, 0, ":") != 3)
return ~0;
tm.hour = strtol(sflds[0], nil, 10);
tm.min = strtol(sflds[1], nil, 10);
tm.sec = strtol(sflds[2], nil, 10);
strcpy(tm.zone, "GMT");
tm.yday = 0;
t = tm2sec(&tm);
zone2tm(&tm, flds[2]);
t -= tm.tzoff;
return t;
} }
/* /*
@ -181,85 +37,18 @@ imap4datetime(char *date)
Tm* Tm*
date2tm(Tm *tm, char *date) date2tm(Tm *tm, char *date)
{ {
char *flds[7], *s, dstr[64]; char **f, *fmts[] = {
int n; "?W, ?DD ?MMM YYYY hh:mm:ss ?Z",
Tm gmt, *atm; "?W ?M ?DD hh:mm:ss ?Z YYYY",
"?W, DD-?MM-YY hh:mm:ss ?Z",
"?DD ?MMM YYYY hh:mm:ss ?Z",
"?M ?DD hh:mm:ss ?Z YYYY",
"DD-?MM-YYYY hh:mm:ss ?Z",
nil,
};
/* for(f = fmts; *f; f++)
* default date is Thu Jan 1 00:00:00 GMT 1970 if(tmparse(tm, *f, date, nil, nil) != nil)
*/
tm->wday = 4;
tm->mday = 1;
tm->mon = 1;
tm->hour = 0;
tm->min = 0;
tm->sec = 0;
tm->year = 70;
strcpy(tm->zone, "GMT");
tm->tzoff = 0;
strncpy(dstr, date, sizeof dstr);
dstr[sizeof dstr - 1] = 0;
n = tokenize(dstr, flds, 7);
if(n != 6 && n != 5)
return nil;
if(n == 5){
for(n = 5; n >= 1; n--)
flds[n] = flds[n - 1];
n = 5;
}else{
/*
* Wday[,]
*/
s = strchr(flds[0], ',');
if(s != nil)
*s = 0;
tm->wday = dateindex(flds[0], wdayname, 7);
if(tm->wday < 0)
return nil;
}
/*
* check for the two major formats:
* Month first or day first
*/
tm->mon = dateindex(flds[1], monname, 12);
if(tm->mon >= 0){
tm->mday = strtoul(flds[2], nil, 10);
time2tm(tm, flds[3]);
zone2tm(tm, flds[4]);
tm->year = strtoul(flds[5], nil, 10);
if(strlen(flds[5]) > 2)
tm->year -= 1900;
}else{
tm->mday = strtoul(flds[1], nil, 10);
tm->mon = dateindex(flds[2], monname, 12);
if(tm->mon < 0)
return nil;
tm->year = strtoul(flds[3], nil, 10);
if(strlen(flds[3]) > 2)
tm->year -= 1900;
time2tm(tm, flds[4]);
zone2tm(tm, flds[5]);
}
if(n == 5){
gmt = *tm;
strncpy(gmt.zone, "", 4);
gmt.tzoff = 0;
atm = gmtime(tm2sec(&gmt));
tm->wday = atm->wday;
}else{
/*
* Wday[,]
*/
s = strchr(flds[0], ',');
if(s != nil)
*s = 0;
tm->wday = dateindex(flds[0], wdayname, 7);
if(tm->wday < 0)
return nil;
}
return tm; return tm;
return nil;
} }

View file

@ -215,6 +215,7 @@ main(int argc, char *argv[])
Binit(&bin, dup(0, -1), OREAD); Binit(&bin, dup(0, -1), OREAD);
close(0); close(0);
Binit(&bout, 1, OWRITE); Binit(&bout, 1, OWRITE);
tmfmtinstall();
quotefmtinstall(); quotefmtinstall();
fmtinstall('F', Ffmt); fmtinstall('F', Ffmt);
fmtinstall('D', Dfmt); /* rfc822; # imap date %Z */ fmtinstall('D', Dfmt); /* rfc822; # imap date %Z */
@ -501,6 +502,8 @@ appendcmd(char *tg, char *cmd)
char *mbox, head[128]; char *mbox, head[128];
uint t, n, now; uint t, n, now;
int flags, ok; int flags, ok;
Tzone *tz;
Tm tm;
Uidplus u; Uidplus u;
mustbe(' '); mustbe(' ');
@ -536,7 +539,9 @@ appendcmd(char *tg, char *cmd)
return; return;
} }
snprint(head, sizeof head, "From %s %s", username, ctime(t)); tz = tzload("local");
tmtime(&tm, t, tz);
snprint(head, sizeof head, "From %s %τ", username, tmfmt(&tm, "WW MMM _D hh:mm:ss Z YYYY"));
ok = appendsave(mbox, flags, head, &bin, n, &u); ok = appendsave(mbox, flags, head, &bin, n, &u);
crnl(); crnl();
check(); check();

View file

@ -1,7 +1,5 @@
#include "nlist.c" #include "nlist.c"
char username[] = "quanstro";
char mboxdir[] = "/mail/box/quanstro/";
Biobuf bout; Biobuf bout;
Bin *parsebin; Bin *parsebin;

View file

@ -90,40 +90,25 @@ Xfmt(Fmt *f)
return fmtstrcpy(f, encfs(buf, sizeof buf, s)); return fmtstrcpy(f, encfs(buf, sizeof buf, s));
} }
static char *day[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
};
static char *mon[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
int int
Dfmt(Fmt *f) Dfmt(Fmt *f)
{ {
char buf[128], *p, *e, *sgn, *fmt; char buf[128], *fmt;
int off; Tm *tm, t;
Tm *tm; Tzone *tz;
tm = va_arg(f->args, Tm*); tm = va_arg(f->args, Tm*);
if(tm == nil) if(tm == nil){
tm = localtime(time(0)); tz = tzload("local");
sgn = "+"; tm = tmtime(&t, time(0), tz);
if(tm->tzoff < 0) }
sgn = "";
e = buf + sizeof buf;
p = buf;
off = (tm->tzoff/3600)*100 + (tm->tzoff/60)%60;
if((f->flags & FmtSharp) == 0){ if((f->flags & FmtSharp) == 0){
/* rfc822 style */ /* rfc822 style */
fmt = "%.2d %s %.4d %.2d:%.2d:%.2d %s%.4d"; fmt = "WW, DD MMM YYYY hh:mm:ss Z";
p = seprint(p, e, "%s, ", day[tm->wday]);
}else }else
fmt = "%2d-%s-%.4d %2.2d:%2.2d:%2.2d %s%4.4d"; fmt = "DD-MMM-YYYY hh:mm:ss Z";
seprint(p, e, fmt,
tm->mday, mon[tm->mon], tm->year + 1900, tm->hour, tm->min, tm->sec,
sgn, off);
if(f->r == L'δ') if(f->r == L'δ')
return fmtstrcpy(f, buf); return fmtprint(f, "", tmfmt(tm, fmt));
snprint(buf, sizeof(buf), "", tmfmt(tm, fmt));
return fmtprint(f, "%Z", buf); return fmtprint(f, "%Z", buf);
} }

View file

@ -140,6 +140,7 @@ int attachfailed;
char lastchar; char lastchar;
char *replymsg; char *replymsg;
#define Rfc822fmt "WW, DD MMM YYYY hh:mm:ss Z"
enum enum
{ {
Ok = 0, Ok = 0,
@ -208,6 +209,7 @@ main(int argc, char **argv)
hdrstring = nil; hdrstring = nil;
ccargc = bccargc = 0; ccargc = bccargc = 0;
tmfmtinstall();
quotefmtinstall(); quotefmtinstall();
fmtinstall('Z', doublequote); fmtinstall('Z', doublequote);
fmtinstall('U', rfc2047fmt); fmtinstall('U', rfc2047fmt);
@ -792,29 +794,13 @@ attachment(Attach *a, Biobuf *out)
Bterm(f); Bterm(f);
} }
char *ascwday[] =
{
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
char *ascmon[] =
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
int int
printdate(Biobuf *b) printdate(Biobuf *b)
{ {
int tz;
Tm *tm; Tm *tm;
tm = localtime(time(0)); tm = localtime(time(0));
tz = (tm->tzoff/3600)*100 + (tm->tzoff/60)%60; return Bprint(b, "Date: %τ\n", tmfmt(tm, Rfc822fmt));
return Bprint(b, "Date: %s, %d %s %d %2.2d:%2.2d:%2.2d %s%.4d\n",
ascwday[tm->wday], tm->mday, ascmon[tm->mon], 1900 + tm->year,
tm->hour, tm->min, tm->sec, tz>=0?"+":"", tz);
} }
int int
@ -1003,16 +989,10 @@ tee(int in, int out1, int out2)
int int
printunixfrom(int fd) printunixfrom(int fd)
{ {
int tz;
Tm *tm; Tm *tm;
tm = localtime(time(0)); tm = localtime(time(0));
tz = (tm->tzoff/3600)*100 + (tm->tzoff/60)%60; return fprint(fd, "From %s %τ\n", user, tmfmt(tm, Rfc822fmt));
return fprint(fd, "From %s %s %s %d %2.2d:%2.2d:%2.2d %s%.4d %d\n",
user,
ascwday[tm->wday], ascmon[tm->mon], tm->mday,
tm->hour, tm->min, tm->sec, tz>=0?"+":"", tz, 1900 + tm->year);
} }
char *specialfile[] = char *specialfile[] =

View file

@ -102,6 +102,8 @@ main(int argc, char **argv)
Binit(&in, 0, OREAD); Binit(&in, 0, OREAD);
Binit(&out, 1, OWRITE); Binit(&out, 1, OWRITE);
tmfmtinstall();
ARGBEGIN{ ARGBEGIN{
case 'a': case 'a':
loggedin = 1; loggedin = 1;

View file

@ -400,18 +400,16 @@ Biobuf*
opendump(char *sender) opendump(char *sender)
{ {
int i; int i;
Tm tm;
ulong h; ulong h;
char buf[512]; char buf[512];
Biobuf *b; Biobuf *b;
char *cp; char *cp, mon[8], day[4];
cp = ctime(time(0)); tmnow(&tm, nil);
cp[7] = 0; snprint(mon, sizeof(mon), "", tmfmt(&tm, "MMM"));
cp[10] = 0; snprint(day, sizeof(day), "", tmfmt(&tm, "D"));
if(cp[8] == ' ') snprint(buf, sizeof buf, "%s/queue.dump/%s%s", SPOOL, mon, day);
snprint(buf, sizeof buf, "%s/queue.dump/%s%c", SPOOL, cp+4, cp[9]);
else
snprint(buf, sizeof buf, "%s/queue.dump/%s%c%c", SPOOL, cp+4, cp[8], cp[9]);
cp = buf+strlen(buf); cp = buf+strlen(buf);
if(access(buf, 0) < 0 && sysmkdir(buf, 0777) < 0){ if(access(buf, 0) < 0 && sysmkdir(buf, 0777) < 0){
syslog(0, "smtpd", "couldn't dump mail from %s: %r", sender); syslog(0, "smtpd", "couldn't dump mail from %s: %r", sender);

View file

@ -66,6 +66,7 @@ main(int argc, char *argv[])
usage(); usage();
}ARGEND }ARGEND
tmfmtinstall();
if(*argv == 0) if(*argv == 0)
usage(); usage();
dp = 0; dp = 0;
@ -404,20 +405,22 @@ static int
replymsg(String *errstring, message *mp, dest *dp) replymsg(String *errstring, message *mp, dest *dp)
{ {
message *refp = m_new(); message *refp = m_new();
dest *ndp;
char *rcvr;
int rv;
String *boundary; String *boundary;
dest *ndp;
char *rcvr, now[128];
int rv;
Tm tm;
boundary = mkboundary(); boundary = mkboundary();
refp->bulk = 1; refp->bulk = 1;
refp->rfc822headers = 1; refp->rfc822headers = 1;
snprint(now, sizeof(now), "", thedate(&tm));
rcvr = dp->status==d_eloop ? "postmaster" : s_to_c(mp->replyaddr); rcvr = dp->status==d_eloop ? "postmaster" : s_to_c(mp->replyaddr);
ndp = d_new(s_copy(rcvr)); ndp = d_new(s_copy(rcvr));
s_append(refp->sender, "postmaster"); s_append(refp->sender, "postmaster");
s_append(refp->replyaddr, "/dev/null"); s_append(refp->replyaddr, "/dev/null");
s_append(refp->date, thedate()); s_append(refp->date, now);
refp->haveto = 1; refp->haveto = 1;
s_append(refp->body, "To: "); s_append(refp->body, "To: ");
s_append(refp->body, rcvr); s_append(refp->body, rcvr);

View file

@ -21,10 +21,12 @@ static String* getaddr(Node *p);
int int
default_from(message *mp) default_from(message *mp)
{ {
char *cp, *lp; char *cp, *lp, now[128];
Tm tm;
cp = getenv("upasname"); cp = getenv("upasname");
lp = getlog(); lp = getlog();
snprint(now, sizeof(now), "", thedate(&tm));
if(lp == nil){ if(lp == nil){
free(cp); free(cp);
return -1; return -1;
@ -34,7 +36,7 @@ default_from(message *mp)
else else
s_append(mp->sender, lp); s_append(mp->sender, lp);
free(cp); free(cp);
s_append(mp->date, thedate()); s_append(mp->date, now);
return 0; return 0;
} }

View file

@ -131,8 +131,10 @@ main(int argc, char **argv)
int i, ok, rcvrs, bustedmx; int i, ok, rcvrs, bustedmx;
String *from, *fromm, *sender; String *from, *fromm, *sender;
Mx mx; Mx mx;
Tm tm;
alarmscale = 60*1000; /* minutes */ alarmscale = 60*1000; /* minutes */
tmfmtinstall();
quotefmtinstall(); quotefmtinstall();
mailfmtinstall(); /* 2047 encoding */ mailfmtinstall(); /* 2047 encoding */
fmtinstall('D', Dfmt); fmtinstall('D', Dfmt);
@ -309,7 +311,7 @@ main(int argc, char **argv)
/* /*
* here when some but not all rcvrs failed * here when some but not all rcvrs failed
*/ */
fprint(2, "%s connect to %s: %D %s:\n", thedate(), addr, &mx, phase); fprint(2, "%τ connect to %s: %D %s:\n", thedate(&tm), addr, &mx, phase);
for(i = 0; i < rcvrs; i++){ for(i = 0; i < rcvrs; i++){
if(errs[i]){ if(errs[i]){
syslog(0, "smtp.fail", "delivery to %s at %s %D %s, failed: %s", syslog(0, "smtp.fail", "delivery to %s at %s %D %s, failed: %s",
@ -335,7 +337,7 @@ error:
} }
syslog(0, "smtp.fail", "%s %s at %s %D %s failed: %s", syslog(0, "smtp.fail", "%s %s at %s %D %s failed: %s",
deliverytype(), allrx, addr, &mx, phase, s_to_c(reply)); deliverytype(), allrx, addr, &mx, phase, s_to_c(reply));
fprint(2, "%s connect to %s %D %s:\n%s\n", thedate(), addr, &mx, phase, s_to_c(reply)); fprint(2, "%τ connect to %s %D %s:\n%s\n", thedate(&tm), addr, &mx, phase, s_to_c(reply));
if(!filter) if(!filter)
quit(rv); quit(rv);
exits(rv); exits(rv);

View file

@ -92,8 +92,10 @@ main(int argc, char **argv)
{ {
char *netdir; char *netdir;
char buf[1024]; char buf[1024];
Tm tm;
netdir = nil; netdir = nil;
tmfmtinstall();
quotefmtinstall(); quotefmtinstall();
fmtinstall('I', eipfmt); fmtinstall('I', eipfmt);
fmtinstall('[', encodefmt); fmtinstall('[', encodefmt);
@ -163,7 +165,7 @@ main(int argc, char **argv)
snprint(buf, sizeof(buf), "%s/smtpd.db", UPASLOG); snprint(buf, sizeof(buf), "%s/smtpd.db", UPASLOG);
if (open(buf, OWRITE) >= 0) { if (open(buf, OWRITE) >= 0) {
seek(2, 0, 2); seek(2, 0, 2);
fprint(2, "%d smtpd %s\n", getpid(), thedate()); fprint(2, "%d smtpd %τ\n", getpid(), thedate(&tm));
} else } else
debug = 0; debug = 0;
} }
@ -1169,6 +1171,7 @@ pipemsg(int *byteswritten)
char *cp; char *cp;
int n, nbytes, sawdot, status; int n, nbytes, sawdot, status;
String *hdr, *line; String *hdr, *line;
Tm tm;
pipesig(&status); /* set status to 1 on write to closed pipe */ pipesig(&status); /* set status to 1 on write to closed pipe */
sawdot = 0; sawdot = 0;
@ -1180,12 +1183,12 @@ pipemsg(int *byteswritten)
* add a 'From ' line as envelope and Received: stamp * add a 'From ' line as envelope and Received: stamp
*/ */
nbytes = 0; nbytes = 0;
nbytes += Bprint(pp->std[0]->fp, "From %s %s remote from \n", nbytes += Bprint(pp->std[0]->fp, "From %s %τ remote from \n",
s_to_c(senders.first->p), thedate()); s_to_c(senders.first->p), thedate(&tm));
nbytes += Bprint(pp->std[0]->fp, "Received: from %s ", him); nbytes += Bprint(pp->std[0]->fp, "Received: from %s ", him);
if(nci->rsys) if(nci->rsys)
nbytes += Bprint(pp->std[0]->fp, "([%s]) ", nci->rsys); nbytes += Bprint(pp->std[0]->fp, "([%s]) ", nci->rsys);
nbytes += Bprint(pp->std[0]->fp, "by %s; %s\n", me, thedate()); nbytes += Bprint(pp->std[0]->fp, "by %s; %τ\n", me, thedate(&tm));
/* /*
* read first 16k obeying '.' escape. we're assuming * read first 16k obeying '.' escape. we're assuming

View file

@ -417,17 +417,15 @@ char*
dumpfile(char *sender) dumpfile(char *sender)
{ {
int i, fd; int i, fd;
Tm tm;
ulong h; ulong h;
static char buf[512]; static char buf[512];
char *cp; char *cp, mon[8], day[4];
if (sflag == 1){ if (sflag == 1){
cp = ctime(time(0)); snprint(mon, sizeof(mon), "", tmfmt(&tm, "MMM"));
cp[7] = 0; snprint(day, sizeof(day), "", tmfmt(&tm, "D"));
if(cp[8] == ' ') snprint(buf, sizeof buf, "%s/queue.dump/%s%s", SPOOL, mon, day);
sprint(buf, "%s/queue.dump/%s%c", SPOOL, cp + 4, cp[9]);
else
sprint(buf, "%s/queue.dump/%s%c%c", SPOOL, cp + 4, cp[8], cp[9]);
cp = buf + strlen(buf); cp = buf + strlen(buf);
if(access(buf, 0) < 0 && sysmkdir(buf, 0777) < 0) if(access(buf, 0) < 0 && sysmkdir(buf, 0777) < 0)
return "/dev/null"; return "/dev/null";

View file

@ -372,7 +372,7 @@ static int
save(Part *p, char *file) save(Part *p, char *file)
{ {
int fd; int fd;
char *cp; Tm tm;
Bterm(&out); Bterm(&out);
memset(&out, 0, sizeof(out)); memset(&out, 0, sizeof(out));
@ -382,9 +382,7 @@ save(Part *p, char *file)
return -1; return -1;
seek(fd, 0, 2); seek(fd, 0, 2);
Binit(&out, fd, OWRITE); Binit(&out, fd, OWRITE);
cp = ctime(time(0)); Bprint(&out, "From virusfilter %τ\n", thedate(&tm));
cp[28] = 0;
Bprint(&out, "From virusfilter %s\n", cp);
writeheader(p, 0); writeheader(p, 0);
bodyoff = Boffset(&out); bodyoff = Boffset(&out);
passbody(p, 1); passbody(p, 1);