Commit Graph

39 Commits

Author SHA1 Message Date
sin-ack
c8585b77d2 Everywhere: Replace single-char StringView op. arguments with chars
This prevents us from needing a sv suffix, and potentially reduces the
need to run generic code for a single character (as contains,
starts_with, ends_with etc. for a char will be just a length and
equality check).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
DexesTTP
e371552ff2 LibIMAP: Properly escape the whole string instead of the first character
These were obvious wrong uses of the old default "only first occurence"
parameter that was used in String::replace.
2022-07-06 11:12:45 +02:00
DexesTTP
7ceeb74535 AK: Use an enum instead of a bool for String::replace(all_occurences)
This commit has no behavior changes.

In particular, this does not fix any of the wrong uses of the previous
default parameter (which used to be 'false', meaning "only replace the
first occurence in the string"). It simply replaces the default uses by
String::replace(..., ReplaceMode::FirstOnly), leaving them incorrect.
2022-07-06 11:12:45 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Ali Mohammad Pur
aafc451016 Userland: Convert TLS::TLSv12 to a Core::Stream::Socket
This commit converts TLS::TLSv12 to a Core::Stream object, and in the
process allows TLS to now wrap other Core::Stream::Socket objects.
As a large part of LibHTTP and LibGemini depend on LibTLS's interface,
this also converts those to support Core::Stream, which leads to a
simplification of LibHTTP (as there's no need to care about the
underlying socket type anymore).
Note that RequestServer now controls the TLS socket options, which is a
better place anyway, as RS is the first receiver of the user-requested
options (though this is currently not particularly useful).
2022-02-06 13:10:10 +01:00
Idan Horowitz
ace36681ff LibJS+LibIMAP: Use the new Optional<U>(Optional<T>) constructor
These look much nicer than these repeated ternaries :^)
2022-01-23 18:53:42 +02:00
sin-ack
aedb013ee3 LibIMAP+Userland: Convert LibIMAP::Client to the Serenity Stream APIs
You now cannot get an unconnected LibIMAP::Client, but you can still
close it. This makes for a nicer API where we don't have a Client object
in a limbo state between being constructed and being connected.

This code still isn't as nice as it should be, as TLS::TLSv12 is still
not a Core::Stream::Socket subclass, which would allow for consolidating
most of the TLS/non-TLS code into a single implementation.
2022-01-13 15:16:12 +03:30
Andreas Kling
8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Ben Wiederhake
9265595e42 LibIMAP: Remove unused Variant option 2021-09-21 04:22:52 +04:30
Idan Horowitz
6704961c82 AK: Replace the mutable String::replace API with an immutable version
This removes the awkward String::replace API which was the only String
API which mutated the String and replaces it with a new immutable
version that returns a new String with the replacements applied. This
also fixes a couple of UAFs that were caused by the use of this API.

As an optimization an equivalent StringView::replace API was also added
to remove an unnecessary String allocations in the format of:
`String { view }.replace(...);`
2021-09-11 20:36:43 +03:00
Daniel Bertalan
d7b6cc6421 Everywhere: Prevent risky implicit casts of (Nonnull)RefPtr
Our existing implementation did not check the element type of the other
pointer in the constructors and move assignment operators. This meant
that some operations that would require explicit casting on raw pointers
were done implicitly, such as:
- downcasting a base class to a derived class (e.g. `Kernel::Inode` =>
  `Kernel::ProcFSDirectoryInode` in Kernel/ProcFS.cpp),
- casting to an unrelated type (e.g. `Promise<bool>` => `Promise<Empty>`
  in LibIMAP/Client.cpp)

This, of course, allows gross violations of the type system, and makes
the need to type-check less obvious before downcasting. Luckily, while
adding the `static_ptr_cast`s, only two truly incorrect usages were
found; in the other instances, our casts just needed to be made
explicit.
2021-09-03 23:20:23 +02:00
Andreas Kling
51ae913bfe LibIMAP: Stop leaking a Core::Promise<bool> in IMAP::Client::connect() 2021-09-01 23:02:18 +02:00
Andreas Kling
ee562a8ed7 LibIMAP: Remove accidental use of STL 2021-09-01 23:02:18 +02:00
Lenny Maiorani
97bd13264a Everywhere: Make use of container version of all_of
Problem:
- New `all_of` implementation takes the entire container so the user
  does not need to pass explicit begin/end iterators. This is unused
  except is in tests.

