Commit graph

19 commits

Author SHA1 Message Date
Michael James Gratton
e8dcad9a43 Add unit tests for adding accounts.
* src/engine/api/geary-engine.vala (Engine::create_orphan_account): Fix
  sense of test when determining the next account id to use. Add unit
  tests.
  (Engine::add_account): Made public so it can be used in public test.
2017-02-23 11:33:12 +11:00
Michael James Gratton
9f5def0d0f Re-implement alt text filename fallback when saving inline images.
This restores some old behaviour after teh WK2 port.

* src/client/conversation-viewer/conversation-message.vala
  (ConversationMessage): Add alt_text param to ::save_image
  signal. Replace ::set_action_param_string with
  ::set_action_param_string so we can pass a (url, alt_text) tuple for
  the save_image tuple and update call sites. Set this tuple for the
  action when enabling it, and pass the two values to the ::save_image
  signal handler when activated.

* src/engine/api/geary-attachment.vala (Attachment::get_safe_file_name):
  Add alt_file_name param method, use that when constructing a file
  name. Add doc comment, test.

* src/client/application/geary-controller.vala: Updated to pass alt text
  from save_imge signal emission all thr way through to
  get_safe_file_name.
2017-02-16 08:58:58 +11:00
Michael James Gratton
2a7fca9397 Clean up default filename when saving attachments.
This ensures both inline images are saved using the specified content
filename, if any, and that an extension is attempted to be guessed when
no filename is specified.

Fixes Bug 713999, Bug 712923, Bug 778026.

* src/client/application/geary-controller.vala: Major rework of how
  attachments are saved. Rework how save dialogs are constructed,
  combining common code paths into one constrcutor method. Split up code
  for saving one attachment vs many into two different methods. Ensure
  all code baths ultimately use the same method to do the actual
  saving. Lookup a attachment when saving an inline image and use that
  by default. Get filenames from new Attachment::get_useful_filename
  method that guesses if needed.

* src/client/conversation-viewer/conversation-message.vala
  (ConversationMessage::save_image): Fix name of first param to reflect
  what it actually is.

* src/engine/api/geary-attachment.vala (Attachment): Add
  ::get_safe_filename method that checks the type of both the
  attachment's content and its file name, if any. Will construct an
  appropriate file name if non is given. Add unit tests.

* src/engine/api/geary-email.vala (Email): Add new
  ::get_attachment_by_content_id to lookup attachments by MIME
  content-id. Rename old ::get_attachment method to disambiguate.
2017-02-16 08:44:27 +11:00
Michael James Gratton
183da8bd3f Add ContentType.is_default and unit test. 2017-02-15 17:50:49 +11:00
Michael James Gratton
e3d708b8e6 Add ContentType methods for determining file name extenions and type sniffing.
* src/engine/mime/mime-content-type.vala (ContentType): Add ::guess_type
  and ::get_file_name_extension methods, unit tests.
2017-02-15 17:50:34 +11:00
Michael James Gratton
31fbfd4047 Add IdleManager class for sane main loop idle scheduling. 2017-02-09 10:54:45 +11:00
Michael James Gratton
97709785d7 Fix brown-paper-bag bug in Geary.JS::escape_string.
* src/engine/util/util-js.vala (Geary.JS): Correctly append escaped char
  to the string. Add unit tests.
2017-02-01 00:41:45 +11:00
Michael James Gratton
320134783c Add Geary.Inet::is_valid_display_host and tests. 2017-02-01 00:41:44 +11:00
Michael James Gratton
b1d4eaa32f Implement milliseconds ctor and tests for Geary.TimeoutManager. 2017-02-01 00:41:44 +11:00
Michael James Gratton
d2bc005d62 Don't run slow timer tests unless specifically requested. 2017-02-01 00:41:44 +11:00
Michael James Gratton
271b9460ec Add Geary.TimeoutManager as a high-level interface to GLib.Timeout. 2017-02-01 00:41:43 +11:00
Michael James Gratton
7654b16908 Add unit test for Geary.RFC822.Message::get_preview. 2016-12-23 10:38:23 +10:30
Michael James Gratton
fdb3c6cac6 Make to_preview_text() require UNIX (LF), not RFC833 (CRLF) strings.
Fixes Base64 encoded parts when fetching PREVIEW, and armour, etc
stripping etc not being applied to previews geneated via
Geary.RFC822.Message.

