Commit graph

40 commits

Author SHA1 Message Date
Richard Adenling
efca9615a6 engine: Fix flag being mistaken for a response code
The parser would think the flag was a response code if the flag started
with a '[' character. Flags like these are sometimes returned by Gmail
which broke fetching emails from Gmail.

This commit checks if the parser is already parsing flags and if so
treats any starting '[' characters as part of the flag string.
2022-09-20 18:32:37 +02:00
Michael Gratton
41be8693d4 Geary.Imap.ClientSession: Treat logout as disconnect
Convert `get_protocol_state` to an automatic property, so that rather
than requiring explcit signals for lifecycle events, a GObject notify
signal can be used instead.

Convert disconnect signal to a property so it can be accessed if needed.

Convert code listening to the disconnect signal to listen to notify
signals for `protocol_state` instead, and hence also treat the session
as disconnected when a logout is in progress.

Fixes #986
2020-09-27 17:38:10 +10:00
Michael Gratton
85e9046c71 Geary.Imap: Make command cancellable a property of the command object
Since both submitting a command no longer requires a cancellable, and it
is desirable to avoid sending a queued command that has already been
cancelled beforehand, add a new `Command.should_send` Cancellable
property to specify if a command should (still) be sent or not, and stop
passing a cancellable to ClientSession when submitting commands.

Allow call sites to pass in existing cancellable objects, and thus also
add it it as a ctor property to the Command class and all subclasses.

Lastly, throw a cancelled exception in `wait_until_complete` if send
was cancelled so that the caller knows what happened.

Remove redundant cancellable argument from
`Imap.Client.command_transaction_async` and rename it to
`submit_command` to make it more obvious about what it does.
2020-09-02 14:34:41 +10:00
Michael Gratton
31f10e2787 Geary.Imap: Add quirk for Envelope address structure placeholders
Some servers (e.g. Dovecot) use placeholder strings instead of the empty
string (e.g. "MISSING_DOMAIN") in FETCH Envelope responses when a
required address part (e.g. local part, domain) are empty.

This adds a quirk that can be enabled for such servers to check for the
placeholders and if found, replace them with empty strings.
2020-08-18 16:34:24 +10:00
Michael Gratton
757c0542dc Geary.Imap.ServerResponse: Add quirks property
Add a quirks object as a property so code that parses the response has
access to it. Simplify constructing server responses slightly and pass
the IMAP connection's quirks when doing so.
2020-08-18 16:34:24 +10:00
Michael Gratton
ebf7a8ad1d Geary.Imap: Update IMAP quirks based on server greeting rather type
Use server greeting to update IMAP quirks, so that if e.g. a GMail
account is configured as a generic account, it still gets the right
quirks.
2020-08-18 16:34:24 +10:00
Michael Gratton
16efce0514 Fix build failure 2020-06-30 18:25:51 +10:00
Michael Gratton
cfbac77fa4 Merge branch 'mjog/unit-test-subproject' into 'mainline'
Unit test subproject and cleanup

See merge request GNOME/geary!517
2020-06-30 08:08:54 +00:00
Michael Gratton
0ae633d88f Update existing tests to work with ValaUnit 2020-06-30 17:31:07 +10:00
Michael Gratton
d6d36768f9 Geary.Imap.Deserialiser: Handle reserved chars in response-text
RFC 3501 allows any kind of char except CRLF in `resp-text` after an
optional response code, so handle that.

Addresses another issue in #711
2020-05-04 10:54:20 +10:00
Michael Gratton
cff26e2501 Geary.Imap.Deserializer: Workaround GMail not quoting IMAP email flags
GMail doesn't seem to quote IMAP email flags when they contain spaces
or `]`, a reserved character under RFC 3501. We can't do anything
about the former, but we can work around the latter.

This patch adds a quirk allowing `]` in IMAP flags in general for
GMail accounts, and adds some additional unit tests to that end.
2020-05-04 10:53:31 +10:00
Michael Gratton
ddb3a899fb Geary.Imap: Add Quirks object to collect all IMAP service quirk config 2020-05-04 10:53:31 +10:00
Michael Gratton
c98efafb28 Fix failing test after test case async changes 2020-04-10 14:29:20 +10:00
Michael Gratton
196f05e595 test/test-case.vala: Rename TestCase async calls to match AsyncCallWaiter's 2020-04-10 12:58:09 +10:00
Michael Gratton
8dcab7f306 Geary.SpecialFolderType: Rename class and related properties, signals
The `SpecialFolderType` was somewhat mis-named, since the special use
does not (in most cases) confer any special type, rather it's simply
defines what a particular folder is used /for/.

As such, rename the enum to to `Geary.Folder.SpecialUse`, moving it in
to the `Folder` class, since it relates specifically to folders, also
rename `Folder::special_folder_type` and
`Folder::special_folder_type_changed` reflect the above and not
duplicate the type name, and similarly rename
`Account::folders_special_type`.

