Commit graph

30 commits

Author SHA1 Message Date
Michael James Gratton
0e6d499808 Fix AccountInformation.has_email_address, add tests. 2018-07-02 21:22:15 +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
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
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
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
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
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
Michael James Gratton
0ea1fe6c35 Don't use the database for internal ConversationMonitor bookkeeping.
This replaces the use of Geary.Folder.find_boundaries_async in
ConversationMonitor with a simple sorted set of known in-folder message
ids. This is both easy and fast, reduces needless DB load when loading
conversations, and also allows allows removing what is otherwise
single-use implementation overhead in classes deriving from Folder.

* src/engine/app/app-conversation-monitor.vala (ConversationMonitor):
  Replace get_lowest_email_id_async() with window_lowest property, update
  call sites. Implement the property by using a sorted set of known
  listed email ids from the base folder. Update the set as messages in
  the base folder are listed. Rename notify_emails_removed to just
  removed and remove ids from the set if any messages from the base
  folder are removed.

* src/engine/api/geary-folder.vala (Folder): Remove
  get_lowest_email_id_async since it is now unused, do same for all
  subclasses.
2018-04-07 10:02:24 +10:00
Michael James Gratton
15748cef03 Tidy up unit test infrastructure and mock classes.
* test/api/*.vala: Renamed files that contained mock objects to *-mock.vala,
  not *-test.vala.

* test/testcase.vala: Renamed to test-case.vala for consistency, remove
  TestCase class from Gee package since that's really not true. Clean up
  code for consistency.

* test/meson.build, test/CMakeLists.txt: Split TestCase compilation out
  into a separate test lib.
2018-04-07 09:41:18 +10:00
Michael James Gratton
50f73ff252 Allow test fixtures and test methods to throw errors by default.
* test/testcase.vala (TestCase): Add a generic throws clause to both
  TestMethod and set_up and tear_down, update subclasses.
2018-04-07 09:41:18 +10:00
Michael James Gratton
f0651803bb Fix conversation-related test warnings and occasionally failing test.
* test/engine/api/geary-email-properties-test.vala: Add new mock
  EmailProperties object.

* test/engine/app/app-conversation-test.vala (ConversationTest): Set
  email sent and received dates to suppress warnings adding them to
  Conversation instances.

* test/engine/app/app-conversation-set-test.vala (ConversationSetTest):
  Set email sent and received dates to suppress warnings adding them to
  Conversation instances, handle both casees when merging two
  conversations, that the first was merged to the second and vice versa.
2018-02-08 18:25:32 +11:00
Michael James Gratton
ea891a39cd Only create IMAP account and folder sessions when ready, not otherwise.
This commit makes the Imap.Account and Imap.Folder classes work somewhat
more like Imap.ClientSession, in that they have become higher-level
wrappers around ClientSession which come and go as the client session
does (i.e. as the connection to the IMAP server comes and goes). Further,
partly decouple account session lifecycle in ImapEngine.GenericAccount
and the folder session in ImapEngine.MinimalFolder from those objects
being opened/closed, so that sessions are created only when open /and/
the IMAP server is available, and disconnected on close /or/ when the
underlying connection goes away.

As a result, GenericAccount and MinimalFolder no longer claims a client
session on open and try to keep it forever. Instead if needed, they wait
for the server to become contactable.

This makes Geary much more robust in the face of changing network
connections - when working offline, resuming after sleep, and so on.
2018-02-04 10:50:31 +10:30
Michael James Gratton
8827bc2a09 Add a mock Account object. 2017-12-19 10:47:36 +11:00
Michael James Gratton
dcdbcbeef9 Add some useful Engine API mock objects. 2017-12-19 10:23:47 +11:00
Michael James Gratton
ccabe6ed6c Update testcase to fix failure introduced by commit da15ebe. 2017-11-16 10:37:29 +11:00
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