Skip to content

Commit c64d84f

Browse files
jwhite66gitster
authored andcommitted
imap.preformattedHTML to tell Thunderbird to send non-flowed text
Many e-mail based development communities require non-flowed text to carry patches to prevent whitespaces from getting mangled, but there is no easy way to tell Thunderbird MUA not to use format=flowed, unless you configure it to do so unconditionally for all outgoing mails. A workaround for users who use git-imap-send is to wrap the patch in "pre" element in the draft folder as an HTML message, and tell Thunderbird to send "text only". Thunderbird turns such a message into a non-flowed plain text when sending it out, which is what we want for patch e-mails. Signed-off-by: Jeremy White <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e9cc02f commit c64d84f

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Documentation/git-imap-send.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ imap.sslverify::
6464
used by the SSL/TLS connection. Default is `true`. Ignored when
6565
imap.tunnel is set.
6666

67+
imap.preformattedHTML::
68+
A boolean to enable/disable the use of html encoding when sending
69+
a patch. An html encoded patch will be bracketed with <pre>
70+
and have a content type of text/html. Ironically, enabling this
71+
option causes Thunderbird to send the patch as a plain/text,
72+
format=fixed email. Default is `false`.
73+
6774
Examples
6875
~~~~~~~~
6976

imap-send.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct imap_server_conf {
135135
char *pass;
136136
int use_ssl;
137137
int ssl_verify;
138+
int use_html;
138139
};
139140

140141
struct imap_store_conf {
@@ -1263,6 +1264,53 @@ static int imap_store_msg(struct store *gctx, struct msg_data *data, int *uid)
12631264
return DRV_OK;
12641265
}
12651266

1267+
static void encode_html_chars(struct strbuf *p)
1268+
{
1269+
int i;
1270+
for (i = 0; i < p->len; i++) {
1271+
if (p->buf[i] == '&')
1272+
strbuf_splice(p, i, 1, "&amp;", 5);
1273+
if (p->buf[i] == '<')
1274+
strbuf_splice(p, i, 1, "&lt;", 4);
1275+
if (p->buf[i] == '>')
1276+
strbuf_splice(p, i, 1, "&gt;", 4);
1277+
if (p->buf[i] == '"')
1278+
strbuf_splice(p, i, 1, "&quot;", 6);
1279+
}
1280+
}
1281+
static void wrap_in_html(struct msg_data *msg)
1282+
{
1283+
struct strbuf buf = STRBUF_INIT;
1284+
struct strbuf **lines;
1285+
struct strbuf **p;
1286+
static char *content_type = "Content-Type: text/html;\n";
1287+
static char *pre_open = "<pre>\n";
1288+
static char *pre_close = "</pre>\n";
1289+
int added_header = 0;
1290+
1291+
strbuf_attach(&buf, msg->data, msg->len, msg->len);
1292+
lines = strbuf_split(&buf, '\n');
1293+
strbuf_release(&buf);
1294+
for (p = lines; *p; p++) {
1295+
if (! added_header) {
1296+
if ((*p)->len == 1 && *((*p)->buf) == '\n') {
1297+
strbuf_addstr(&buf, content_type);
1298+
strbuf_addbuf(&buf, *p);
1299+
strbuf_addstr(&buf, pre_open);
1300+
added_header = 1;
1301+
continue;
1302+
}
1303+
}
1304+
else
1305+
encode_html_chars(*p);
1306+
strbuf_addbuf(&buf, *p);
1307+
}
1308+
strbuf_addstr(&buf, pre_close);
1309+
strbuf_list_free(lines);
1310+
msg->len = buf.len;
1311+
msg->data = strbuf_detach(&buf, NULL);
1312+
}
1313+
12661314
#define CHUNKSIZE 0x1000
12671315

12681316
static int read_message(FILE *f, struct msg_data *msg)
@@ -1339,6 +1387,7 @@ static struct imap_server_conf server = {
13391387
NULL, /* pass */
13401388
0, /* use_ssl */
13411389
1, /* ssl_verify */
1390+
0, /* use_html */
13421391
};
13431392

13441393
static char *imap_folder;
@@ -1377,6 +1426,8 @@ static int git_imap_config(const char *key, const char *val, void *cb)
13771426
server.tunnel = xstrdup(val);
13781427
else if (!strcmp("sslverify", key))
13791428
server.ssl_verify = git_config_bool(key, val);
1429+
else if (!strcmp("preformattedHTML", key))
1430+
server.use_html = git_config_bool(key, val);
13801431
return 0;
13811432
}
13821433

@@ -1439,6 +1490,8 @@ int main(int argc, char **argv)
14391490
fprintf(stderr, "%4u%% (%d/%d) done\r", percent, n, total);
14401491
if (!split_msg(&all_msgs, &msg, &ofs))
14411492
break;
1493+
if (server.use_html)
1494+
wrap_in_html(&msg);
14421495
r = imap_store_msg(ctx, &msg, &uid);
14431496
if (r != DRV_OK)
14441497
break;

0 commit comments

Comments
 (0)