Update the many call sites.
2020-03-31 16:15:57 +11:00
Michael Gratton
b53d5b2470 Simply Geary.Imap.ClientService selected mailbox handling
Convert mailbox and mailbox RW/RO state accessors to properties and
rename to be more explicit about what they mean. Remove mailbox arg
from ::getProtocolState() since it's unused.
2020-03-27 08:29:14 +11:00
Michael Gratton
9e01d8dca0 Remove Geary.Imap.ClientSession::server-data-received signal
This was only being used internally, and it leaks low level details out
of the mid-level abstraction.
2020-03-27 08:29:14 +11:00
Michael Gratton
7ac72379bb Update Geary.Imap.ClientSession namespace handling
Add namespace accessors, handle updating namespaces when processing
the received data, not when executing the command so that unsolicited
namespaces are still recognised. Clear namespaces when new data is
receieved and when not in selected and auth states. Add unit tests.
2020-03-27 08:29:14 +11:00
Michael Gratton
b46838f100 Update Geary.Imap.Capabilities handling
Move Capabilities to the api directory and make immutable.

Don't pass around out params to simply increment the revision and use a
field in ClientSession, just use the last capability instance. Ensure
after starting a TLS session capabilities are cleared. Add unit tests
for getting both implicit and explicity capaibilities when initiating
a client session.
2020-03-27 08:29:14 +11:00
Michael Gratton
13d43d41b2 Update Geary.Imap.ClientSession connect timeout handling
Allow specifying the connect greeting timeout length, ensure that
any connect errors are in place before releasing the connect waiter,
add unit test to ensure it works properly.
2020-03-27 08:29:14 +11:00
Michael Gratton
62f1df12cb Rework Geary.Imap.ClientConnection signal and error handling
Remove connect, disconnect and close_error signals, since they are
implied by their respective methods completing and/or throwing an
error. Remove Deserializer pass-through signals, treat all three kinds
as generic receive errors instead.

Make Deserializer emit end-of-stream signal only on EOS, not on EOS and
on receive error, so it only signals an error condition once.
2020-03-27 08:29:14 +11:00
Michael Gratton
7e77133bda Update Geary.Imap.Command API
Make the class abstract, since it only gets used by subclases. Allow
a null cancellable when waiting for the command to complete.
2020-03-27 08:29:14 +11:00
Michael Gratton
339d8ae26e Add unit test for Geary.Imap.ClientSession 2020-03-27 08:29:14 +11:00
Michael Gratton
95c1916abf Add unit test for Geary.Imap.ClientConnection 2020-03-27 08:29:14 +11:00
Michael Gratton
01a154bc5f Make it possible to distinguish between different folder roots
Add a label to Geary.FolderRoot so it different instances can be
differenciated.
2019-04-17 09:06:24 +10: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
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 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
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
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
b8304b594b Update unit tests after recent changes. 2017-11-23 09:37:59 +11:00
Michael James Gratton
2af9412740 Merge branch 'wip/768422-namespace-support'. Fixes Bug 768422 and Bug 726866. 2017-11-10 00:29:51 +11:00
Michael James Gratton
21421f8d48 Add unit tests for NAMESPACE parsing, CREATE serialisation, fix an error. 2017-11-03 16:52:21 +11:00
Michael James Gratton
9ac2b05a23 Ensure syntax errors are always reported by the deserialiser.
Add unit tests.

* src/engine/imap/transport/imap-deserializer.vala (Deserialiser): Add a
  new EOL even handler to the FAILED state that is the one place where
  the deserialize_failure() signal is fired and that any existing params
  are reset.
  (Deserialiser::push_line): Remove signal calls and unused return
  value. Don't use EOS to detect NUL to avoid some confusion. Ensure an
  EOL event is always fired so that the FAILED EOF handler is always run.
  (Deserialiser::push_data): Remove signal calls and unused return value.
  (Deserialiser::flush_params): Don't bother returning a state, since we
  now always know what the next one should be when calling it. Only
  trigger the parameters_ready() signal if there is a valid
  parameter. Make logging consistent with the rest of the class.
  (Deserialiser::reset_params): New common method for resetting any
  existing deserialised message.
  (Deserialiser::on_literal_char): Minor tidy up.
  (Deserialiser::on_eos): Ensure that any existing param is sent on EOS
  so that any BYE+EOS sent by the server is picked up.
2017-11-02 19:10:29 +11:00
Michael James Gratton
25e700d22a Allow IMAP atoms to be terminated by an atom-special w/o needing a space.
Fixes Bug 781488.

* src/engine/imap/transport/imap-deserializer.vala (Deserializer): Update
  char handling in START_PARAM state to be more explict and to handle all
  possible chars, not just a subset. Then, simply defer to START_PARAM to
  determine what to do when an invalid atom char is encountered when in
  the ATOM state. Rename SYSTEM_FLAG state to just FLAG since it also
  handles extension flags, and only use it for handling the first char in
  the flag so "\*" can be treated appropriately, then defer to the ATOM
  state, so flag keywords are treated in the same way as regular
  atoms. Add unit tests.
2017-11-02 19:10:29 +11:00
Michael James Gratton
bbcf57c8eb Add test case stub for Geary.Imap.Deserializer to the build. 2017-11-02 19:10:29 +11:00