Commit graph

142 commits

Author SHA1 Message Date
Michael Gratton
3e461e7b45 Don't include empty root folder path segment constructing a mailbox name
This fixes attempts to create special mailboxes as "/Special" instead
of "Special".
2018-09-25 23:33:12 +10:00
Michael Gratton
f3ad1fe00d Merge branch 'wip/29-ms-breaks-plain-sigs' into 'master'
Fix plain text signatures losing their formatting when rendered by MS products

See merge request GNOME/geary!33
2018-09-12 11:09:34 +00:00
Michael James Gratton
43ba38bb05 Add unit test for IMAP FETCH command constructor. 2018-09-01 22:09:18 +10:00
Michael James Gratton
ab9d0c27ad Make Imap.Command a top-level type rather than inherit from Parameter.
Instead, make the args property a parameter list, and add params to that.

This means Command's serialize method have a different signature compared
to Parameter's, letting us do some more interesting things with it.
2018-09-01 22:09:18 +10:00
Michael James Gratton
51b44f0f4b Remove ListParameter.parent property so lists can have multiple parents.
The ListParameter.parent property only existed to make the deserialier's
life easier, but is also why sketchy code was needed for appending search
criteria from a ServerSearchEmail replay op to the actual IMAP search
command sent to the server.

This removes the property altogether, and replaces its only use in
Deserialier with a stack, as nature intended. This means lists can be
added to more than one other list, and e.g. when a search is executed,
the search critera can be used for multiple requests.
2018-09-01 22:09:18 +10:00
Michael James Gratton
183a9f3e7a Don't quote an RFC 822 mailbox local part if it has a '.' in the middle.
This breaks sending mail via Yahoo since it doesn't like it if the SMTP
return path local part is quoted.

We can't use GMime.utils_quote_string since it's currently broken, so
implement our own quoter.
2018-07-28 17:57:48 +10:00
Michael James Gratton
f3e8b26227 Fix MS mailers munging plain-text signatures in HTML body parts.
Geary previously wrapped plain text sigs (i.e. those that did not contain
any HTML elements) in a DIV styled to preserve whitespace. This is all
perfectly fine, except that certain Microsoft products munged the email
for presentation and destroy the whitespace present in the message body,
causing the sig to be mis-rendered.

This works around their shitty software by using BRs instead of the DIV,
also escapes other control chars and sequential whitespace as well when
using a plain text sig. It also stops trying to smart-escape quoted reply
text, since we know it's going to be HTML from the conversation viewer,
meaning smart escaping only needs to be used for sigs.

See issue #29
2018-07-28 15:53:50 +10:00
Michael James Gratton
b345af61e3 Fix mailbox names not being sent to the server quoted if needed.
Since MailboxParameter inherited from StringParameter directly, it meant
that we could never send mailbox names as quoted strings. Also, the
modified-UTF-7 encoding used for mailbox names does not encode
atom-specials such as "\", so if a mailbox name contained one or more of
these, it would be sent to the mail server unquoted.

This removes the MailboxParameter class altogether, and does the
parameter conversion to/from appropriate StringParameter subclasses as
needed. Also adds unit tests for param conversion for ASCII,
atom-specials, and non-ASCII mailbox names.

Fixes issue #40
2018-07-20 13:43:42 +10:00
Michael James Gratton
d9c913268d Fix Imap.DataFormat.is_atom_special not flagging \, [, or DEL as special
Add unit tests.
2018-07-20 13:29:09 +10:00
Michael James Gratton
4cc7cf1769 Fix empty folder/no matching search UI not showing up.
This fixes a regression introduced by commit 0ea1fe6c3.

* src/engine/app/app-conversation-monitor.vala (ConversationMonitor):
  Signal scan_complete from the same method call that we signal
  scan_started, so that a) we know it will get fired, even if no messages
  are loaded (the issue introduced by 0ea1fe6c3) and b) so we can get rid
  of the inside_scan complexity.
