trfc5322.c - scribo - Email-based phlog generator
(HTM) git clone git://git.z3bra.org/scribo.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
trfc5322.c (1155B)
---
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <time.h>
6
7 #include "rfc5322.h"
8
9 #define HDRSIZ 997
10
11 #ifndef strlcpy
12 size_t strlcpy(char *dst, const char *src, size_t siz);
13 #endif
14 #ifndef strlcat
15 size_t strlcat(char *dst, const char *src, size_t siz);
16 #endif
17
18 char *
19 rfc5322_headername(const char *s)
20 {
21 static char n[HDRSIZ];
22 char *p;
23
24 strlcpy(n, s, sizeof(n));
25
26 p = n;
27 return strsep(&p, ":");
28 }
29
30 char *
31 rfc5322_headerbody(const char *s)
32 {
33 static char n[BUFSIZ + HDRSIZ + 1];
34 char *p;
35
36 strlcpy(n, s, sizeof(n));
37
38 p = n + strlen(rfc5322_headername(s)) + 1;
39 while (isblank(*p)) p++;
40
41 return strsep(&p, "\r\n");
42 }
43
44 size_t
45 rfc5322_unfold(char *body, char *line, size_t n)
46 {
47 /* trim leading whitespace when current body is empty */
48 if (strnlen(body, n) == 0)
49 while (isblank(*line)) line++;
50
51 return strlcat(body, strsep(&line, "\r\n"), n);
52 }
53
54 char *
55 rfc5322_addr(const char *s)
56 {
57 static char addr[HDRSIZ];
58 char *p;
59
60 if (!(p = strrchr(s, '<'))) {
61 strlcpy(addr, s, HDRSIZ);
62 return addr;
63 }
64
65 strlcpy(addr, p + 1, HDRSIZ);
66 if ((p = strchr(addr, '>'))) {
67 *p = '\0';
68 return addr;
69 }
70
71 return NULL;
72 }