@matheusbsbs / matheus-bagliano / commits / c64d84f145
Fork 0

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 <jwhite@codeweavers.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeremy White committed Feb 12, 2009 at 08:58 UTC c64d84f1452ec56fd1586493a0b0707bf7442c42
2 files changed +60
Documentation/git-imap-send.txt
+7
@@ -64,6 +64,13 @@ imap.sslverify::
64 used by the SSL/TLS connection. Default is `true`. Ignored when
65 imap.tunnel is set.
66
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 +
74 Examples
75 ~~~~~~~~
76
imap-send.c
+53
@@ -135,6 +135,7 @@ struct imap_server_conf {
135 char *pass;
136 int use_ssl;
137 int ssl_verify;
138 + int use_html;
139 };
140
141 struct imap_store_conf {
@@ -1263,6 +1264,53 @@ static int imap_store_msg(struct store *gctx, struct msg_data *data, int *uid)
1264 return DRV_OK;
1265 }
1266
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 +
1314 #define CHUNKSIZE 0x1000
1315
1316 static int read_message(FILE *f, struct msg_data *msg)
@@ -1339,6 +1387,7 @@ static struct imap_server_conf server = {
1387 NULL, /* pass */
1388 0, /* use_ssl */
1389 1, /* ssl_verify */
1390 + 0, /* use_html */
1391 };
1392
1393 static char *imap_folder;
@@ -1377,6 +1426,8 @@ static int git_imap_config(const char *key, const char *val, void *cb)
1426 server.tunnel = xstrdup(val);
1427 else if (!strcmp("sslverify", key))
1428 server.ssl_verify = git_config_bool(key, val);
1429 + else if (!strcmp("preformattedHTML", key))
1430 + server.use_html = git_config_bool(key, val);
1431 return 0;
1432 }
1433
@@ -1439,6 +1490,8 @@ int main(int argc, char **argv)
1490 fprintf(stderr, "%4u%% (%d/%d) done\r", percent, n, total);
1491 if (!split_msg(&all_msgs, &msg, &ofs))
1492 break;
1493 + if (server.use_html)
1494 + wrap_in_html(&msg);
1495 r = imap_store_msg(ctx, &msg, &uid);
1496 if (r != DRV_OK)
1497 break;