2018-07-08 15:11:44 +10:00
Michael James Gratton
f0ac998684 Allow blacklisting folders when obtaining email from conversations.
Add an optional blacklist arg to Conversations.get_email and
get_earliest_sent_email and similar methods that specifies folders that
email returned should not be contained within. Also add unit tests.
2018-07-07 11:43:51 +10:00
Michael James Gratton
0e6d499808 Fix AccountInformation.has_email_address, add tests. 2018-07-02 21:22:15 +10:00
Michael James Gratton
98e2d319eb Remove CMake build.
Closes Bug 777044.
2018-06-13 22:30:10 +10:00
Michael James Gratton
13c92c3f7e Convert Credentials and CredentialsMediator to refer to tokens, tidy up.
* src/engine/api/geary-credentials.vala (Credentials): Refer to auth
  tokens, not passwords, so we can use the same object for OAuth2
  auth. Update call sites.

* src/engine/api/geary-credentials-mediator.vala (CredentialsMediator):
  Refer to auth tokens, not passwords, so we can use the same object for
  OAuth2 auth. Remove saving and clearing methods from the interface
  since that's only supported for password storage, not SSO like
  GOA. Update implementations and call sites.

* src/engine/api/geary-account-information.vala (AccountInformation):
  Replace many byzantine auth management methods with just a few for
  handling loading and prompting. Remove ServiceFlag enum now it is no
  longer used. Clean up call sites.

* src/client/accounts/account-manager.vala (AccountInformation): Manage
  initial saving and final deletion of libsecret based accounts here,
  rather than all over the code base.
2018-06-12 13:25:05 +10:00
Michael James Gratton
acac68afed Make ServiceInformation.mediator a required, read-only property. 2018-06-12 13:25:05 +10:00
Michael James Gratton
054d53a498 Move CredentalsMethod enum and property to Credentals.
* src/engine/api/geary-credentials.vala (Credentals): Move
  CredentalsMethod enum here, rename to Method. Add supported_method
  property, make all props read-only. Update call sites.
2018-06-12 13:25:05 +10:00
Michael James Gratton
863a11e780 Rename Geary.Service to Protocol, move into ServiceInformation source. 2018-06-12 13:25:05 +10:00
Michael James Gratton
677b1cec86 Rename ServiceInformation.service to protocol to reduce redundancy. 2018-06-12 13:25:05 +10:00
Rico Tzschichholz
20cd9823a7 bindings: Drop custom javascriptcore-4.0 and webkit2gtk-4.0 vapi 2018-06-04 12:55:59 +02:00
Michael James Gratton
2dcc6c7e4f Fix critical when editing account settings.
Ensure when getting a temp copy of an AccountInformation, that its
IMAP and SMTP ServiceInformation members are also copied.
2018-05-28 14:06:39 +10:00
Michael James Gratton
fc795c7ec1 Fix signatures being mangled between getting loaded and saved. 2018-05-28 14:06:39 +10:00
Michael James Gratton
e6891f528a Clean up Engine's account added/removed signals.
* src/engine/api/geary-engine.vala (Engine): Move account_added and
  account_removed signals to AccountRemoved since the engine isn't
  tracking this any more. Remove bool param from add_account for the same
  reason and update call sites.
2018-05-28 00:55:59 +10:00
Oskar Viljasaar
5108a21def Implement GOA support for password-based accounts 2018-05-25 15:48:46 +10:00
Michael James Gratton
4e0950f9bc Introduce a ConfigFile class to improve config management.
ConfigFile is a GLib.KeyFile-like class (and is backed by a KeyFile) that
nonetheless provides convenient a high-level API for getting and setting
grouped config values and asynchronous loading and saving.

* src/engine/util/util-config-file.vala: New ConfigFile class.

* src/engine/api/geary-service-information.vala (ServiceInformation):
  Require ConfigFile groups rather than KeyFile instances for loading and
  saving. Update subclasses and unit tests.

* src/client/accounts/account-manager.vala (AccountManager): Move generic
  account key consts here from Config. Instead of using KeyFile directly,
  use ConfigFile groups for loading and saving settings. Rename load and
  save methods to be a bit more consistent with the class's role, and
  make save_account() throw its errors so they can be reported to the
  user. Update call sites.

* src/client/accounts/local-service-information.vala
  (LocalServiceInformation): Move service-specific config key consts
  here, use new ConfigFile groups for loading and saving.

