aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-06-30 05:49:54 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-06-30 05:49:54 +0000
commitf3fb1172b4b6ecf8254e52d03bb326f78cd58e57 (patch)
tree3d3da8c64e6ad1a1f1025fdf89d12bc43538a484 /src
parent59e5f5b6f481f379846734755603bae75eb98460 (diff)
when sending messages, check for line length limit and display warning if exceeds.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@386 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src')
-rw-r--r--src/compose.c24
-rw-r--r--src/utils.c26
-rw-r--r--src/utils.h5
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);