* src/engine/rfc822/rfc822-utils.vala
  (Geary.RFC822.Utils::to_preview_text): Assume line endings are LF
  encoded, update doc comment and unit tests to reflect that.

* src/engine/rfc822/rfc822-message-data.vala (PreviewText.with_header):
  Add CRLF filter to preveiw text to strip CR chars from lines.
2016-12-21 10:45:21 +11:00
Michael James Gratton
5b97efa529 Add test case handling HTML entities when converting to text.
* test/engine/util-html-test.vala (UtilTest::remove_html_tags): Added
  test case for HTML entities.
2016-12-20 12:27:07 +11:00
Michael James Gratton
f577e41ce8 Workaround conversation message preview being cut off on wide screens.
Bug 772607.

* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Don't
  truncate the preview here - fetch preview will already be truncated,
  and the conversation message preview needs the full text anyway. Update
  unit tests.

* src/client/conversation-viewer/conversation-message.vala
  (ConversationMessage::ConversationMessage): Since we need to know if
  the preview has been truncated so we know if we need to add an elipsis
  or not, get the full preview and tuncate it here if needed.

* src/engine/rfc822/rfc822-message.vala (Message): Don't bother trying to
  set the preview when creating a Geary.Email from the message. Minor
  code & doc cleanup.

* src/engine/api/geary-email.vala (Email): Double length of max fetch
  preview so HTML parts might actually pick up some content. Tidy up doc
  comments.
2016-12-20 12:25:44 +11:00
Michael James Gratton
821ae7c987 Remove hacks for MIME part headers when processing preview text.
* src/engine/rfc822/rfc822-utils.vala (to_preview_text): Don't bother to
  check for MIME Content-* headers now that we are only treating a part
  as plain text if it is actually text/plain.
2016-12-20 10:15:24 +11:00
Michael James Gratton
1879ea8480 Combine fetch and convo message codepaths for generating preview text.
Ensures that both appear the same to the user, and that the conversation
message preview gets the same armour and quote stripping that the fecth
preview does.

Added tests.

Bug 714317

* src/engine/rfc822/rfc822-utils.vala
  (Geary.RFC822.Utils::to_preview_text): New common function to handle
  generating a preview from a RFC 822 plain text or HTML string.

* src/engine/rfc822/rfc822-message-data.vala (PreviewText::with_header):
  Move plain text armour and quote stripping to to_preview_text(), call
  that to generate preview text.

* src/engine/rfc822/rfc822-message.vala (Message::get_preview): call
  to_preview_text() to generate the preview text.
2016-12-19 18:47:38 +11:00
Michael James Gratton
deb0c415d0 Fix HTML, CSS and JS leaking into conversation list preview. Bug 714317
When generating the preview, only the first 128 bytes of the first MIME
part is fetched and used. If this part is text/html with a significant
amount of embedded CSS, then there is a good chance the string passed to
Geary.HTML::remove_html_tags() will be invalid, or be missing closing
elements. Since that function uses regexes that require balanced tags to
remove script and style blocks, then it was very possible that in these
cases this method will miss removing these blocks.

To solve this, remove_html_tags() is removed and its call sites are
replaced by calls to Geary.HTML::html_to_text(), which has been tidyied
up to produce more human-readable result.

Add unit tests to cover new html_to_text functionality and its call
sites.

* src/engine/util/util-html.vala: Remove remove_html_tags(). Update
  html_to_text() to not just insert line breaks, but also insert spaces
  and alt text, and ignore tags like HEAD, SCRIPT and STYLE, as
  appropriate. Add an optional param to also allow skipping BLOCKQUOTE
  elements, which we don't want in the preview.
2016-12-19 00:45:41 +11:00
Michael James Gratton
7683044d61 Add an initial/example unit test. 2016-12-13 11:27:19 +11:00