nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

newfield.c (1903B)


      1 #include "newfield.h"
      2 
      3 #include <unistd.h>
      4 #include "fmt.h"
      5 #include "datetime.h"
      6 #include "stralloc.h"
      7 #include "date822fmt.h"
      8 
      9 /* "Date: 26 Sep 1995 04:46:53 -0000\n" */
     10 stralloc newfield_date = {0};
     11 /* "Message-ID: <19950926044653.12345.qmail@silverton.berkeley.edu>\n" */
     12 stralloc newfield_msgid = {0};
     13 
     14 static unsigned int datefmt(s,when)
     15 char *s;
     16 datetime_sec when;
     17 {
     18  unsigned int i;
     19  unsigned int len;
     20  struct datetime dt;
     21  datetime_tai(&dt,when);
     22  len = 0;
     23  i = fmt_str(s,"Date: "); len += i; if (s) s += i;
     24  i = date822fmt(s,&dt); len += i; if (s) s += i;
     25  return len;
     26 }
     27 
     28 static unsigned int msgidfmt(s,idhost,idhostlen,when)
     29 char *s;
     30 char *idhost;
     31 int idhostlen;
     32 datetime_sec when;
     33 {
     34  unsigned int i;
     35  unsigned int len;
     36  struct datetime dt;
     37  datetime_tai(&dt,when);
     38  len = 0;
     39  i = fmt_str(s,"Message-ID: <"); len += i; if (s) s += i;
     40  i = fmt_uint(s,dt.year + 1900); len += i; if (s) s += i;
     41  i = fmt_uint0(s,dt.mon + 1,2); len += i; if (s) s += i;
     42  i = fmt_uint0(s,dt.mday,2); len += i; if (s) s += i;
     43  i = fmt_uint0(s,dt.hour,2); len += i; if (s) s += i;
     44  i = fmt_uint0(s,dt.min,2); len += i; if (s) s += i;
     45  i = fmt_uint0(s,dt.sec,2); len += i; if (s) s += i;
     46  i = fmt_str(s,"."); len += i; if (s) s += i;
     47  i = fmt_uint(s,getpid()); len += i; if (s) s += i;
     48  i = fmt_str(s,".qmail@"); len += i; if (s) s += i;
     49  i = fmt_strn(s,idhost,idhostlen); len += i; if (s) s += i;
     50  i = fmt_str(s,">\n"); len += i; if (s) s += i;
     51  return len;
     52 }
     53 
     54 int newfield_datemake(when)
     55 datetime_sec when;
     56 {
     57  if (!stralloc_ready(&newfield_date,datefmt(FMT_LEN,when))) return 0;
     58  newfield_date.len = datefmt(newfield_date.s,when);
     59  return 1;
     60 }
     61 
     62 int newfield_msgidmake(idhost,idhostlen,when)
     63 char *idhost;
     64 int idhostlen;
     65 datetime_sec when;
     66 {
     67  if (!stralloc_ready(&newfield_msgid,msgidfmt(FMT_LEN,idhost,idhostlen,when))) return 0;
     68  newfield_msgid.len = msgidfmt(newfield_msgid.s,idhost,idhostlen,when);
     69  return 1;
     70 }