* src/engine/api/geary-config.vala: Removed, all config consts have been
  moved to the classes using them and KeyFile convenience methods
  subsumed by ConfigFile.
2018-05-25 15:42:56 +10:00
Michael James Gratton
4fdeb9db47 Ensure AccountInformation objects always have valid IMAP/SMTP services.
* src/engine/api/geary-engine.vala (Engine): Require a ServiceInformation
  object for IMAP and SMTP when creating orphan info objects. Update call
  sites.

* src/client/accounts/account-manager.vala (AccountManager): provide
  factory methods for constructing local service info objects. Use these
  when re-constituting accounts. Use a singleton SecretMediator object
  instance as a bonus.

* src/client/accounts/add-edit-page.vala (AddEditPage): Get
  ServiceInformation objects from the account manager, pass an instance
  of GearyApplication through so it has access to the manager. Update
  call chains back to GearyController to pass the app instance through.
2018-05-24 16:52:54 +10:00
Michael James Gratton
91e85a6647 Make EngineTest a bit more robust. 2018-05-24 15:52:36 +10:00
Michael James Gratton
ebf499927c Make KeyFile arg mandatory when loading/saving service information.
* src/engine/api/geary-service-information.vala (ServiceInformation):
  Make KeyFile arg mandator for load and save methods, since it will
  always need to be provided. Update subclasses.

* src/client/accounts/local-service-information.vala
  (LocalServiceInformation): Remove from Geary package since it's not an
  engine class. Update call sites.
2018-05-24 15:38:42 +10:00
Michael James Gratton
0d3f10f51f Clean up user directory management.
Instead of passing in user config and data base dirs to the Engine from
the app, then pulling them out from the engine again from the app, just
store them in AccountManager, since that's where they are needed.

* src/client/accounts/account-manager.vala (AccountManager): Store user
  config and data base dirs directly rather than getting them from the
  engine. Split account directory creation out into a separate method so
  they aren't re-made every time the config is saved.

* src/engine/api/geary-engine.vala (Engine): Remove user config and data
  dir properties and open_async args. Update call sites and unit tests.

* src/client/application/geary-controller.vala (GearyController): Chase
  AccountManager and Engine API changes. Ensure account dirs are created
  when an new account is added.

* src/engine/api/geary-account-information.vala (AccountInformation):
  Explicitly track copies rather relying on account dirs being
  null. Don't require dirs be set in the default ctor, since they won't
  be known, provide a method for updating them later on instead.
2018-05-24 15:34:29 +10:00
Michael James Gratton
9f3ec5bfcb Update unit tests to work with ServiceInfo API changes. 2018-05-23 17:53:23 +10:00
Michael James Gratton
1b49fc1104 Ensure Db.Database corruption check doesn't fail on missing DB file.
* src/engine/db/db-database.vala (Context): Only run the corruption check
  if there is a DB file and the file exists. Add unit tests.
2018-05-21 21:01:34 +10:00
Michael James Gratton
65b44c3b3a Don't strip CRLF from iCal, vCard, and other formats that requires them.
* src/engine/rfc822/rfc822-part.vala (Part): Add a blacklist for text
  types that shouldn't have CRLF's stripped. Add unit tests.
2018-05-20 12:51:59 +10:00
Michael James Gratton
440a4d5932 Merge branch 'wip/726281-text-attachment-crlf'. Fixes Bug 726281. 2018-05-19 14:59:10 +10:00
Michael James Gratton
fe9461e439 Add a unit test for upgrading an actual Geary v0.6 database. 2018-05-19 14:55:19 +10:00
Michael James Gratton
386f9864c7 Revert "Merge branch 'wip/ricotz/webkit'. Fixes Bug 788113."
This reverts commit 43341cd3e3, reversing
changes made to ffb4befdd8.