Solution:
- Make use of the new and more user-friendly version where possible.
2021-08-03 10:46:43 +02:00
Linus Groh
028e4bd2ae LibIMAP: Parse (but ignore) OK [HIGHESTMODSEQ <mod-sequence-value>]
Parse it to avoid dbgln() spam, but ignore the value for now. See:
https://datatracker.ietf.org/doc/html/rfc4551#section-3.1.1
2021-07-24 22:22:41 +01:00
Linus Groh
66e47d05c5 LibIMAP: Parse OK [CLOSED]
In my case the mail server responded with the following after selecting
a mailbox (in the Mail application):

    * OK [CLOSED] Previous mailbox closed.
    * FLAGS (\Answered \Flagged ...)
    * OK [PERMANENTFLAGS (\Answered \Flagged ... \*)] Flags permitted.
    * 2 EXISTS
    * 0 RECENT
    * OK [UIDVALIDITY 1234567890] UIDs valid
    * OK [UIDNEXT 12345] Predicted next UID
    * OK [HIGHESTMODSEQ 123456] Highest
    A6 OK [READ-WRITE] Select completed (0.002 secs).

The [CLOSED] part threw the parser off as it was expecting a space after
the atom following the opening bracket, which would actually lead to a
crash of Mail (AK::Optional::value() without value).
2021-07-24 22:22:41 +01:00
Linus Groh
73a9d2ec32 LibIMAP: Replace abuse of String::matches() with == in the parser
matches() is for globs. These are not globs.
2021-07-24 22:22:41 +01:00
Linus Groh
ddd11b98d9 LibIMAP: Add and use Parser::consume_until_end_of_line() 2021-07-24 22:22:41 +01:00
Linus Groh
8e8d1383b7 LibIMAP: Clean up Parser.h a bit
Move members after methods, remove useless parameter names ('x', 's'),
more sensible method grouping.
2021-07-24 22:22:41 +01:00
Linus Groh
8c05b4e137 LibIMAP: Rename IMAP::Parser::{parse => consume}_while()
This isn't parsing anything.
2021-07-24 22:22:41 +01:00
Luke
3948161c14 LibIMAP: Add a bunch of serialize_astring in command construction
These were putting the raw string values into the command, where they
should be astrings as per the grammar:
https://datatracker.ietf.org/doc/html/rfc3501#section-9
2021-07-24 19:03:43 +01:00
Luke
e80f8746b1 LibIMAP: Use try_parse_number instead of parse_number when parsing parts
This makes it so we can use Optional instead of relying on an error
number.
2021-07-24 20:11:28 +04:30
Luke
2c793d5935 LibIMAP: Make Section::parts unsigned 2021-07-24 20:11:28 +04:30
Luke
27644785f1 LibIMAP: Add method to get data out of BodyStructure 2021-07-24 20:11:28 +04:30
Luke
c63913b633 LibIMAP: Add quoted printable decoder
This is a very common encoding for e-mail. Gmail seems to encode all
HTML e-mail in it.
imap qp clang
2021-07-24 20:11:28 +04:30
Timothy
2eb93f2628 LibCore+LibIMAP: Move Promise to LibCore
This makes Promise available without having to link LibIMAP.
2021-07-15 11:11:14 +02:00
x-yl
9174fabf05 LibIMAP: Support for remaining IMAP commands
These include APPEND, AUTHENTICATE, CHECK, CLOSE, EXAMINE, EXPUNGE,
LSUB, SUBSCRIBE, UNSUBSCRIBE
2021-06-11 23:58:28 +04:30
x-yl
16995dc3d9 LibIMAP: Support for APPEND 2021-06-11 23:58:28 +04:30
x-yl
7021413d30 LibIMAP: Support for COPY, CREATE, DELETE and RENAME 2021-06-11 23:58:28 +04:30
x-yl
076c708d0a LibIMAP: Support for STORE and STATUS 2021-06-11 23:58:28 +04:30
x-yl
a6339297ec LibIMAP: Support for the SEARCH command 2021-06-11 23:58:28 +04:30
x-yl
318709c8ca LibIMAP: Support for FETCH BodyStructure
This completes the implementation of the FETCH command.
2021-06-11 23:58:28 +04:30
x-yl
c152a9a594 LibIMAP: Support for the FETCH command (*mostly)
This commit doesn't include support for FETCH BODY, because it's a bit
big already. Rest assured, FETCH is the most complicated IMAP command,
and we'll go back to simple boring ones shortly.
2021-06-11 23:58:28 +04:30
x-yl
1e9dfdcdcc LibIMAP: Support for the IDLE command 2021-06-11 23:58:28 +04:30
x-yl
f00c2c0192 LibIMAP: Support for LOGIN and LOGOUT 2021-06-11 23:58:28 +04:30
x-yl
2f04d24b66 LibIMAP: Support for the LIST and SELECT commands 2021-06-11 23:58:28 +04:30
x-yl
0f42ea6770 LibIMAP: Support for CAPABILITY command & response
This involves parsing messages with untagged responses
2021-06-11 23:58:28 +04:30
x-yl
8c6061fc4a LibIMAP: Add a new IMAP client and support NOOP
A large commit, but sets up the framework for how the IMAP library will
work. Right now only the NOOP command and response is supported.
2021-06-11 23:58:28 +04:30