11 static char *hdrs
[NHDRS
]; /* included headers */
13 static char pn_buf
[4096]; /* last line */
14 static char pn_rev
; /* push back the last line */
15 static int maxlen
= -1; /* body length to include */
16 static char *pn_path
; /* input path */
17 static FILE *pn_fp
; /* input file */
18 static long pn_pos
; /* file position */
19 static int pn_num
; /* message number */
21 static char *lnext(void)
27 pn_pos
+= strlen(pn_buf
);
28 return fgets(pn_buf
, sizeof(pn_buf
), pn_fp
);
31 static void lback(void)
36 static int hdrs_add(char *hdr
)
43 static int hdrs_find(char *ln
)
46 for (i
= 0; i
< hdrs_n
; i
++)
47 if (startswith(ln
, hdrs
[i
]))
52 static int from_(char *s
)
54 return s
&& s
[0] == 'F' && s
[1] == 'r' && s
[2] == 'o' &&
55 s
[3] == 'm' && s
[4] == ' ';
58 static int pn_one(void)
63 while ((ln
= lnext())) {
72 while ((ln
= lnext())) {
73 if (from_(ln
) || ln
[0] == '\n') {
77 if (ln
[0] != ' ' && ln
[0] != '\t')
78 hdrout
= hdrs_find(ln
) >= 0;
84 while ((ln
= lnext())) {
89 if (maxlen
< 0 || pn_pos
- body
+ strlen(ln
) < maxlen
)
92 if (pn_path
&& maxlen
== 0)
93 printf("Neatmail-Source: %d@%s %ld %ld\n", pn_num
, pn_path
, beg
, pn_pos
);
94 if (maxlen
>= 0 && pn_pos
- body
>= maxlen
)
99 static int pn_proc(char *path
)
101 if (path
&& (pn_fp
= fopen(path
, "r")) == NULL
)
109 while (pn_one() == 0)
113 fprintf(stderr
, "%s: %d messages\n", path
? path
: "stdin", pn_num
);
118 "usage: neatmail pn [options] [imbox] <imbox >ombox\n\n"
120 " -h hdr \tspecify headers to include\n"
121 " -H \tinclude the default set of headers\n"
122 " -s size \tmaximum message body length to include\n";
126 char *path
[16] = {NULL
};
133 for (i
= 0; argv
[i
] && argv
[i
][0] == '-'; i
++) {
134 if (argv
[i
][1] == 'h') {
135 hdrs_add(argv
[i
][2] ? argv
[i
] + 2 : argv
[++i
]);
138 if (argv
[i
][1] == 'H') {
143 hdrs_add("Subject:");
145 hdrs_add("Message-ID:");
146 hdrs_add("Reply-To:");
147 hdrs_add("In-Reply-To:");
148 hdrs_add("References:");
149 hdrs_add("MIME-Version:");
150 hdrs_add("Content-Type:");
151 hdrs_add("Content-Transfer-Encoding:");
152 hdrs_add("User-Agent:");
153 hdrs_add("X-Mailer:");
154 hdrs_add("Organization:");
156 hdrs_add("Neatmail");
159 if (argv
[i
][1] == 's') {
160 maxlen
= atoi(argv
[i
][2] ? argv
[i
] + 2 : argv
[++i
]);
163 if (argv
[i
][1] == 'b') {
164 path
[path_n
++] = argv
[i
][2] ? argv
[i
] + 2 : argv
[++i
];
169 path
[path_n
++] = argv
[i
];
170 for (i
= 0; i
< path_n
; i
++)
171 if (pn_proc(path
[i
]) != 0)
172 fprintf(stderr
, "pn: cannot open <%s>\n", path
[i
]);