This is causing segfault in Geary.JS.to_string_released() when running
client tests, so reverting until a solution is found.
2018-05-19 13:57:58 +10:00
Michael James Gratton
43341cd3e3 Merge branch 'wip/ricotz/webkit'. Fixes Bug 788113.
This became necessary sooner rather than later since WebKitGTK 2.21
with the upstream valac bindings are now incompatible with the custom
in-source bindings.
2018-05-19 10:06:45 +10:00
Michael James Gratton
f78939ce00 Push GResource URL for test data down so it's accessible to all tests. 2018-05-19 09:26:09 +10:00
Michael James Gratton
d91dd36484 Update unit tests to ensure text attachments saved without CRLF. 2018-05-19 09:26:09 +10:00
Michael James Gratton
ba861b8ed1 Fix failing RFC822.Mailbox test.
Reverting commit 1d8c4aea broke the mailbox class a bit. This fixes the
issue, introduces Ascii.last_index_of which is needed by Mailbox anyway,
and adds some test for it. Also 'optimises' Ascii.index_of bit as well.
2018-05-17 15:41:28 +10:00
Michael James Gratton
f1c797650f Ensure we always use the one, same codepath when decoding text content.
This introduces the Geary.RFC822.Part class, which provides a place to
MIME entity body decoding code so it can be reused when needed. It also
provides a place to put common GMime to Geary object conversion, and
apply some common policy decisions, such as what is the default content
type if none is specified.

* src/engine/rfc822/rfc822-part.vala: New Part class that represents a
  MIME entity. Move code for both decoding entity body from
  RFC822.Message and code for cleaning content filename from RFC822.Util
  to here. Convert GMime entity header objects into their Geary
  equivalents and make available as properties. Provide a common means of
  determining the content type of the part if not explicitly set.

* src/engine/rfc822/rfc822-message-data.vala (PreviewText.with_header):
  Construct a RFC822.Part and use that for decoding preview text. Swap
  args to make some more sense and update call sites.

* src/engine/rfc822/rfc822-message.vala (InlinePartReplacer): Simply pass
  through an instance of a RFC822.Part rather than the multi-arg list,
  since that has all the data needed by replacers.

* src/engine/imap-db/imap-db-attachment.vala (Attachment): Require and
  use RFC822.Part instances for obtaining attachment bodies rather than
  GMime.Part instances. Update call sites.
2018-05-10 13:53:24 +10:00
Michael James Gratton
bfe665d1a0 Add unit tests for Geary.RFC822.Message body content, fix a few issues.
* src/engine/rfc822/rfc822-message.vala (Message): Fix has_plain_body(),
  handle the case where displayed MIME entities (as opposed to attached
  ones) with no Content-Type default to US-ASCII, per the RFC.

* test/engine/rfc822-message-test.vala (MessageTest): Add tests for
  testing and accessing body content as both plain text and HTML. Use
  GResources for accessing test message bodies rather than extremely long
  const strings.
2018-05-10 13:53:24 +10:00
Michael James Gratton
a2a95686b4 Support default content types for both displayed and attached entities.
This replaces the const ContentType.DEFAULT_CONTENT_TYPE string and
related code with static defaults for both displayed and attached MIME
entities.

* src/engine/mime/mime-content-type.vala (ContentType): Replace
  DEFAULT_CONTENT_TYPE const with static DISPLAY_DEFAULT and
  ATTACHMENT_DEFAULT static instances. Remove is_default() since that no
  longer makes sense. Update call sites and unit tests.

* src/engine/mime/mime-content-parameters.vala (ContentParameters): Make
  the class immutable so it is safe to be used as a component of the
  static ContentType DISPLAY_DEFAULT and ATTACHMENT_DEFAULT members.
2018-05-10 13:53:24 +10:00
Michael James Gratton
037af00740 Improve how attachments are saved to the db and disk.
This mostly aims to make the Geary.Attachment and ImapDB.Attachment
objects usable more generally for managing attachments, allowing
these to be instantiated once, persisted, and then reused, rather than
going through a number of representations (GMime, SQlite, Geary) and
having to be saved and re-loaded.

* src/engine/api/geary-attachment.vala (Attachment): Remove id property
  and allow both file and filesize properties to be set after instances
  are constructed. Update call sites.

* src/engine/api/geary-email.vala (Email): Remove get_attachment_by_id
  since it unused.

* src/engine/imap-db/imap-db-attachment.vala (Attachment): Chase
  Geary.Attachment API changes, move object-specific persistence code
  into methods on the actual object class itself and modernise a
  bit. Rename static methods to be a bit more terse. Update call sites
  and add unit tests.

