Commit Graph

82 Commits

Author SHA1 Message Date
Dan Klishch
5ed7cd6e32 Everywhere: Use east const in more places
These changes are compatible with clang-format 16 and will be mandatory
when we eventually bump clang-format version. So, since there are no
real downsides, let's commit them now.
2024-04-19 06:31:19 -04:00
Shannon Booth
e2e7c4d574 Everywhere: Use to_number<T> instead of to_{int,uint,float,double}
In a bunch of cases, this actually ends up simplifying the code as
to_number will handle something such as:

```
Optional<I> opt;
if constexpr (IsSigned<I>)
    opt = view.to_int<I>();
else
    opt = view.to_uint<I>();
```

For us.

The main goal here however is to have a single generic number conversion
API between all of the String classes.
2023-12-23 20:41:07 +01:00
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Tim Ledbetter
4b995542c4 LibIMAP: Make parsing of atom data fallible
We now return an error where `parse_atom()` would have previously
returned an empty StringView. This is consistent with RFC3501, which
says that an atom consists of one or more characters.

This prevents a few cases where parsing an invalid atom could lead to
an infinite loop.
2023-11-08 09:36:37 +01:00
Tim Ledbetter
54a28afc13 LibIMAP: Stop parsing immediately on error
This makes the parser more resilient to invalid IMAP messages.

Usages of `Optional` have also been removed where the empty case is
equivalent to an empty object.
2023-10-13 11:12:18 -06:00
Tim Ledbetter
29c477598c LibIMAP: Rename Parser::try_consume() to consume_if() 2023-10-13 11:12:18 -06:00
Tim Ledbetter
80238f29d2 LibIMAP: Handle invalid escape sequences in Quoted-Printable parser
When an invalid escape sequence is encountered, we now output the
characters unaltered instead of crashing.
2023-10-06 22:31:43 +02:00
Karol Kosek
f789d26e37 LibIMAP+Mail: Rename MultiPartBody's mime_type to multipart_subtype 2023-09-09 11:19:37 -06:00
Karol Kosek
642a3f85ef LibIMAP: Parse body-type-msg to spec 2023-09-09 11:19:37 -06:00
Karol Kosek
4a92d712ea LibIMAP: Don't parse starting space directly in parse_envelope
Makes parse_envelope() look like the defined ABNF rule and the parser
will no longer try to consume double spaces in body-type-msg.
2023-09-09 11:19:37 -06:00
Karol Kosek
e9cf35fd60 LibIMAP: Parse body-ext-1part for every one part body type
Previously we were only doing it only for body-type-text, which isn't
correct to spec.

Fixes a crash when parsing a BODYSTRUCTURE response on a mail with
attachments.
2023-09-09 11:19:37 -06:00
Karol Kosek
a61a66c685 LibIMAP: Simplify parsing one part body structure
Each branch was very similar, so let's merge common parts together for
clarity. Also added corresponding ABNF rules names while I'm here. :^)

No behavior change.
2023-09-09 11:19:37 -06:00
Karol Kosek
90af21aef4 LibIMAP+Mail+test-imap: Let a Promise result type be non-optional
The Empty type was used only when parsing a response failed. The
failures will now go to Promise's error type.
2023-08-31 11:10:09 +02:00
Karol Kosek
1f605407bd LibIMAP: Reject a promise if a response couldn't be parsed
Promises can take an Error type now for quite some time, so let's use it
instead of returning an empty Optional type in the result field. :^)

Ideally we should give a more detailed info of what failed to parse, but
this will do for now.
2023-08-31 11:10:09 +02:00
Karol Kosek
55d730bd5c LibIMAP+Mail+test-imap: Make Client requests infailable 2023-08-31 11:10:09 +02:00
Karol Kosek
44ea5092e8 LibIMAP: Reject a promise when a command couldn't be sent
I feel like ErrorOr<RefPtr<Promise<>>> was an overkill. Promises already
hold an optional error type we can use instead.
2023-08-31 11:10:09 +02:00
Valtteri Koskivuori
2b23f3f216 LibIMAP: Fix Parser::parse_disposition()
It didn't consume the initial opening "(" before.
2023-08-12 11:45:52 -06:00
Valtteri Koskivuori
35f1cec7ca LibIMAP: Propagate errors from Parser::parse_number()
More error propagation is still needed, we really want the parser to
just crash early when it encounters unexpected input, instead of trying
to carry on like nothing happened.
I think ErrorOr<unsigned> is *much* better than returning (unsigned)-1
to indicate an error ;)
2023-08-12 11:45:52 -06:00
Valtteri Koskivuori
077a8058c3 LibIMAP+Mail: Implement RFC2047 message header encoding
This enables us to display email subject fields with non-ASCII
characters in Mail :^)
2023-08-12 11:45:52 -06:00
Valtteri Koskivuori
34adf9eeae LibIMAP: Wait for a full IMAP response before parsing
We're now sniffing the incoming data to verify the server has sent a
full response, instead of passing partial data to our IMAP parser.
Our parser really can't handle partial input very well, so for the time
being, this heuristic does a much better job of verifying we have full
response before parsing.
It doesn't yet handle unprompted untagged reponses, nor the
"continuation request" responses that start with a `+`, but we don't
fully support those yet.
2023-08-12 11:45:52 -06:00
Valtteri Koskivuori
0b7e18177b LibIMAP: Rename position -> m_position in IMAP::Parser
No functional changes, just renaming this member variable to bring that
in line with current coding style.
2023-08-12 11:45:52 -06:00
Valtteri Koskivuori
8451c4d91c LibIMAP: Add useful dbgln_if() printouts to IMAP::Parser
I couldn't run the parser in a debugger like I normally would, so I
added printouts to understand where the parser is failing.
More could be added, but these are enough to get a good idea of what
the parser is doing. It's very spammy, though, so enable it by flicking
the IMAP_PARSER_DEBUG switch :^)
2023-08-12 11:45:52 -06:00
Valtteri Koskivuori
c2ed1547ba LibIMAP: Remove needless conversion to DeprecatedString
We're comparing the return value to StringViews right after, so there is
no need to do the conversion twice.
2023-08-12 11:45:52 -06:00
Valtteri Koskivuori
6128e859ac LibIMAP+Mail: Propagate errors from LibIMAP and MailWidget
This lets us bubble up errors from `LibIMAP::Client::send_command()`,
which can happen if the connection hangs or is taking a long time, and
the user closes Mail.
2023-08-12 11:45:52 -06:00
Andreas Kling
ddbe6bd7b4 Userland: Rename Core::Object to Core::EventReceiver
This is a more precise description of what this class actually does.
2023-08-06 20:39:51 +02:00
Karol Kosek
2132e0f1bb LibIMAP: Implement serializing FetchCommands with PeekBody type 2023-08-02 11:21:03 +01:00
Ali Mohammad Pur
0c5c75e8a4 LibCore: Slightly rework the Core::Promise API
The previous iteration of this API was somewhat odd and rough in random
places, which degraded usability and made less than perfect sense.
This commit reworks the API to be a little closer to more
conventional promise APIs (a la javascript promises).

