diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compose.c | 24 | ||||
-rw-r--r-- | src/utils.c | 26 | ||||
-rw-r--r-- | src/utils.h | 5 |
3 files changed, 53 insertions, 2 deletions
diff --git a/src/compose.c b/src/compose.c index 2f1dee05..5967cc0b 100644 --- a/src/compose.c +++ b/src/compose.c @@ -2625,6 +2625,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, const gchar *body_charset; const gchar *src_charset = CS_INTERNAL; EncodingType encoding; + gint line; if ((fp = fopen(file, "wb")) == NULL) { FILE_OP_ERROR(file, "fopen"); @@ -2731,10 +2732,31 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, src_charset, out_charset, body_charset, procmime_get_encoding_str(encoding)); + /* check for line length limit */ + if (encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 && + check_line_length(buf, 1000, &line) < 0) { + AlertValue aval; + gchar *msg; + + msg = g_strdup_printf + (_("Line %d exceeds the line length limit (998 bytes).\n" + "The contents of the message might be broken on the way to the delivery.\n" + "\n" + "Send it anyway?"), line + 1); + aval = alertpanel(_("Warning"), msg, _("Yes"), _("+No"), NULL); + if (aval != G_ALERTDEFAULT) { + g_free(msg); + fclose(fp); + unlink(file); + g_free(buf); + return -1; + } + } + /* write headers */ if (compose_write_headers(compose, fp, out_charset, body_charset, encoding, is_draft) < 0) { - g_warning(_("can't write headers\n")); + g_warning("can't write headers\n"); fclose(fp); unlink(file); g_free(buf); diff --git a/src/utils.c b/src/utils.c index f5ba1125..932c8320 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1133,6 +1133,32 @@ gint get_quote_level(const gchar *str) return quote_level; } +gint check_line_length(const gchar *str, gint max_chars, gint *line) +{ + const gchar *p = str, *q; + gint cur_line = 0, len; + + while ((q = strchr(p, '\n')) != NULL) { + len = q - p + 1; + if (len > max_chars) { + if (line) + *line = cur_line; + return -1; + } + p = q + 1; + ++cur_line; + } + + len = strlen(p); + if (len > max_chars) { + if (line) + *line = cur_line; + return -1; + } + + return 0; +} + gchar *strstr_with_skip_quote(const gchar *haystack, const gchar *needle) { register guint haystack_len, needle_len; diff --git a/src/utils.h b/src/utils.h index 46767d90..e3cfa75f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2004 Hiroyuki Yamamoto + * Copyright (C) 1999-2005 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -299,6 +299,9 @@ void subst_for_filename (gchar *str); gboolean is_header_line (const gchar *str); gboolean is_ascii_str (const guchar *str); gint get_quote_level (const gchar *str); +gint check_line_length (const gchar *str, + gint max_chars, + gint *line); gchar *strstr_with_skip_quote (const gchar *haystack, const gchar *needle); |