From 89b7b67a13ebb7965cc7f13ad0595e2194a2d34c Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Wed, 3 Jul 2024 15:48:04 +0200 Subject: add sqmail-4.2.29a --- src/hfield.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/hfield.c (limited to 'src/hfield.c') diff --git a/src/hfield.c b/src/hfield.c new file mode 100644 index 0000000..2376e1f --- /dev/null +++ b/src/hfield.c @@ -0,0 +1,113 @@ +#include "hfield.h" + +static char *(hname[]) = { + "unknown-header" +, "sender" +, "from" +, "reply-to" +, "to" +, "cc" +, "bcc" +, "date" +, "message-id" +, "subject" +, "resent-sender" +, "resent-from" +, "resent-reply-to" +, "resent-to" +, "resent-cc" +, "resent-bcc" +, "resent-date" +, "resent-message-id" +, "return-receipt-to" +, "errors-to" +, "apparently-to" +, "received" +, "return-path" +, "delivered-to" +, "content-length" +, "content-type" +, "content-transfer-encoding" +, "notice-requested-upon-delivery-to" +, "mail-followup-to" +, 0 +}; + +static int hmatch( char *s,int len,char *t) +{ + int i; + char ch; + + for (i = 0; (ch = t[i]); ++i) { + if (i >= len) return 0; + if (ch != s[i]) { + if (ch == '-') return 0; + if (ch - 32 != s[i]) return 0; + } + } + for (;;) { + if (i >= len) return 0; + ch = s[i]; + if (ch == ':') return 1; + if ((ch != ' ') && (ch != '\t')) return 0; + ++i; + } +} + +int hfield_known(char *s,int len) +{ + int i; + char *t; + + for (i = 1; (t = hname[i]); ++i) + if (hmatch(s,len,t)) + return i; + + return 0; +} + +int hfield_valid(char *s,int len) +{ + int i; + int j; + char ch; + + for (j = 0; j < len; ++j) + if (s[j] == ':') break; + + if (j >= len) return 0; + + while (j) { + ch = s[j - 1]; + if ((ch != ' ') && (ch != '\t')) + break; + --j; + } + if (!j) return 0; + + for (i = 0; i < j; ++i) { + ch = s[i]; + if (ch <= 32) return 0; + if (ch >= 127) return 0; + } + return 1; +} + +unsigned int hfield_skipname(char *s,int len) +{ + int i; + char ch; + + for (i = 0; i < len; ++i) + if (s[i] == ':') break; + + if (i < len) ++i; + while (i < len) { + ch = s[i]; + if ((ch != '\t') && (ch != '\n') && (ch != '\r') && (ch != ' ')) + break; + ++i; + } + + return i; +} -- cgit v1.2.3