2005-04-12 06:46:50 +00:00
|
|
|
/*
|
|
|
|
* Another stupid program, this one parsing the headers of an
|
|
|
|
* email to figure out authorship and subject
|
|
|
|
*/
|
2005-11-28 00:29:38 +00:00
|
|
|
#include "cache.h"
|
2006-06-13 20:21:50 +00:00
|
|
|
#include "builtin.h"
|
2006-12-24 07:36:55 +00:00
|
|
|
#include "utf8.h"
|
2008-07-13 18:30:12 +00:00
|
|
|
#include "strbuf.h"
|
2005-04-12 06:46:50 +00:00
|
|
|
|
2015-10-14 22:40:04 +00:00
|
|
|
static FILE *cmitmsg, *patchfile;
|
2005-04-12 06:46:50 +00:00
|
|
|
|
2015-10-19 05:22:10 +00:00
|
|
|
struct mailinfo {
|
2015-10-14 22:40:04 +00:00
|
|
|
FILE *input;
|
|
|
|
FILE *output;
|
|
|
|
|
2015-10-19 05:22:10 +00:00
|
|
|
struct strbuf name;
|
|
|
|
struct strbuf email;
|
2015-10-14 22:39:37 +00:00
|
|
|
int keep_subject;
|
|
|
|
int keep_non_patch_brackets_in_subject;
|
2015-10-19 05:27:56 +00:00
|
|
|
int add_message_id;
|
2015-10-14 23:14:57 +00:00
|
|
|
int use_scissors;
|
|
|
|
int use_inbody_headers;
|
2015-10-14 23:15:40 +00:00
|
|
|
const char *metainfo_charset;
|
2015-10-14 23:13:34 +00:00
|
|
|
|
2015-10-19 05:30:08 +00:00
|
|
|
struct strbuf charset;
|
2015-10-19 05:27:56 +00:00
|
|
|
char *message_id;
|
2015-10-14 23:16:05 +00:00
|
|
|
enum {
|
|
|
|
TE_DONTCARE, TE_QP, TE_BASE64
|
|
|
|
} transfer_encoding;
|
2015-10-14 23:13:51 +00:00
|
|
|
int patch_lines;
|
2015-10-14 23:13:34 +00:00
|
|
|
int filter_stage; /* still reading log or are we copying patch? */
|
|
|
|
int header_stage; /* still checking in-body headers? */
|
2015-10-19 05:22:10 +00:00
|
|
|
};
|
2005-04-12 06:46:50 +00:00
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
static struct strbuf **p_hdr_data, **s_hdr_data;
|
2007-03-12 19:52:04 +00:00
|
|
|
|
|
|
|
#define MAX_BOUNDARIES 5
|
2005-08-28 19:33:16 +00:00
|
|
|
|
2015-10-15 00:44:26 +00:00
|
|
|
static void cleanup_space(struct strbuf *sb)
|
|
|
|
{
|
|
|
|
size_t pos, cnt;
|
|
|
|
for (pos = 0; pos < sb->len; pos++) {
|
|
|
|
if (isspace(sb->buf[pos])) {
|
|
|
|
sb->buf[pos] = ' ';
|
|
|
|
for (cnt = 0; isspace(sb->buf[pos + cnt + 1]); cnt++);
|
|
|
|
strbuf_remove(sb, pos + 1, cnt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-01 17:45:05 +00:00
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
static void get_sane_name(struct strbuf *out, struct strbuf *name, struct strbuf *email)
|
2005-04-12 06:46:50 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
struct strbuf *src = name;
|
|
|
|
if (name->len < 3 || 60 < name->len || strchr(name->buf, '@') ||
|
|
|
|
strchr(name->buf, '<') || strchr(name->buf, '>'))
|
|
|
|
src = email;
|
|
|
|
else if (name == out)
|
|
|
|
return;
|
|
|
|
strbuf_reset(out);
|
|
|
|
strbuf_addbuf(out, src);
|
2005-04-12 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 05:22:10 +00:00
|
|
|
static void parse_bogus_from(struct mailinfo *mi, const struct strbuf *line)
|
2005-12-15 00:31:06 +00:00
|
|
|
{
|
|
|
|
/* John Doe <johndoe> */
|
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
char *bra, *ket;
|
2005-12-15 00:31:06 +00:00
|
|
|
/* This is fallback, so do not bother if we already have an
|
|
|
|
* e-mail address.
|
2006-06-13 20:21:50 +00:00
|
|
|
*/
|
2015-10-19 05:22:10 +00:00
|
|
|
if (mi->email.len)
|
2008-07-13 18:30:12 +00:00
|
|
|
return;
|
2005-12-15 00:31:06 +00:00
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
bra = strchr(line->buf, '<');
|
2005-12-15 00:31:06 +00:00
|
|
|
if (!bra)
|
2008-07-13 18:30:12 +00:00
|
|
|
return;
|
2005-12-15 00:31:06 +00:00
|
|
|
ket = strchr(bra, '>');
|
|
|
|
if (!ket)
|
2008-07-13 18:30:12 +00:00
|
|
|
return;
|
2005-12-15 00:31:06 +00:00
|
|
|
|
2015-10-19 05:22:10 +00:00
|
|
|
strbuf_reset(&mi->email);
|
|
|
|
strbuf_add(&mi->email, bra + 1, ket - bra - 1);
|
2008-07-13 18:30:12 +00:00
|
|
|
|
2015-10-19 05:22:10 +00:00
|
|
|
strbuf_reset(&mi->name);
|
|
|
|
strbuf_add(&mi->name, line->buf, bra - line->buf);
|
|
|
|
strbuf_trim(&mi->name);
|
|
|
|
get_sane_name(&mi->name, &mi->name, &mi->email);
|
2005-12-15 00:31:06 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 05:22:10 +00:00
|
|
|
static void handle_from(struct mailinfo *mi, const struct strbuf *from)
|
2005-04-12 06:46:50 +00:00
|
|
|
{
|
2006-05-23 19:58:36 +00:00
|
|
|
char *at;
|
2008-07-13 18:30:12 +00:00
|
|
|
size_t el;
|
|
|
|
struct strbuf f;
|
2005-04-12 06:46:50 +00:00
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_init(&f, from->len);
|
|
|
|
strbuf_addbuf(&f, from);
|
|
|
|
|
|
|
|
at = strchr(f.buf, '@');
|
|
|
|
if (!at) {
|
2015-10-19 05:22:10 +00:00
|
|
|
parse_bogus_from(mi, from);
|
2008-07-13 18:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-04-12 06:46:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we already have one email, don't take any confusing lines
|
|
|
|
*/
|
2015-10-19 05:22:10 +00:00
|
|
|
if (mi->email.len && strchr(at + 1, '@')) {
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_release(&f);
|
|
|
|
return;
|
|
|
|
}
|
2005-04-12 06:46:50 +00:00
|
|
|
|
2005-08-28 19:33:16 +00:00
|
|
|
/* Pick up the string around '@', possibly delimited with <>
|
2008-07-13 18:30:12 +00:00
|
|
|
* pair; that is the email part.
|
2005-08-28 19:33:16 +00:00
|
|
|
*/
|
2008-07-13 18:30:12 +00:00
|
|
|
while (at > f.buf) {
|
2005-04-12 06:46:50 +00:00
|
|
|
char c = at[-1];
|
2005-08-28 19:33:16 +00:00
|
|
|
if (isspace(c))
|
|
|
|
break;
|
|
|
|
if (c == '<') {
|
|
|
|
at[-1] = ' ';
|
2005-04-12 06:46:50 +00:00
|
|
|
break;
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
2005-04-12 06:46:50 +00:00
|
|
|
at--;
|
|
|
|
}
|
2008-07-13 18:30:12 +00:00
|
|
|
el = strcspn(at, " \n\t\r\v\f>");
|
2015-10-19 05:22:10 +00:00
|
|
|
strbuf_reset(&mi->email);
|
|
|
|
strbuf_add(&mi->email, at, el);
|
mailinfo: avoid violating strbuf assertion
In handle_from, we calculate the end boundary of a section
to remove from a strbuf using strcspn like this:
el = strcspn(buf, set_of_end_boundaries);
strbuf_remove(&sb, start, el + 1);
This works fine if "el" is the offset of the boundary
character, meaning we remove up to and including that
character. But if the end boundary didn't match (that is, we
hit the end of the string as the boundary instead) then we
want just "el". Asking for "el+1" caught an out-of-bounds
assertion in the strbuf library.
This manifested itself when we got a 'From' header that had
just an email address with nothing else in it (the end of
the string was the end of the address, rather than, e.g., a
trailing '>' character), causing git-mailinfo to barf.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-19 17:28:24 +00:00
|
|
|
strbuf_remove(&f, at - f.buf, el + (at[el] ? 1 : 0));
|
2005-04-12 06:46:50 +00:00
|
|
|
|
2009-02-01 17:45:05 +00:00
|
|
|
/* The remainder is name. It could be
|
|
|
|
*
|
|
|
|
* - "John Doe <john.doe@xz>" (a), or
|
|
|
|
* - "john.doe@xz (John Doe)" (b), or
|
|
|
|
* - "John (zzz) Doe <john.doe@xz> (Comment)" (c)
|
|
|
|
*
|
|
|
|
* but we have removed the email part, so
|
|
|
|
*
|
|
|
|
* - remove extra spaces which could stay after email (case 'c'), and
|
|
|
|
* - trim from both ends, possibly removing the () pair at the end
|
|
|
|
* (cases 'a' and 'b').
|
2005-08-28 19:33:16 +00:00
|
|
|
*/
|
2009-02-01 17:45:05 +00:00
|
|
|
cleanup_space(&f);
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_trim(&f);
|
2008-07-21 13:34:29 +00:00
|
|
|
if (f.buf[0] == '(' && f.len && f.buf[f.len - 1] == ')') {
|
|
|
|
strbuf_remove(&f, 0, 1);
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_setlen(&f, f.len - 1);
|
2008-07-21 13:34:29 +00:00
|
|
|
}
|
2005-04-12 06:46:50 +00:00
|
|
|
|
2015-10-19 05:22:10 +00:00
|
|
|
get_sane_name(&mi->name, &f, &mi->email);
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_release(&f);
|
2005-04-12 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
static void handle_header(struct strbuf **out, const struct strbuf *line)
|
2005-05-02 04:42:53 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
if (!*out) {
|
|
|
|
*out = xmalloc(sizeof(struct strbuf));
|
|
|
|
strbuf_init(*out, line->len);
|
|
|
|
} else
|
|
|
|
strbuf_reset(*out);
|
2007-03-12 19:52:04 +00:00
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_addbuf(*out, line);
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE NOTE NOTE. We do not claim we do full MIME. We just attempt
|
|
|
|
* to have enough heuristics to grok MIME encoded patches often found
|
|
|
|
* on our mailing lists. For example, we do not even treat header lines
|
|
|
|
* case insensitively.
|
|
|
|
*/
|
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
static int slurp_attr(const char *line, const char *name, struct strbuf *attr)
|
2005-08-28 19:33:16 +00:00
|
|
|
{
|
2006-06-28 09:04:39 +00:00
|
|
|
const char *ends, *ap = strcasestr(line, name);
|
2005-08-28 19:33:16 +00:00
|
|
|
size_t sz;
|
|
|
|
|
2012-09-17 21:17:58 +00:00
|
|
|
strbuf_setlen(attr, 0);
|
|
|
|
if (!ap)
|
2005-08-28 19:33:16 +00:00
|
|
|
return 0;
|
|
|
|
ap += strlen(name);
|
|
|
|
if (*ap == '"') {
|
|
|
|
ap++;
|
|
|
|
ends = "\"";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ends = "; \t";
|
|
|
|
sz = strcspn(ap, ends);
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_add(attr, ap, sz);
|
2005-08-28 19:33:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
static struct strbuf *content[MAX_BOUNDARIES];
|
2007-03-12 19:52:04 +00:00
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
static struct strbuf **content_top = content;
|
2007-03-12 19:52:04 +00:00
|
|
|
|
2015-10-19 05:30:08 +00:00
|
|
|
static void handle_content_type(struct mailinfo *mi, struct strbuf *line)
|
2005-08-28 19:33:16 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
struct strbuf *boundary = xmalloc(sizeof(struct strbuf));
|
|
|
|
strbuf_init(boundary, line->len);
|
2007-03-12 19:52:04 +00:00
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
if (slurp_attr(line->buf, "boundary=", boundary)) {
|
|
|
|
strbuf_insert(boundary, 0, "--", 2);
|
2015-10-14 22:34:19 +00:00
|
|
|
if (++content_top >= &content[MAX_BOUNDARIES]) {
|
2007-03-12 19:52:04 +00:00
|
|
|
fprintf(stderr, "Too many boundaries to handle\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2008-07-13 18:30:12 +00:00
|
|
|
*content_top = boundary;
|
|
|
|
boundary = NULL;
|
2005-09-06 23:46:34 +00:00
|
|
|
}
|
2015-10-19 05:30:08 +00:00
|
|
|
slurp_attr(line->buf, "charset=", &mi->charset);
|
2008-07-13 18:30:12 +00:00
|
|
|
|
|
|
|
if (boundary) {
|
|
|
|
strbuf_release(boundary);
|
|
|
|
free(boundary);
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-19 05:27:56 +00:00
|
|
|
static void handle_message_id(struct mailinfo *mi, const struct strbuf *line)
|
2014-11-25 14:00:55 +00:00
|
|
|
{
|
2015-10-19 05:27:56 +00:00
|
|
|
if (mi->add_message_id)
|
|
|
|
mi->message_id = strdup(line->buf);
|
2014-11-25 14:00:55 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 23:16:05 +00:00
|
|
|
static void handle_content_transfer_encoding(struct mailinfo *mi,
|
|
|
|
const struct strbuf *line)
|
2005-08-28 19:33:16 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
if (strcasestr(line->buf, "base64"))
|
2015-10-14 23:16:05 +00:00
|
|
|
mi->transfer_encoding = TE_BASE64;
|
2008-07-13 18:30:12 +00:00
|
|
|
else if (strcasestr(line->buf, "quoted-printable"))
|
2015-10-14 23:16:05 +00:00
|
|
|
mi->transfer_encoding = TE_QP;
|
2005-08-28 19:33:16 +00:00
|
|
|
else
|
2015-10-14 23:16:05 +00:00
|
|
|
mi->transfer_encoding = TE_DONTCARE;
|
2005-04-12 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
static int is_multipart_boundary(const struct strbuf *line)
|
2005-08-28 19:33:16 +00:00
|
|
|
{
|
2008-08-09 08:17:24 +00:00
|
|
|
return (((*content_top)->len <= line->len) &&
|
|
|
|
!memcmp(line->buf, (*content_top)->buf, (*content_top)->len));
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 22:39:37 +00:00
|
|
|
static void cleanup_subject(struct mailinfo *mi, struct strbuf *subject)
|
2005-04-12 06:46:50 +00:00
|
|
|
{
|
2009-07-15 22:31:12 +00:00
|
|
|
size_t at = 0;
|
|
|
|
|
|
|
|
while (at < subject->len) {
|
|
|
|
char *pos;
|
|
|
|
size_t remove;
|
|
|
|
|
|
|
|
switch (subject->buf[at]) {
|
2005-04-12 06:46:50 +00:00
|
|
|
case 'r': case 'R':
|
2009-07-15 22:31:12 +00:00
|
|
|
if (subject->len <= at + 3)
|
2008-07-13 18:30:12 +00:00
|
|
|
break;
|
2012-09-09 09:59:58 +00:00
|
|
|
if ((subject->buf[at + 1] == 'e' ||
|
|
|
|
subject->buf[at + 1] == 'E') &&
|
|
|
|
subject->buf[at + 2] == ':') {
|
2009-07-15 22:31:12 +00:00
|
|
|
strbuf_remove(subject, at, 3);
|
2005-04-12 06:46:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-07-15 22:31:12 +00:00
|
|
|
at++;
|
2005-04-12 06:46:50 +00:00
|
|
|
break;
|
|
|
|
case ' ': case '\t': case ':':
|
2009-07-15 22:31:12 +00:00
|
|
|
strbuf_remove(subject, at, 1);
|
2005-04-12 06:46:50 +00:00
|
|
|
continue;
|
|
|
|
case '[':
|
2009-07-15 22:31:12 +00:00
|
|
|
pos = strchr(subject->buf + at, ']');
|
|
|
|
if (!pos)
|
|
|
|
break;
|
|
|
|
remove = pos - subject->buf + at + 1;
|
2015-10-14 22:39:37 +00:00
|
|
|
if (!mi->keep_non_patch_brackets_in_subject ||
|
2009-07-15 22:31:12 +00:00
|
|
|
(7 <= remove &&
|
|
|
|
memmem(subject->buf + at, remove, "PATCH", 5)))
|
|
|
|
strbuf_remove(subject, at, remove);
|
2012-01-16 10:53:01 +00:00
|
|
|
else {
|
2009-07-15 22:31:12 +00:00
|
|
|
at += remove;
|
2012-01-16 10:53:01 +00:00
|
|
|
/*
|
|
|
|
* If the input had a space after the ], keep
|
|
|
|
* it. We don't bother with finding the end of
|
|
|
|
* the space, since we later normalize it
|
|
|
|
* anyway.
|
|
|
|
*/
|
|
|
|
if (isspace(subject->buf[at]))
|
|
|
|
at += 1;
|
|
|
|
}
|
2009-07-15 22:31:12 +00:00
|
|
|
continue;
|
2005-04-12 06:46:50 +00:00
|
|
|
}
|
2009-07-15 22:31:12 +00:00
|
|
|
break;
|
2005-04-12 06:46:50 +00:00
|
|
|
}
|
2009-07-15 22:31:12 +00:00
|
|
|
strbuf_trim(subject);
|
2006-06-13 20:21:50 +00:00
|
|
|
}
|
2005-04-12 06:46:50 +00:00
|
|
|
|
2015-10-15 00:44:46 +00:00
|
|
|
#define MAX_HDR_PARSED 10
|
2007-10-21 04:12:12 +00:00
|
|
|
static const char *header[MAX_HDR_PARSED] = {
|
2007-03-12 19:52:04 +00:00
|
|
|
"From","Subject","Date",
|
2005-08-28 19:33:16 +00:00
|
|
|
};
|
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
static inline int cmp_header(const struct strbuf *line, const char *hdr)
|
2005-08-28 19:33:16 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
int len = strlen(hdr);
|
|
|
|
return !strncasecmp(line->buf, hdr, len) && line->len > len &&
|
|
|
|
line->buf[len] == ':' && isspace(line->buf[len + 1]);
|
|
|
|
}
|
2005-08-28 19:33:16 +00:00
|
|
|
|
2014-09-14 01:30:38 +00:00
|
|
|
static int is_format_patch_separator(const char *line, int len)
|
|
|
|
{
|
2014-09-21 09:13:58 +00:00
|
|
|
static const char SAMPLE[] =
|
|
|
|
"From e6807f3efca28b30decfecb1732a56c7db1137ee Mon Sep 17 00:00:00 2001\n";
|
2014-09-14 01:30:38 +00:00
|
|
|
const char *cp;
|
|
|
|
|
|
|
|
if (len != strlen(SAMPLE))
|
|
|
|
return 0;
|
|
|
|
if (!skip_prefix(line, "From ", &cp))
|
|
|
|
return 0;
|
|
|
|
if (strspn(cp, "0123456789abcdef") != 40)
|
|
|
|
return 0;
|
|
|
|
cp += 40;
|
|
|
|
return !memcmp(SAMPLE + (cp - line), cp, strlen(SAMPLE) - (cp - line));
|
|
|
|
}
|
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
static struct strbuf *decode_q_segment(const struct strbuf *q_seg, int rfc2047)
|
2005-08-28 19:33:16 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
const char *in = q_seg->buf;
|
2005-08-28 19:33:16 +00:00
|
|
|
int c;
|
2008-07-13 18:30:12 +00:00
|
|
|
struct strbuf *out = xmalloc(sizeof(struct strbuf));
|
|
|
|
strbuf_init(out, q_seg->len);
|
|
|
|
|
|
|
|
while ((c = *in++) != 0) {
|
2005-08-28 19:33:16 +00:00
|
|
|
if (c == '=') {
|
|
|
|
int d = *in++;
|
|
|
|
if (d == '\n' || !d)
|
|
|
|
break; /* drop trailing newline */
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_addch(out, (hexval(d) << 4) | hexval(*in++));
|
2006-04-21 07:06:58 +00:00
|
|
|
continue;
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
2006-04-21 07:06:58 +00:00
|
|
|
if (rfc2047 && c == '_') /* rfc2047 4.2 (2) */
|
|
|
|
c = 0x20;
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_addch(out, c);
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
2008-07-13 18:30:12 +00:00
|
|
|
return out;
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
static struct strbuf *decode_b_segment(const struct strbuf *b_seg)
|
2005-08-28 19:33:16 +00:00
|
|
|
{
|
|
|
|
/* Decode in..ep, possibly in-place to ot */
|
|
|
|
int c, pos = 0, acc = 0;
|
2008-07-13 18:30:12 +00:00
|
|
|
const char *in = b_seg->buf;
|
|
|
|
struct strbuf *out = xmalloc(sizeof(struct strbuf));
|
|
|
|
strbuf_init(out, b_seg->len);
|
2005-08-28 19:33:16 +00:00
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
while ((c = *in++) != 0) {
|
2005-08-28 19:33:16 +00:00
|
|
|
if (c == '+')
|
|
|
|
c = 62;
|
|
|
|
else if (c == '/')
|
|
|
|
c = 63;
|
|
|
|
else if ('A' <= c && c <= 'Z')
|
|
|
|
c -= 'A';
|
|
|
|
else if ('a' <= c && c <= 'z')
|
|
|
|
c -= 'a' - 26;
|
|
|
|
else if ('0' <= c && c <= '9')
|
|
|
|
c -= '0' - 52;
|
|
|
|
else
|
|
|
|
continue; /* garbage */
|
|
|
|
switch (pos++) {
|
|
|
|
case 0:
|
|
|
|
acc = (c << 2);
|
|
|
|
break;
|
|
|
|
case 1:
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_addch(out, (acc | (c >> 4)));
|
2005-08-28 19:33:16 +00:00
|
|
|
acc = (c & 15) << 4;
|
|
|
|
break;
|
|
|
|
case 2:
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_addch(out, (acc | (c >> 2)));
|
2005-08-28 19:33:16 +00:00
|
|
|
acc = (c & 3) << 6;
|
|
|
|
break;
|
|
|
|
case 3:
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_addch(out, (acc | c));
|
2005-08-28 19:33:16 +00:00
|
|
|
acc = pos = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-07-13 18:30:12 +00:00
|
|
|
return out;
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 23:15:40 +00:00
|
|
|
static void convert_to_utf8(struct mailinfo *mi,
|
|
|
|
struct strbuf *line, const char *charset)
|
2005-08-28 19:33:16 +00:00
|
|
|
{
|
Do a better job at guessing unknown character sets
At least in the kernel development community, we're generally slowly
converting to UTF-8 everywhere, and the old default of Latin1 in emails is
being supplanted by UTF-8, and it doesn't necessarily show up as such in
the mail headers (because, quite frankly, when people send patches
around, they want the email client to do as little as humanly possible
about the patch)
Despite that, it's often the case that email addresses etc still have
Latin1, so I've seen emails where this is a mixed bag, with Signed-off
parts being copied from email (and containing Latin1 characters), and the
rest of the email being a patch in UTF-8.
So this suggests a very natural change: if the target character set is
utf-8 (the default), and if the source already looks like utf-8, just
assume that it doesn't need any conversion at all.
Only assume that it needs conversion if it isn't already valid utf-8, in
which case we (for historical reasons) will assume it's Latin1.
Basically no really _valid_ latin1 will ever look like utf-8, so while
this changes our historical behaviour, it doesn't do so in practice, and
makes the default behaviour saner for the case where the input was already
in proper format.
We could do a more fancy guess, of course, but this correctly handled a
series of patches I just got from Andrew that had a mixture of Latin1 and
UTF-8 (in different emails, but without any character set indication).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-07-17 17:34:44 +00:00
|
|
|
char *out;
|
|
|
|
|
2015-10-18 22:58:35 +00:00
|
|
|
if (!mi->metainfo_charset || !charset || !*charset)
|
2012-06-28 18:24:14 +00:00
|
|
|
return;
|
2006-12-24 07:36:55 +00:00
|
|
|
|
2015-10-14 23:15:40 +00:00
|
|
|
if (same_encoding(mi->metainfo_charset, charset))
|
2007-07-24 00:03:26 +00:00
|
|
|
return;
|
2015-10-14 23:15:40 +00:00
|
|
|
out = reencode_string(line->buf, mi->metainfo_charset, charset);
|
2007-01-10 05:31:36 +00:00
|
|
|
if (!out)
|
2009-01-04 18:38:41 +00:00
|
|
|
die("cannot convert from %s to %s",
|
2015-10-14 23:15:40 +00:00
|
|
|
charset, mi->metainfo_charset);
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_attach(line, out, strlen(out), strlen(out));
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 23:15:40 +00:00
|
|
|
static void decode_header(struct mailinfo *mi, struct strbuf *it)
|
2005-08-28 19:33:16 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
char *in, *ep, *cp;
|
|
|
|
struct strbuf outbuf = STRBUF_INIT, *dec;
|
|
|
|
struct strbuf charset_q = STRBUF_INIT, piecebuf = STRBUF_INIT;
|
2005-08-28 19:33:16 +00:00
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
in = it->buf;
|
|
|
|
while (in - it->buf <= it->len && (ep = strstr(in, "=?")) != NULL) {
|
|
|
|
int encoding;
|
|
|
|
strbuf_reset(&charset_q);
|
|
|
|
strbuf_reset(&piecebuf);
|
2006-07-05 21:17:49 +00:00
|
|
|
|
2005-08-28 19:33:16 +00:00
|
|
|
if (in != ep) {
|
2009-01-07 22:43:42 +00:00
|
|
|
/*
|
|
|
|
* We are about to process an encoded-word
|
|
|
|
* that begins at ep, but there is something
|
|
|
|
* before the encoded word.
|
|
|
|
*/
|
|
|
|
char *scan;
|
|
|
|
for (scan = in; scan < ep; scan++)
|
|
|
|
if (!isspace(*scan))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (scan != ep || in == it->buf) {
|
|
|
|
/*
|
|
|
|
* We should not lose that "something",
|
|
|
|
* unless we have just processed an
|
|
|
|
* encoded-word, and there is only LWS
|
|
|
|
* before the one we are about to process.
|
|
|
|
*/
|
|
|
|
strbuf_add(&outbuf, in, ep - in);
|
|
|
|
}
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
|
|
|
/* E.g.
|
|
|
|
* ep : "=?iso-2022-jp?B?GyR...?= foo"
|
|
|
|
* ep : "=?ISO-8859-1?Q?Foo=FCbar?= baz"
|
|
|
|
*/
|
|
|
|
ep += 2;
|
2008-07-13 18:30:12 +00:00
|
|
|
|
|
|
|
if (ep - it->buf >= it->len || !(cp = strchr(ep, '?')))
|
2015-10-14 22:33:44 +00:00
|
|
|
goto release_return;
|
2008-07-13 18:30:12 +00:00
|
|
|
|
|
|
|
if (cp + 3 - it->buf > it->len)
|
2015-10-14 22:33:44 +00:00
|
|
|
goto release_return;
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_add(&charset_q, ep, cp - ep);
|
|
|
|
|
2005-08-28 19:33:16 +00:00
|
|
|
encoding = cp[1];
|
|
|
|
if (!encoding || cp[2] != '?')
|
2015-10-14 22:33:44 +00:00
|
|
|
goto release_return;
|
2005-08-28 19:33:16 +00:00
|
|
|
ep = strstr(cp + 3, "?=");
|
|
|
|
if (!ep)
|
2015-10-14 22:33:44 +00:00
|
|
|
goto release_return;
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_add(&piecebuf, cp + 3, ep - cp - 3);
|
2005-08-28 19:33:16 +00:00
|
|
|
switch (tolower(encoding)) {
|
|
|
|
default:
|
2015-10-14 22:33:44 +00:00
|
|
|
goto release_return;
|
2005-08-28 19:33:16 +00:00
|
|
|
case 'b':
|
2008-07-13 18:30:12 +00:00
|
|
|
dec = decode_b_segment(&piecebuf);
|
2005-08-28 19:33:16 +00:00
|
|
|
break;
|
|
|
|
case 'q':
|
2008-07-13 18:30:12 +00:00
|
|
|
dec = decode_q_segment(&piecebuf, 1);
|
2005-08-28 19:33:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-10-18 22:58:35 +00:00
|
|
|
convert_to_utf8(mi, dec, charset_q.buf);
|
2007-08-30 21:48:24 +00:00
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_addbuf(&outbuf, dec);
|
|
|
|
strbuf_release(dec);
|
|
|
|
free(dec);
|
2005-08-28 19:33:16 +00:00
|
|
|
in = ep + 2;
|
|
|
|
}
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_addstr(&outbuf, in);
|
|
|
|
strbuf_reset(it);
|
|
|
|
strbuf_addbuf(it, &outbuf);
|
2015-10-14 22:33:44 +00:00
|
|
|
release_return:
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_release(&outbuf);
|
|
|
|
strbuf_release(&charset_q);
|
|
|
|
strbuf_release(&piecebuf);
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 05:27:56 +00:00
|
|
|
static int check_header(struct mailinfo *mi,
|
|
|
|
const struct strbuf *line,
|
|
|
|
struct strbuf *hdr_data[], int overwrite)
|
2015-10-15 00:44:21 +00:00
|
|
|
{
|
|
|
|
int i, ret = 0, len;
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2015-10-19 05:27:56 +00:00
|
|
|
|
2015-10-15 00:44:21 +00:00
|
|
|
/* search for the interesting parts */
|
|
|
|
for (i = 0; header[i]; i++) {
|
|
|
|
int len = strlen(header[i]);
|
|
|
|
if ((!hdr_data[i] || overwrite) && cmp_header(line, header[i])) {
|
|
|
|
/* Unwrap inline B and Q encoding, and optionally
|
|
|
|
* normalize the meta information to utf8.
|
|
|
|
*/
|
|
|
|
strbuf_add(&sb, line->buf + len + 2, line->len - len - 2);
|
2015-10-14 23:15:40 +00:00
|
|
|
decode_header(mi, &sb);
|
2015-10-15 00:44:21 +00:00
|
|
|
handle_header(&hdr_data[i], &sb);
|
|
|
|
ret = 1;
|
|
|
|
goto check_header_out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Content stuff */
|
|
|
|
if (cmp_header(line, "Content-Type")) {
|
|
|
|
len = strlen("Content-Type: ");
|
|
|
|
strbuf_add(&sb, line->buf + len, line->len - len);
|
2015-10-14 23:15:40 +00:00
|
|
|
decode_header(mi, &sb);
|
2015-10-15 00:44:21 +00:00
|
|
|
strbuf_insert(&sb, 0, "Content-Type: ", len);
|
2015-10-19 05:30:08 +00:00
|
|
|
handle_content_type(mi, &sb);
|
2015-10-15 00:44:21 +00:00
|
|
|
ret = 1;
|
|
|
|
goto check_header_out;
|
|
|
|
}
|
|
|
|
if (cmp_header(line, "Content-Transfer-Encoding")) {
|
|
|
|
len = strlen("Content-Transfer-Encoding: ");
|
|
|
|
strbuf_add(&sb, line->buf + len, line->len - len);
|
2015-10-14 23:15:40 +00:00
|
|
|
decode_header(mi, &sb);
|
2015-10-14 23:16:05 +00:00
|
|
|
handle_content_transfer_encoding(mi, &sb);
|
2015-10-15 00:44:21 +00:00
|
|
|
ret = 1;
|
|
|
|
goto check_header_out;
|
|
|
|
}
|
|
|
|
if (cmp_header(line, "Message-Id")) {
|
|
|
|
len = strlen("Message-Id: ");
|
|
|
|
strbuf_add(&sb, line->buf + len, line->len - len);
|
2015-10-14 23:15:40 +00:00
|
|
|
decode_header(mi, &sb);
|
2015-10-19 05:27:56 +00:00
|
|
|
handle_message_id(mi, &sb);
|
2015-10-15 00:44:21 +00:00
|
|
|
ret = 1;
|
|
|
|
goto check_header_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for inbody stuff */
|
|
|
|
if (starts_with(line->buf, ">From") && isspace(line->buf[5])) {
|
|
|
|
ret = is_format_patch_separator(line->buf + 1, line->len - 1);
|
|
|
|
goto check_header_out;
|
|
|
|
}
|
|
|
|
if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {
|
|
|
|
for (i = 0; header[i]; i++) {
|
|
|
|
if (!strcmp("Subject", header[i])) {
|
|
|
|
handle_header(&hdr_data[i], line);
|
|
|
|
ret = 1;
|
|
|
|
goto check_header_out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
check_header_out:
|
|
|
|
strbuf_release(&sb);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-14 23:16:05 +00:00
|
|
|
static void decode_transfer_encoding(struct mailinfo *mi, struct strbuf *line)
|
2005-08-28 19:33:16 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
struct strbuf *ret;
|
2005-08-28 19:33:16 +00:00
|
|
|
|
2015-10-14 23:16:05 +00:00
|
|
|
switch (mi->transfer_encoding) {
|
2005-08-28 19:33:16 +00:00
|
|
|
case TE_QP:
|
2008-07-13 18:30:12 +00:00
|
|
|
ret = decode_q_segment(line, 0);
|
|
|
|
break;
|
2005-08-28 19:33:16 +00:00
|
|
|
case TE_BASE64:
|
2008-07-13 18:30:12 +00:00
|
|
|
ret = decode_b_segment(line);
|
|
|
|
break;
|
2005-08-28 19:33:16 +00:00
|
|
|
case TE_DONTCARE:
|
2008-05-25 08:16:05 +00:00
|
|
|
default:
|
2008-07-13 18:30:12 +00:00
|
|
|
return;
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_reset(line);
|
|
|
|
strbuf_addbuf(line, ret);
|
|
|
|
strbuf_release(ret);
|
|
|
|
free(ret);
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
static inline int patchbreak(const struct strbuf *line)
|
2007-03-12 19:52:06 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
size_t i;
|
|
|
|
|
2007-03-12 19:52:06 +00:00
|
|
|
/* Beginning of a "diff -" header? */
|
2013-11-30 20:55:40 +00:00
|
|
|
if (starts_with(line->buf, "diff -"))
|
2007-03-12 19:52:06 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* CVS "Index: " line? */
|
2013-11-30 20:55:40 +00:00
|
|
|
if (starts_with(line->buf, "Index: "))
|
2007-03-12 19:52:06 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "--- <filename>" starts patches without headers
|
|
|
|
* "---<sp>*" is a manual separator
|
|
|
|
*/
|
2008-07-13 18:30:12 +00:00
|
|
|
if (line->len < 4)
|
|
|
|
return 0;
|
|
|
|
|
2013-11-30 20:55:40 +00:00
|
|
|
if (starts_with(line->buf, "---")) {
|
2007-03-12 19:52:06 +00:00
|
|
|
/* space followed by a filename? */
|
2008-07-13 18:30:12 +00:00
|
|
|
if (line->buf[3] == ' ' && !isspace(line->buf[4]))
|
2007-03-12 19:52:06 +00:00
|
|
|
return 1;
|
|
|
|
/* Just whitespace? */
|
2008-07-13 18:30:12 +00:00
|
|
|
for (i = 3; i < line->len; i++) {
|
|
|
|
unsigned char c = line->buf[i];
|
2007-03-12 19:52:06 +00:00
|
|
|
if (c == '\n')
|
|
|
|
return 1;
|
|
|
|
if (!isspace(c))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-23 08:56:19 +00:00
|
|
|
static int is_scissors_line(const struct strbuf *line)
|
|
|
|
{
|
|
|
|
size_t i, len = line->len;
|
|
|
|
int scissors = 0, gap = 0;
|
|
|
|
int first_nonblank = -1;
|
|
|
|
int last_nonblank = 0, visible, perforation = 0, in_perforation = 0;
|
|
|
|
const char *buf = line->buf;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (isspace(buf[i])) {
|
|
|
|
if (in_perforation) {
|
|
|
|
perforation++;
|
|
|
|
gap++;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
last_nonblank = i;
|
|
|
|
if (first_nonblank < 0)
|
|
|
|
first_nonblank = i;
|
|
|
|
if (buf[i] == '-') {
|
|
|
|
in_perforation = 1;
|
|
|
|
perforation++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (i + 1 < len &&
|
2010-04-03 19:52:17 +00:00
|
|
|
(!memcmp(buf + i, ">8", 2) || !memcmp(buf + i, "8<", 2) ||
|
|
|
|
!memcmp(buf + i, ">%", 2) || !memcmp(buf + i, "%<", 2))) {
|
2009-08-23 08:56:19 +00:00
|
|
|
in_perforation = 1;
|
|
|
|
perforation += 2;
|
|
|
|
scissors += 2;
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
in_perforation = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The mark must be at least 8 bytes long (e.g. "-- >8 --").
|
|
|
|
* Even though there can be arbitrary cruft on the same line
|
|
|
|
* (e.g. "cut here"), in order to avoid misidentification, the
|
|
|
|
* perforation must occupy more than a third of the visible
|
|
|
|
* width of the line, and dashes and scissors must occupy more
|
|
|
|
* than half of the perforation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
visible = last_nonblank - first_nonblank + 1;
|
|
|
|
return (scissors && 8 <= visible &&
|
|
|
|
visible < perforation * 3 &&
|
|
|
|
gap * 2 < perforation);
|
|
|
|
}
|
|
|
|
|
2015-10-14 23:13:34 +00:00
|
|
|
static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
|
2005-08-28 19:33:16 +00:00
|
|
|
{
|
|
|
|
if (!cmitmsg)
|
|
|
|
return 0;
|
2005-04-12 06:46:50 +00:00
|
|
|
|
2015-10-14 23:13:34 +00:00
|
|
|
if (mi->header_stage) {
|
2010-02-20 05:55:33 +00:00
|
|
|
if (!line->len || (line->len == 1 && line->buf[0] == '\n'))
|
2008-07-13 18:30:12 +00:00
|
|
|
return 0;
|
2009-11-20 16:12:47 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 23:14:57 +00:00
|
|
|
if (mi->use_inbody_headers && mi->header_stage) {
|
2015-10-19 05:27:56 +00:00
|
|
|
mi->header_stage = check_header(mi, line, s_hdr_data, 0);
|
2015-10-14 23:13:34 +00:00
|
|
|
if (mi->header_stage)
|
2007-03-12 19:52:04 +00:00
|
|
|
return 0;
|
2009-11-20 16:12:47 +00:00
|
|
|
} else
|
|
|
|
/* Only trim the first (blank) line of the commit message
|
|
|
|
* when ignoring in-body headers.
|
|
|
|
*/
|
2015-10-14 23:13:34 +00:00
|
|
|
mi->header_stage = 0;
|
2006-05-23 19:47:28 +00:00
|
|
|
|
2007-03-30 16:18:45 +00:00
|
|
|
/* normalize the log message to UTF-8. */
|
2015-10-19 05:30:08 +00:00
|
|
|
convert_to_utf8(mi, line, mi->charset.buf);
|
2007-03-30 16:18:45 +00:00
|
|
|
|
2015-10-14 23:14:57 +00:00
|
|
|
if (mi->use_scissors && is_scissors_line(line)) {
|
2009-08-23 08:56:19 +00:00
|
|
|
int i;
|
2009-09-29 06:40:08 +00:00
|
|
|
if (fseek(cmitmsg, 0L, SEEK_SET))
|
|
|
|
die_errno("Could not rewind output message file");
|
|
|
|
if (ftruncate(fileno(cmitmsg), 0))
|
|
|
|
die_errno("Could not truncate output message file at scissors");
|
2015-10-14 23:13:34 +00:00
|
|
|
mi->header_stage = 1;
|
2009-08-23 08:56:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We may have already read "secondary headers"; purge
|
|
|
|
* them to give ourselves a clean restart.
|
|
|
|
*/
|
|
|
|
for (i = 0; header[i]; i++) {
|
|
|
|
if (s_hdr_data[i])
|
|
|
|
strbuf_release(s_hdr_data[i]);
|
|
|
|
s_hdr_data[i] = NULL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-12 19:52:06 +00:00
|
|
|
if (patchbreak(line)) {
|
2015-10-19 05:27:56 +00:00
|
|
|
if (mi->message_id)
|
|
|
|
fprintf(cmitmsg, "Message-Id: %s\n", mi->message_id);
|
2007-03-12 19:52:04 +00:00
|
|
|
fclose(cmitmsg);
|
|
|
|
cmitmsg = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
2006-05-23 19:47:28 +00:00
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
fputs(line->buf, cmitmsg);
|
2005-08-28 19:33:16 +00:00
|
|
|
return 0;
|
2005-04-12 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 23:13:51 +00:00
|
|
|
static void handle_patch(struct mailinfo *mi, const struct strbuf *line)
|
2005-04-12 06:46:50 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
fwrite(line->buf, 1, line->len, patchfile);
|
2015-10-14 23:13:51 +00:00
|
|
|
mi->patch_lines++;
|
2005-04-12 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 23:13:34 +00:00
|
|
|
static void handle_filter(struct mailinfo *mi, struct strbuf *line)
|
2005-04-12 06:46:50 +00:00
|
|
|
{
|
2015-10-14 23:13:34 +00:00
|
|
|
switch (mi->filter_stage) {
|
2007-03-12 19:52:04 +00:00
|
|
|
case 0:
|
2015-10-14 23:13:34 +00:00
|
|
|
if (!handle_commit_msg(mi, line))
|
2005-08-28 19:33:16 +00:00
|
|
|
break;
|
2015-10-14 23:13:34 +00:00
|
|
|
mi->filter_stage++;
|
2007-03-12 19:52:04 +00:00
|
|
|
case 1:
|
2015-10-14 23:13:51 +00:00
|
|
|
handle_patch(mi, line);
|
2008-07-13 18:30:12 +00:00
|
|
|
break;
|
2005-04-12 06:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-15 00:44:07 +00:00
|
|
|
static int is_rfc2822_header(const struct strbuf *line)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The section that defines the loosest possible
|
|
|
|
* field name is "3.6.8 Optional fields".
|
|
|
|
*
|
|
|
|
* optional-field = field-name ":" unstructured CRLF
|
|
|
|
* field-name = 1*ftext
|
|
|
|
* ftext = %d33-57 / %59-126
|
|
|
|
*/
|
|
|
|
int ch;
|
|
|
|
char *cp = line->buf;
|
|
|
|
|
|
|
|
/* Count mbox From headers as headers */
|
|
|
|
if (starts_with(cp, "From ") || starts_with(cp, ">From "))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
while ((ch = *cp++)) {
|
|
|
|
if (ch == ':')
|
|
|
|
return 1;
|
|
|
|
if ((33 <= ch && ch <= 57) ||
|
|
|
|
(59 <= ch && ch <= 126))
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read_one_header_line(struct strbuf *line, FILE *in)
|
|
|
|
{
|
|
|
|
struct strbuf continuation = STRBUF_INIT;
|
|
|
|
|
|
|
|
/* Get the first part of the line. */
|
|
|
|
if (strbuf_getline(line, in, '\n'))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is it an empty line or not a valid rfc2822 header?
|
|
|
|
* If so, stop here, and return false ("not a header")
|
|
|
|
*/
|
|
|
|
strbuf_rtrim(line);
|
|
|
|
if (!line->len || !is_rfc2822_header(line)) {
|
|
|
|
/* Re-add the newline */
|
|
|
|
strbuf_addch(line, '\n');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we need to eat all the continuation lines..
|
|
|
|
* Yuck, 2822 header "folding"
|
|
|
|
*/
|
|
|
|
for (;;) {
|
|
|
|
int peek;
|
|
|
|
|
|
|
|
peek = fgetc(in); ungetc(peek, in);
|
|
|
|
if (peek != ' ' && peek != '\t')
|
|
|
|
break;
|
|
|
|
if (strbuf_getline(&continuation, in, '\n'))
|
|
|
|
break;
|
|
|
|
continuation.buf[0] = ' ';
|
|
|
|
strbuf_rtrim(&continuation);
|
|
|
|
strbuf_addbuf(line, &continuation);
|
|
|
|
}
|
|
|
|
strbuf_release(&continuation);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-10-14 22:40:04 +00:00
|
|
|
static int find_boundary(struct mailinfo *mi, struct strbuf *line)
|
2015-10-13 18:03:20 +00:00
|
|
|
{
|
2015-10-14 22:40:04 +00:00
|
|
|
while (!strbuf_getline(line, mi->input, '\n')) {
|
2015-10-18 22:40:06 +00:00
|
|
|
if (*content_top && is_multipart_boundary(line))
|
2015-10-13 18:03:20 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-14 23:13:34 +00:00
|
|
|
static int handle_boundary(struct mailinfo *mi, struct strbuf *line)
|
2015-10-13 18:03:20 +00:00
|
|
|
{
|
|
|
|
struct strbuf newline = STRBUF_INIT;
|
|
|
|
|
|
|
|
strbuf_addch(&newline, '\n');
|
|
|
|
again:
|
2015-10-18 22:40:06 +00:00
|
|
|
if (line->len >= (*content_top)->len + 2 &&
|
|
|
|
!memcmp(line->buf + (*content_top)->len, "--", 2)) {
|
2015-10-13 18:03:20 +00:00
|
|
|
/* we hit an end boundary */
|
|
|
|
/* pop the current boundary off the stack */
|
|
|
|
strbuf_release(*content_top);
|
|
|
|
free(*content_top);
|
|
|
|
*content_top = NULL;
|
|
|
|
|
|
|
|
/* technically won't happen as is_multipart_boundary()
|
|
|
|
will fail first. But just in case..
|
|
|
|
*/
|
|
|
|
if (--content_top < content) {
|
|
|
|
fprintf(stderr, "Detected mismatched boundaries, "
|
|
|
|
"can't recover\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2015-10-14 23:13:34 +00:00
|
|
|
handle_filter(mi, &newline);
|
2015-10-13 18:03:20 +00:00
|
|
|
strbuf_release(&newline);
|
|
|
|
|
|
|
|
/* skip to the next boundary */
|
2015-10-14 22:40:04 +00:00
|
|
|
if (!find_boundary(mi, line))
|
2015-10-13 18:03:20 +00:00
|
|
|
return 0;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set some defaults */
|
2015-10-14 23:16:05 +00:00
|
|
|
mi->transfer_encoding = TE_DONTCARE;
|
2015-10-19 05:30:08 +00:00
|
|
|
strbuf_reset(&mi->charset);
|
2015-10-13 18:03:20 +00:00
|
|
|
|
|
|
|
/* slurp in this section's info */
|
2015-10-14 22:40:04 +00:00
|
|
|
while (read_one_header_line(line, mi->input))
|
2015-10-19 05:27:56 +00:00
|
|
|
check_header(mi, line, p_hdr_data, 0);
|
2015-10-13 18:03:20 +00:00
|
|
|
|
|
|
|
strbuf_release(&newline);
|
|
|
|
/* replenish line */
|
2015-10-14 22:40:04 +00:00
|
|
|
if (strbuf_getline(line, mi->input, '\n'))
|
2015-10-13 18:03:20 +00:00
|
|
|
return 0;
|
2015-10-18 22:40:06 +00:00
|
|
|
strbuf_addch(line, '\n');
|
2015-10-13 18:03:20 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-10-14 22:40:04 +00:00
|
|
|
static void handle_body(struct mailinfo *mi, struct strbuf *line)
|
2005-07-23 09:10:31 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
struct strbuf prev = STRBUF_INIT;
|
2005-08-28 19:33:16 +00:00
|
|
|
|
|
|
|
/* Skip up to the first boundary */
|
2008-07-13 18:30:12 +00:00
|
|
|
if (*content_top) {
|
2015-10-14 22:40:04 +00:00
|
|
|
if (!find_boundary(mi, line))
|
2008-07-13 18:30:12 +00:00
|
|
|
goto handle_body_out;
|
2007-03-12 19:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* process any boundary lines */
|
2015-10-18 22:36:16 +00:00
|
|
|
if (*content_top && is_multipart_boundary(line)) {
|
2007-03-12 19:52:04 +00:00
|
|
|
/* flush any leftover */
|
2008-08-09 08:17:24 +00:00
|
|
|
if (prev.len) {
|
2015-10-14 23:13:34 +00:00
|
|
|
handle_filter(mi, &prev);
|
2008-08-09 08:17:24 +00:00
|
|
|
strbuf_reset(&prev);
|
|
|
|
}
|
2015-10-14 23:13:34 +00:00
|
|
|
if (!handle_boundary(mi, line))
|
2008-07-13 18:30:12 +00:00
|
|
|
goto handle_body_out;
|
2007-03-12 19:52:04 +00:00
|
|
|
}
|
|
|
|
|
2007-03-30 16:18:45 +00:00
|
|
|
/* Unwrap transfer encoding */
|
2015-10-14 23:16:05 +00:00
|
|
|
decode_transfer_encoding(mi, line);
|
2007-03-12 19:52:04 +00:00
|
|
|
|
2015-10-14 23:16:05 +00:00
|
|
|
switch (mi->transfer_encoding) {
|
2007-03-12 19:52:04 +00:00
|
|
|
case TE_BASE64:
|
2008-02-15 21:53:36 +00:00
|
|
|
case TE_QP:
|
2007-03-12 19:52:04 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
struct strbuf **lines, **it, *sb;
|
|
|
|
|
|
|
|
/* Prepend any previous partial lines */
|
2015-10-18 22:36:16 +00:00
|
|
|
strbuf_insert(line, 0, prev.buf, prev.len);
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_reset(&prev);
|
2007-03-12 19:52:04 +00:00
|
|
|
|
2008-05-25 08:16:05 +00:00
|
|
|
/*
|
|
|
|
* This is a decoded line that may contain
|
2007-03-12 19:52:04 +00:00
|
|
|
* multiple new lines. Pass only one chunk
|
|
|
|
* at a time to handle_filter()
|
|
|
|
*/
|
2015-10-18 22:36:16 +00:00
|
|
|
lines = strbuf_split(line, '\n');
|
2008-07-13 18:30:12 +00:00
|
|
|
for (it = lines; (sb = *it); it++) {
|
|
|
|
if (*(it + 1) == NULL) /* The last line */
|
|
|
|
if (sb->buf[sb->len - 1] != '\n') {
|
|
|
|
/* Partial line, save it for later. */
|
|
|
|
strbuf_addbuf(&prev, sb);
|
|
|
|
break;
|
|
|
|
}
|
2015-10-14 23:13:34 +00:00
|
|
|
handle_filter(mi, sb);
|
2008-07-13 18:30:12 +00:00
|
|
|
}
|
2008-05-25 08:16:05 +00:00
|
|
|
/*
|
2008-07-13 18:30:12 +00:00
|
|
|
* The partial chunk is saved in "prev" and will be
|
2008-05-25 08:16:05 +00:00
|
|
|
* appended by the next iteration of read_line_with_nul().
|
2007-03-12 19:52:04 +00:00
|
|
|
*/
|
2008-07-13 18:30:12 +00:00
|
|
|
strbuf_list_free(lines);
|
2005-08-28 19:33:16 +00:00
|
|
|
break;
|
2005-07-23 09:10:31 +00:00
|
|
|
}
|
2007-03-12 19:52:04 +00:00
|
|
|
default:
|
2015-10-14 23:13:34 +00:00
|
|
|
handle_filter(mi, line);
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
2007-03-12 19:52:04 +00:00
|
|
|
|
2015-10-14 22:40:04 +00:00
|
|
|
} while (!strbuf_getwholeline(line, mi->input, '\n'));
|
2008-07-13 18:30:12 +00:00
|
|
|
|
|
|
|
handle_body_out:
|
|
|
|
strbuf_release(&prev);
|
2005-07-23 09:10:31 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
static void output_header_lines(FILE *fout, const char *hdr, const struct strbuf *data)
|
2007-07-29 00:57:25 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
const char *sp = data->buf;
|
2007-07-29 00:57:25 +00:00
|
|
|
while (1) {
|
2008-07-13 18:30:12 +00:00
|
|
|
char *ep = strchr(sp, '\n');
|
2007-07-29 00:57:25 +00:00
|
|
|
int len;
|
|
|
|
if (!ep)
|
2008-07-13 18:30:12 +00:00
|
|
|
len = strlen(sp);
|
2007-07-29 00:57:25 +00:00
|
|
|
else
|
2008-07-13 18:30:12 +00:00
|
|
|
len = ep - sp;
|
|
|
|
fprintf(fout, "%s: %.*s\n", hdr, len, sp);
|
2007-07-29 00:57:25 +00:00
|
|
|
if (!ep)
|
|
|
|
break;
|
2008-07-13 18:30:12 +00:00
|
|
|
sp = ep + 1;
|
2007-07-29 00:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-19 05:22:10 +00:00
|
|
|
static void handle_info(struct mailinfo *mi)
|
2005-04-12 06:46:50 +00:00
|
|
|
{
|
2008-07-13 18:30:12 +00:00
|
|
|
struct strbuf *hdr;
|
2007-03-12 19:52:04 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; header[i]; i++) {
|
|
|
|
/* only print inbody headers if we output a patch file */
|
2015-10-14 23:13:51 +00:00
|
|
|
if (mi->patch_lines && s_hdr_data[i])
|
2007-03-12 19:52:04 +00:00
|
|
|
hdr = s_hdr_data[i];
|
|
|
|
else if (p_hdr_data[i])
|
|
|
|
hdr = p_hdr_data[i];
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
2014-06-01 09:00:40 +00:00
|
|
|
if (!strcmp(header[i], "Subject")) {
|
2015-10-14 22:39:37 +00:00
|
|
|
if (!mi->keep_subject) {
|
|
|
|
cleanup_subject(mi, hdr);
|
2008-07-13 18:30:12 +00:00
|
|
|
cleanup_space(hdr);
|
2007-07-29 00:57:25 +00:00
|
|
|
}
|
2015-10-14 22:40:04 +00:00
|
|
|
output_header_lines(mi->output, "Subject", hdr);
|
2014-06-01 09:00:40 +00:00
|
|
|
} else if (!strcmp(header[i], "From")) {
|
2009-01-12 23:22:11 +00:00
|
|
|
cleanup_space(hdr);
|
2015-10-19 05:22:10 +00:00
|
|
|
handle_from(mi, hdr);
|
2015-10-14 22:40:04 +00:00
|
|
|
fprintf(mi->output, "Author: %s\n", mi->name.buf);
|
|
|
|
fprintf(mi->output, "Email: %s\n", mi->email.buf);
|
2007-03-12 19:52:04 +00:00
|
|
|
} else {
|
|
|
|
cleanup_space(hdr);
|
2015-10-14 22:40:04 +00:00
|
|
|
fprintf(mi->output, "%s: %s\n", header[i], hdr->buf);
|
2007-03-12 19:52:04 +00:00
|
|
|
}
|
2005-08-28 19:33:16 +00:00
|
|
|
}
|
2015-10-14 22:40:04 +00:00
|
|
|
fprintf(mi->output, "\n");
|
2005-04-12 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 22:40:04 +00:00
|
|
|
static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
|
2006-06-13 20:21:50 +00:00
|
|
|
{
|
2007-11-01 22:57:45 +00:00
|
|
|
int peek;
|
2015-10-18 22:47:02 +00:00
|
|
|
struct strbuf line = STRBUF_INIT;
|
|
|
|
|
2006-06-13 20:21:50 +00:00
|
|
|
cmitmsg = fopen(msg, "w");
|
|
|
|
if (!cmitmsg) {
|
|
|
|
perror(msg);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
patchfile = fopen(patch, "w");
|
|
|
|
if (!patchfile) {
|
|
|
|
perror(patch);
|
|
|
|
fclose(cmitmsg);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-03-12 19:52:04 +00:00
|
|
|
|
2008-07-13 18:30:12 +00:00
|
|
|
p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*p_hdr_data));
|
|
|
|
s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*s_hdr_data));
|
2007-03-12 19:52:04 +00:00
|
|
|
|
2007-11-01 22:57:45 +00:00
|
|
|
do {
|
2015-10-14 22:40:04 +00:00
|
|
|
peek = fgetc(mi->input);
|
2007-11-01 22:57:45 +00:00
|
|
|
} while (isspace(peek));
|
2015-10-14 22:40:04 +00:00
|
|
|
ungetc(peek, mi->input);
|
2007-11-01 22:57:45 +00:00
|
|
|
|
2007-03-12 19:52:04 +00:00
|
|
|
/* process the email header */
|
2015-10-14 22:40:04 +00:00
|
|
|
while (read_one_header_line(&line, mi->input))
|
2015-10-19 05:27:56 +00:00
|
|
|
check_header(mi, &line, p_hdr_data, 1);
|
2007-03-12 19:52:04 +00:00
|
|
|
|
2015-10-14 22:40:04 +00:00
|
|
|
handle_body(mi, &line);
|
2015-10-14 22:35:10 +00:00
|
|
|
fclose(patchfile);
|
|
|
|
|
2015-10-19 05:22:10 +00:00
|
|
|
handle_info(mi);
|
2015-10-18 22:47:02 +00:00
|
|
|
strbuf_release(&line);
|
2006-06-13 20:21:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-14 23:14:57 +00:00
|
|
|
static int git_mailinfo_config(const char *var, const char *value, void *mi_)
|
2009-08-27 05:30:33 +00:00
|
|
|
{
|
2015-10-14 23:14:57 +00:00
|
|
|
struct mailinfo *mi = mi_;
|
|
|
|
|
2013-11-30 20:55:40 +00:00
|
|
|
if (!starts_with(var, "mailinfo."))
|
2015-10-14 23:14:57 +00:00
|
|
|
return git_default_config(var, value, NULL);
|
2009-08-27 05:30:33 +00:00
|
|
|
if (!strcmp(var, "mailinfo.scissors")) {
|
2015-10-14 23:14:57 +00:00
|
|
|
mi->use_scissors = git_config_bool(var, value);
|
2009-08-27 05:30:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* perhaps others here */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-19 05:22:10 +00:00
|
|
|
static void setup_mailinfo(struct mailinfo *mi)
|
|
|
|
{
|
|
|
|
memset(mi, 0, sizeof(*mi));
|
|
|
|
strbuf_init(&mi->name, 0);
|
|
|
|
strbuf_init(&mi->email, 0);
|
2015-10-19 05:30:08 +00:00
|
|
|
strbuf_init(&mi->charset, 0);
|
2015-10-14 23:13:34 +00:00
|
|
|
mi->header_stage = 1;
|
2015-10-14 23:14:57 +00:00
|
|
|
mi->use_inbody_headers = 1;
|
2015-10-19 05:22:10 +00:00
|
|
|
git_config(git_mailinfo_config, &mi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clear_mailinfo(struct mailinfo *mi)
|
|
|
|
{
|
|
|
|
strbuf_release(&mi->name);
|
|
|
|
strbuf_release(&mi->email);
|
2015-10-19 05:30:08 +00:00
|
|
|
strbuf_release(&mi->charset);
|
2015-10-19 05:27:56 +00:00
|
|
|
free(mi->message_id);
|
2015-10-19 05:22:10 +00:00
|
|
|
}
|
|
|
|
|
2005-08-17 05:18:27 +00:00
|
|
|
static const char mailinfo_usage[] =
|
2015-01-13 07:44:47 +00:00
|
|
|
"git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] <msg> <patch> < mail >info";
|
2005-08-28 19:33:16 +00:00
|
|
|
|
2006-07-29 05:44:25 +00:00
|
|
|
int cmd_mailinfo(int argc, const char **argv, const char *prefix)
|
2005-04-12 06:46:50 +00:00
|
|
|
{
|
2007-01-10 05:31:36 +00:00
|
|
|
const char *def_charset;
|
2015-10-19 05:22:10 +00:00
|
|
|
struct mailinfo mi;
|
|
|
|
int status;
|
2007-01-10 05:31:36 +00:00
|
|
|
|
2005-11-28 00:29:38 +00:00
|
|
|
/* NEEDSWORK: might want to do the optional .git/ directory
|
|
|
|
* discovery
|
|
|
|
*/
|
2015-10-19 05:22:10 +00:00
|
|
|
setup_mailinfo(&mi);
|
2005-11-28 00:29:38 +00:00
|
|
|
|
2010-11-02 19:59:07 +00:00
|
|
|
def_charset = get_commit_output_encoding();
|
2015-10-14 23:15:40 +00:00
|
|
|
mi.metainfo_charset = def_charset;
|
2007-01-10 05:31:36 +00:00
|
|
|
|
2005-08-17 05:18:27 +00:00
|
|
|
while (1 < argc && argv[1][0] == '-') {
|
|
|
|
if (!strcmp(argv[1], "-k"))
|
2015-10-14 22:39:37 +00:00
|
|
|
mi.keep_subject = 1;
|
2009-07-15 22:31:12 +00:00
|
|
|
else if (!strcmp(argv[1], "-b"))
|
2015-10-14 22:39:37 +00:00
|
|
|
mi.keep_non_patch_brackets_in_subject = 1;
|
2014-11-25 14:00:55 +00:00
|
|
|
else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id"))
|
2015-10-19 05:27:56 +00:00
|
|
|
mi.add_message_id = 1;
|
2005-08-28 19:33:16 +00:00
|
|
|
else if (!strcmp(argv[1], "-u"))
|
2015-10-14 23:15:40 +00:00
|
|
|
mi.metainfo_charset = def_charset;
|
2007-01-10 05:31:36 +00:00
|
|
|
else if (!strcmp(argv[1], "-n"))
|
2015-10-14 23:15:40 +00:00
|
|
|
mi.metainfo_charset = NULL;
|
2013-11-30 20:55:40 +00:00
|
|
|
else if (starts_with(argv[1], "--encoding="))
|
2015-10-14 23:15:40 +00:00
|
|
|
mi.metainfo_charset = argv[1] + 11;
|
2009-08-27 04:36:05 +00:00
|
|
|
else if (!strcmp(argv[1], "--scissors"))
|
2015-10-14 23:14:57 +00:00
|
|
|
mi.use_scissors = 1;
|
2009-08-27 04:36:05 +00:00
|
|
|
else if (!strcmp(argv[1], "--no-scissors"))
|
2015-10-14 23:14:57 +00:00
|
|
|
mi.use_scissors = 0;
|
2009-11-20 16:12:47 +00:00
|
|
|
else if (!strcmp(argv[1], "--no-inbody-headers"))
|
2015-10-14 23:14:57 +00:00
|
|
|
mi.use_inbody_headers = 0;
|
2005-08-28 19:33:16 +00:00
|
|
|
else
|
2005-11-28 00:29:38 +00:00
|
|
|
usage(mailinfo_usage);
|
2005-08-17 05:18:27 +00:00
|
|
|
argc--; argv++;
|
|
|
|
}
|
|
|
|
|
2005-06-23 16:40:23 +00:00
|
|
|
if (argc != 3)
|
2005-11-28 00:29:38 +00:00
|
|
|
usage(mailinfo_usage);
|
2006-06-13 20:21:50 +00:00
|
|
|
|
2015-10-14 22:40:04 +00:00
|
|
|
mi.input = stdin;
|
|
|
|
mi.output = stdout;
|
|
|
|
status = !!mailinfo(&mi, argv[1], argv[2]);
|
2015-10-19 05:22:10 +00:00
|
|
|
clear_mailinfo(&mi);
|
|
|
|
|
|
|
|
return status;
|
2005-04-12 06:46:50 +00:00
|
|
|
}
|