Also adds a test to ensure the class even works.
2023-07-08 23:13:00 +01:00
Timothy Flynn
c911781c21 Everywhere: Remove needless trailing semi-colons after functions
This is a new option in clang-format-16.
2023-07-08 10:32:56 +01:00
Tim Schumacher
ae51c1821c Everywhere: Remove unintentional partial stream reads and writes 2023-03-13 15:16:20 +00:00
Tim Schumacher
d5871f5717 AK: Rename Stream::{read,write} to Stream::{read_some,write_some}
Similar to POSIX read, the basic read and write functions of AK::Stream
do not have a lower limit of how much data they read or write (apart
from "none at all").

Rename the functions to "read some [data]" and "write some [data]" (with
"data" being omitted, since everything here is reading and writing data)
to make them sufficiently distinct from the functions that ensure to
use the entire buffer (which should be the go-to function for most
usages).

No functional changes, just a lot of new FIXMEs.
2023-03-13 15:16:20 +00:00
kleines Filmröllchen
8f4d0d3797 LibCore+Userland: Make Promise's on_resolve fallible
This will be primarily necessary for BackgroundAction integration, but
it already allows us to add proper error handling in LibIMAP :^)
2023-03-13 12:12:17 +00:00
Andreas Kling
a504ac3e2a Everywhere: Rename equals_ignoring_case => equals_ignoring_ascii_case
Let's make it clear that these functions deal with ASCII case only.
2023-03-10 13:15:44 +01:00
Linus Groh
e76394d96c AK: Remove infallible version of StringBuilder::to_byte_buffer
Also drop the try_ prefix from the fallible function, as it is no longer
needed to distinguish the two.
2023-03-09 15:51:00 +00:00
Linus Groh
f068ddb79f LibIMAP: Propagate OOM errors from decode_quoted_printable() 2023-03-09 14:47:45 +00:00
Tim Schumacher
874c7bba28 LibCore: Remove Stream.h 2023-02-13 00:50:07 +00:00
Tim Schumacher
a96339b72b LibCore: Move Stream-based sockets into the Core namespace 2023-02-13 00:50:07 +00:00
Linus Groh
6e7459322d AK: Remove StringBuilder::build() in favor of to_deprecated_string()
Having an alias function that only wraps another one is silly, and
keeping the more obvious name should flush out more uses of deprecated
strings.
No behavior change.
2023-01-27 20:38:49 +00:00
Sam Atkins
c4c65ba727 LibIMAP: Remove declarations for non-existent methods 2023-01-27 20:33:18 +00:00
Ben Wiederhake
6fd478b6ce Everywhere: Remove unused includes of AK/Format.h
These instances were detected by searching for files that include
AK/Format.h, but don't match the regex:

\\b(CheckedFormatString|critical_dmesgln|dbgln|dbgln_if|dmesgln|FormatBu
ilder|__FormatIfSupported|FormatIfSupported|FormatParser|FormatString|Fo
rmattable|Formatter|__format_value|HasFormatter|max_format_arguments|out
|outln|set_debug_enabled|StandardFormatter|TypeErasedFormatParams|TypeEr
asedParameter|VariadicFormatParams|v_critical_dmesgln|vdbgln|vdmesgln|vf
ormat|vout|warn|warnln|warnln_if)\\b

(Without the linebreaks.)

This regex is pessimistic, so there might be more files that don't
actually use any formatting functions.

Observe that this revealed that Userland/Libraries/LibC/signal.cpp is
missing an include.

In theory, one might use LibCPP to detect things like this
automatically, but let's do this one step after another.
2023-01-02 20:27:20 -05:00
Ben Wiederhake
b83cb09db1 Everywhere: Fix badly-formatted includes
In 7c5e30daaa, the focus was "only" on
Userland/Libraries/, whereas this commit cleans up the remaining
headers in the repo, and any new badly-formatted include.
2023-01-02 11:06:15 -05:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Tim Schumacher
ce2f1b845f Everywhere: Mark dependencies of most targets as PRIVATE
Otherwise, we end up propagating those dependencies into targets that
link against that library, which creates unnecessary link-time
dependencies.

Also included are changes to readd now missing dependencies to tools
that actually need them.
2022-11-01 14:49:09 +00:00
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