From 0b94ba0a75385a7c2ff456ba40244159e2bcb863 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Tue, 5 Feb 2013 16:03:50 -0800 Subject: [PATCH] Don't attach zero-byte files to message: Closes #5587 --- THANKS | 1 + src/client/composer/composer-window.vala | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/THANKS b/THANKS index 6d4261c8..90e8ee2a 100644 --- a/THANKS +++ b/THANKS @@ -2,6 +2,7 @@ The Geary team would like to thank the following contributors: Robert Ancell Jürg Billeter +Martijn Braam Andrea Corbellini Sergey Shnatsel Davidoff Joanmarie Diggs diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala index f023814c..2e17991c 100644 --- a/src/client/composer/composer-window.vala +++ b/src/client/composer/composer-window.vala @@ -566,14 +566,24 @@ public class ComposerWindow : Gtk.Window { } private bool add_attachment(File attachment_file) { - if (!attachment_file.query_exists()) { - attachment_failed(_("\"%s\" does not exist").printf(attachment_file.get_path())); + FileInfo attachment_file_info; + try { + attachment_file_info = attachment_file.query_info("standard::size,standard::type", + FileQueryInfoFlags.NONE); + } catch(Error e) { + attachment_failed(_("\"%s\" could not be found.").printf(attachment_file.get_path())); return false; } - if (attachment_file.query_file_type(FileQueryInfoFlags.NONE) == FileType.DIRECTORY) { - attachment_failed(_("\"%s\" is a folder").printf(attachment_file.get_path())); + if (attachment_file_info.get_file_type() == FileType.DIRECTORY) { + attachment_failed(_("\"%s\" is a folder.").printf(attachment_file.get_path())); + + return false; + } + + if (attachment_file_info.get_size() == 0){ + attachment_failed(_("\"%s\" is an empty file.").printf(attachment_file.get_path())); return false; } @@ -586,13 +596,13 @@ public class ComposerWindow : Gtk.Window { debug("File '%s' could not be opened for reading. Error: %s", attachment_file.get_path(), e.message); - attachment_failed(_("\"%s\" could not be opened for reading").printf(attachment_file.get_path())); + attachment_failed(_("\"%s\" could not be opened for reading.").printf(attachment_file.get_path())); return false; } if (!attachment_files.add(attachment_file)) { - attachment_failed(_("\"%s\" already attached for delivery").printf(attachment_file.get_path())); + attachment_failed(_("\"%s\" already attached for delivery.").printf(attachment_file.get_path())); return false; }