Commit graph

34 commits

Author SHA1 Message Date
Michael Gratton
cddbb28a43 Add initial integration test famework and IMAP client session tests 2019-03-31 02:05:14 +11:00
Michael Gratton
6c8f192148 Attempt to de-mangle From names from Mailman, GitLab, etc
Some software like the above will mangle From mailbox names by appending
"via Some Service" to the From mailbox name. This messes up generating
default avatars for the actual people sending these messages, so
attempt to de-mangle the names.

This involves moving primary originator determination from the engine
to the client, since it's now a policy thing. Add unit tests.
2019-03-09 20:17:01 +11:00
Michael Gratton
76ee07595d Make avatar code a bit more robust in the face of bad input
Don't try to dray null initials, actually return null per API contract
when no initials can be found, don't include non-alphanumerics in the
initials. Add test case.
2019-03-09 20:17:01 +11:00
Michael Gratton
539893fb72 Add some unit tests for setting email flags 2019-02-13 18:41:49 +11:00
Michael Gratton
5a22e8e4a2 Convert Geary.FolderRoot to be an actual root, not just a top-level
Instead of each top-level IMAP folder being a FolderRoot object, then
children of that being FolderPath objects, this makes FolderRoot an
"empty" FolderPath, so that both top-level and descendant folders are
plain FolderPath objects. Aside from being more technically correct,
this means that empty namespace roots can now be used interchangably
with non-empty namespace roots (addressing issue #181), and custom
folder implementations no longer need to provide their own trivial,
custom FolderRoot.

To support this, a notion of an IMAP root and a local root have been
added from which all remote and local folder paths are now derived,
existing places that assume top-level == root have been fixed, and
unit tests have been added.
2019-01-15 00:18:45 +11:00
Michael Gratton
faf7a2bdfd Add some unit tests for Geary.ImapDb.Account folder management 2019-01-14 11:01:03 +11:00
Michael Gratton
123f51dbb2 Enable config file versioning
This (way too large patch) enables versioning in config files, and
provides a mechanism by which to load older versions from a newer
version of Geary. It also properly introduces a new v1 config format
that adds several groups to geary.ini to make it easier to read and to
distinguish between incoming/outgoig services rather than IMAP/SMTP.

To do this, a few things that should have happened in seperate patches
were also done:

 * Make AccountInformation's imap and smtp properties mutable (they
 aren't stateful any more anyway), make ServiceInformation non-abstract
 again and remove the subclasses (to get config versioning happening
 without an explosion of a classes, it all has to be handled from the
 AccountManager anyway), and some other misc things.
2018-12-08 13:53:01 +11:00
Michael Gratton
9884faba84 Add general impls for converting enum values to nicks and back.
Use this for service provider related enums.
2018-11-30 23:49:30 +11:00
Michael James Gratton
5305c27ca7 Move AccountManager and related objects into Accounts package.
This makes the manager consistent with the source file naming convention
and the new account UI classes.
2018-11-30 23:49:30 +11:00
Michael James Gratton
74fa29b73f Tidy up Geary.AccountInformation creation.
Pass service provider to ctor so we can make the service provider
property immutable. Fill in service label in ctor so it's always set to
something useful. Move creating orphans from Engine to AccountManager
since it exists only to assign an internal id for new accounts, so it
should handled by the account manager anyway.
2018-11-30 23:49:30 +11:00
Michael James Gratton
43ba38bb05 Add unit test for IMAP FETCH command constructor. 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
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
0e6d499808 Fix AccountInformation.has_email_address, add tests. 2018-07-02 21:22:15 +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
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
9f3ec5bfcb Update unit tests to work with ServiceInfo API changes. 2018-05-23 17:53:23 +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
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
15d8789685 Move attachment related code from ImapDB.Folder to Attachment. 2018-05-08 13:28:48 +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
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
712088061b Add a mock object mixin that can check call expectations on mocks.
* test/mock-object.vala: Add initial mock object implementation.

* test/test-case.vala; Add some useful high level assertion functions.
2018-04-07 10:02:18 +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
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
178ce35113 Fix MailboxAddresses.to_rfc822_string formatting, add unit tests. 2018-01-31 16:15:29 +10:30
Michael James Gratton
71e0e6835e Check for spoofed sender addresses, only display the address if so.
This adds a check for malware spoofing of RFC 822 mailbox addresses such
as those found in Mailsploit, and if found only displays the email
address part and not the mailbox name part.

Part 1 of Mailsploit mitigation.

* src/engine/rfc822/rfc822-mailbox-address.vala (MailboxAddress): Add new
  is_spoofed method to check if the mailbox address looks like it has
  been spoofed. Add is_distinct method to determine if the name and the
  label is the same. Do whitespace and non-printing character stripping
  when generating display versions of the mailbox address, rename methods
  to make it more obvious what they do and update call sites. Add unit
  tests to cover all this.

* src/client/conversation-viewer/conversation-message.vala
  (ConversationMessage): Check name is distinct and is not valid before
  displaying it. Use new MailboxAddress methods for getting display
  versions of the address, to ensure we get the stripped versions of the
  addresses.

* src/client/conversation-list/formatted-conversation-data.vala
  (ParticipantDisplay): Ensure full addresses are always HTML-markup
  escaped before displaying them as markup, to avoid dropping "<address>"
  values as invalid HTML. Always show the full address if an address is
  invalid.

* src/engine/util/util-string.vala (reduce_whitespace): Strip not only
  whitespace but also non-printing characters. Add unit tests.
2018-01-31 16:15:29 +10:30
Michael James Gratton
3aefeb0783 Update meson build after merging wip/778276-better-flag-updates. 2018-01-12 12:25:33 +11:00
Michael James Gratton
fc880442f5 Update Meson build to also build separate engine and client tests.
* src/engine/meson.build: Add some ugly hacks to both build the internal
  VAPI and work around a valac bug to ensure the internal VAPI correctly
  references the internal header, not the public header.

* test/meson.build: Split the test suite build into test-engine and
  test-client.
2017-12-18 14:49:04 +11:00
Michael James Gratton
a38a450ae5 Fix compiling tests under Meson.
* test/meson.build: Client tests need both the complied GSettings schema
  and GResources, also common Geary compilation arguments.
2017-12-12 15:56:31 +11:00
Niels De Graef
01c13f726f Port build system to Meson. Bug 777044.
Some remarks:

* Note that Meson adds a hard dependency on Python 3.

* All dependencies and defines are now listed together.

* Some build files were put in their respective subdirectories, e.g. the Geary
  engine library will be built from the Meson file in `src/engine`.

* `--fatal-warnings` is no longer an explicit flag, as Meson provides
  `-Dwerror=true` for this.

* An explicit resource file needs to be used. The issue to support this from
  Meson itself can be found at https://github.com/mesonbuild/meson/issues/706 .

* The `gnome.yelp()` function parses a LINGUAS file so we no longer need to keep
  track of all languages in our build system.

* There are no Debian scripts defined in the meson.build files to keep them
  clean, but they can be kept as separate scripts in `build-aux`.

* Left out the `dist` target as there is now `ninja dist`

* `geary-docs` is disabled by default, as valadoc-0.38.3 returns errors.

https://bugzilla.gnome.org/show_bug.cgi?id=777044
2017-12-12 00:27:46 +01:00