nightmaremail

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

hfield.c (1725B)


      1 #include "hfield.h"
      2 
      3 static char *(hname[]) = {
      4   "unknown-header"
      5 , "sender"
      6 , "from"
      7 , "reply-to"
      8 , "to"
      9 , "cc"
     10 , "bcc"
     11 , "date"
     12 , "message-id"
     13 , "subject"
     14 , "resent-sender"
     15 , "resent-from"
     16 , "resent-reply-to"
     17 , "resent-to"
     18 , "resent-cc"
     19 , "resent-bcc"
     20 , "resent-date"
     21 , "resent-message-id"
     22 , "return-receipt-to"
     23 , "errors-to"
     24 , "apparently-to"
     25 , "received"
     26 , "return-path"
     27 , "delivered-to"
     28 , "content-length"
     29 , "content-type"
     30 , "content-transfer-encoding"
     31 , "notice-requested-upon-delivery-to"
     32 , "mail-followup-to"
     33 , 0
     34 };
     35 
     36 static int hmatch(s,len,t)
     37 char *s;
     38 int len;
     39 char *t;
     40 {
     41  int i;
     42  char ch;
     43 
     44  for (i = 0;(ch = t[i]);++i)
     45   {
     46    if (i >= len) return 0;
     47    if (ch != s[i])
     48     {
     49      if (ch == '-') return 0;
     50      if (ch - 32 != s[i]) return 0;
     51     }
     52   }
     53  for (;;)
     54   {
     55    if (i >= len) return 0;
     56    ch = s[i];
     57    if (ch == ':') return 1;
     58    if ((ch != ' ') && (ch != '\t')) return 0;
     59    ++i;
     60   }
     61 }
     62 
     63 int hfield_known(s,len)
     64 char *s;
     65 int len;
     66 {
     67  int i;
     68  char *t;
     69 
     70  for (i = 1;(t = hname[i]);++i)
     71    if (hmatch(s,len,t))
     72      return i;
     73  return 0;
     74 }
     75 
     76 int hfield_valid(s,len)
     77 char *s;
     78 int len;
     79 {
     80  int i;
     81  int j;
     82  char ch;
     83 
     84  for (j = 0;j < len;++j)
     85    if (s[j] == ':')
     86      break;
     87  if (j >= len) return 0;
     88  while (j)
     89   {
     90    ch = s[j - 1];
     91    if ((ch != ' ') && (ch != '\t'))
     92      break;
     93    --j;
     94   }
     95  if (!j) return 0;
     96 
     97  for (i = 0;i < j;++i)
     98   {
     99    ch = s[i];
    100    if (ch <= 32) return 0;
    101    if (ch >= 127) return 0;
    102   }
    103  return 1;
    104 }
    105 
    106 unsigned int hfield_skipname(s,len)
    107 char *s;
    108 int len;
    109 {
    110  int i;
    111  char ch;
    112 
    113  for (i = 0;i < len;++i)
    114    if (s[i] == ':')
    115      break;
    116  if (i < len) ++i;
    117  while (i < len)
    118   {
    119    ch = s[i];
    120    if ((ch != '\t') && (ch != '\n') && (ch != '\r') && (ch != ' '))
    121      break;
    122    ++i;
    123   }
    124  return i;
    125 }