* src/engine/imap-db/imap-db-folder.vala (Folder): Rather than saving
  attachments to the db then reloading them to add them to their email
  objects, just instantiate Attachment instances once, save and then add
  them.

* src/engine/imap-db/imap-db-gc.vala (GC): Replace custom SQL with
  existing accessor for listing attachments.

* src/engine/util/util-stream.vala (MimeOutputStream): New adaptor class
  for GMime streams to GIO output streams.
2018-05-10 13:53:24 +10:00
Michael James Gratton
15d8789685 Move attachment related code from ImapDB.Folder to Attachment. 2018-05-08 13:28:48 +10:00
Michael James Gratton
5c73fbcba5 Push all ImapDB path management down into to ImapDb.Account.
This stops generating account storage paths, and in particular the
location of attachment files, in a number of different places. Instead,
we determine the paths once, in ImapDb.Account and pass them around as
needed. This will help making the ImapDB classes unit-testable, and
in particular ImapDb.Folder by passing an instance of Db.Database,
rather than ImapDb.Database.
2018-05-08 13:28:35 +10:00
Michael James Gratton
587e4e7596 Add TestCase.assert_null_string method. 2018-05-08 12:25:03 +10:00
Michael James Gratton
743b24dd5d Make database classes more amenable to asynchronous use.
This makes both the open() and open_connection() methods on
Geary.DB.Database asynchronous, which allows the VersionedDatabase
open_background() and its hackery to be removed, and upgrades to be
performed asynchronously as well. It also adds a
exec_transaction_async() method to Connection, allowing an existing
object to also be used to establish an async transaction.

* src/engine/db/db-connection.vala (Connection): Add
  exec_transaction_async method, update doc comments.

* src/engine/db/db-database.vala (Database): Make open and
  open_connection async by executing SQLite code in a background thread,
  update call sites. Move job management code out of
  exec_transaction_async into a new internal add_async_job() method so it
  can be used by Connection. Add unit tests.

* src/engine/db/db-transaction-async-job.vala (TransactionAsyncJob): Add
  an optional internal connection method and make the job's cancellable
  an internal property so a Connection instance can specify itself for
  the transaction.

* src/engine/db/db-versioned-database.vala (VersionedDatabase): Remove
  open_background() hack since open() is now async. Make version upgrade
  hooks for derived classes async and update call sites. Use a
  Nonblocking.Mutex rather than GLib mutex so upgrade exclusion works
  asynchronously. Add unit tests.

* src/engine/imap-db/imap-db-database.vala (Database): Make database
  upgrade methods async and execute SQL in async instructions now that
  the bases classes support it. Add unit tests.
2018-05-08 12:24:48 +10:00
Michael James Gratton
598f1a5e89 Increase len of non-truncated strs that TestCase.assert_string reports. 2018-04-27 12:37:13 +10:00
Michael James Gratton
057e733eb1 Fix a crash saving an attachment with unknown content type.
* src/engine/api/geary-attachment.vala (Attachment): Add a null check for
  the extension before using it, add a test case to cover it.
2018-04-27 12:29:06 +10:00
Rico Tzschichholz
f809febed3 Drop custom webkit2gtk bindings 2018-04-23 19:38:37 +02:00
Michael James Gratton
3bf2ac181a Add unit tests for ConversationMonitor, fix a few issues.
* src/engine/app/app-conversation-monitor.vala (ConversationMonitor):
  Don't check the folder blacklist for external folder signals when the
  signal is received, do it when the operation is executed so it's fresh.

* src/engine/app/conversation-monitor/app-fill-window-operation.vala
  (FillWindowOperation): Only re-fill the conversation if we get a full
  load, anything else means we hit the end of the folder.

* test/engine/app/app-conversation-monitor-test.vala: New unit tests
  for ConversationMonitor.

* test/engine/api/geary-account-mock.vala,
  test/engine/api/geary-folder-mock.vala: Mix in MockObject mock up all
  method calls.

* test/engine/api/geary-email-identifier-mock.vala: Fix the comparator
  method when the other instance is null.
2018-04-07 10:02:24 +10:00