Commit Graph
100 Commits
Author SHA1 Message Date
Dmitry Bogatov a9dd78f622 Narrow return type of location::set: cint -> bool 2019-10-19 22:38:43 +02:00
Dmitry Bogatov 2d0f563dfe Replace magic constant with symbolic name 2019-10-15 13:45:08 +02:00
Dmitry Bogatov a4257b619a Replace flags argument to Sql.open with single bool
Previously, "flags" argument of Sql.open was of type libc::c_int, but
only one bit was used: whether to open database read-only. This commit
makes it explicit by changing type to bool and renaming argument.
2019-10-12 09:56:18 +02:00
Dmitry Bogatov a6a6fc48c1 Remove unused outlk_autodiscover_t.redirect field 2019-09-29 23:35:01 +02:00
Dmitry Bogatov 0beadde758 Remove _safe suffix from dc_decode_header function
There is no longer unsafe version of this function, so suffix is
useless now.
2019-09-28 23:18:41 +02:00
Dmitry Bogatov 618abd63cf Drop unsafe version of dc_decode_header_words
Replace all call sites with safe version and adjust tests as apporiate.
2019-09-28 23:18:41 +02:00
Dmitry Bogatov 6c9c21c135 quote_word: avoid dependency on phf crate 2019-09-27 04:11:50 +02:00
Dmitry Bogatov d02a721eed Reimplement dc_encode_header_words in safe Rust
This change fixes proptest, introduced in [THIS~2] commit.
2019-09-27 04:11:50 +02:00
Dmitry Bogatov 8ffb4ae127 Add proptest seed that reveals strencoding bug 2019-09-27 04:11:50 +02:00
Dmitry Bogatov 96fbeb583b Add proptest to check dc_header_{encode,decode} 2019-09-27 04:11:50 +02:00
Dmitry Bogatov 33b98a15d3 Remove unused "print_hex" function 2019-09-27 04:11:50 +02:00
Dmitry Bogatov e523ebe3c1 Implement safe version of quote_word 2019-09-27 04:11:50 +02:00
Dmitry Bogatov e17c671b7c Rename local variables to not misleadingly refer to MMAPString 2019-09-27 04:11:50 +02:00
Dmitry Bogatov e7565e1a2a Use rust strings instead of MMapString in src/dc_strencode.rs
Since Rust strings operations are assumed to never fail, this commit
removes a lot of checking, whether appending to mmapstring fails. Now it
is Rust runtime burden.
2019-09-27 04:11:50 +02:00
Dmitry Bogatov 8f6a0bbf09 Remove unused argument of DC_JOB_CONFIGURE_IMAP 2019-09-22 22:22:00 +02:00
Dmitry Bogatov 9ba57a923b Remove useless argument to quote_word
Function "quote_word" accepts display charset argument, but on only call
site it is string constant. Change function to always use "utf-8"
display charset, and remove useless argument.
2019-09-21 22:20:56 +00:00
Dmitry Bogatov 90e2b6f26b Add test for dc_remove_cr_chars 2019-09-21 21:26:47 +00:00
Dmitry Bogatov 43f6db3252 cargo-fmt 2019-09-21 06:19:55 +00:00
Dmitry Bogatov 5b917e7d10 Remove last mutable variable from do_set_draft 2019-09-21 06:19:21 +00:00
Dmitry Bogatov 0523868a88 Avoid ok-to-continue pattern in "do_set_draft" function
Note: I strongly suggest reviewing this commit in side-by-side mode.

Note: This commit fails CI due incorrect formatting. It is done
deliberately to simplify review process.
2019-09-21 06:16:15 +00:00
Dmitry Bogatov 26f176eb7e Factor another part of set_draft_raw into separate function 2019-09-21 06:04:55 +00:00
Dmitry Bogatov ad32b5ca8f cargo-fmt 2019-09-21 05:44:31 +00:00
Dmitry Bogatov dbf14179dc Make message argument to set_draft_raw() no longer optional
Previously, "set_draft_raw" function was used with "msg = None" only for
side-effect of removing current draft message in chat.

After draft removal functionality was factored into separate
"maybe_delete_draft" function, it is used directly in only call site,
which used to invoke "set_draft_raw" with optional message.

This function is private, and this refactoring does not change FFI
interface.

Note: This commit fails CI due incorrect formatting. It is done
deliberately to simplify review process.
2019-09-21 05:34:48 +00:00
Dmitry Bogatov 45b0a4ec27 Factor part of set_draft_raw into new function maybe_delete_draft 2019-09-21 05:24:03 +00:00
Dmitry Bogatov 7dd3bad8bd Add factory method MimeFactory::new
* src/dc_mimefactory.rs(new): add factory method to have verbose
   initialization of all (more than 10) MimeFactory fields only in one place.
 * src/dc_mimefactory.rc(dc_mimefactory_load_msg, dc_mimefactory_load_mdn):
   simplify code (and reduce linecount) using Mimefactory::new
2019-09-20 22:49:33 +02:00
Dmitry Bogatov e9c9a3e1ce Change type of MimeFactory.loaded to enum
* src/dc_mimefactory.rs(MimeFactory): change type of `loaded` field
 * src/dc_mimefactory.rs(Loaded): new enum, describing possible
   values of `loaded` field of `MimeFactory` structure
 * src/dc_mimefactory.rs(dc_mimefactory_loaded_t): remove unused type alias
 * src/job.rs(add_smtp_job): adjust call site by removing multiple casts
 * src/dc_mimefactory.rs(dc_mimefactory_render): ditto
2019-09-20 18:02:57 +00:00
Dmitry Bogatov fa7bb71f3f Change type of MimeFactory.out_{gossip,encrypted} to bool 2019-09-20 18:02:57 +00:00
Dmitry Bogatov 34a3ad82e0 Rename dc_mimefactory_t -> MimeFactory
CamelCase naming convention is more natural for Rust.

https://rust-lang-nursery.github.io/api-guidelines/naming.html
2019-09-20 18:02:57 +00:00
Dmitry Bogatov 2f5d74dbf4 Remove unused constants from src/imap.rs 2019-09-20 17:35:26 +00:00
Dmitry Bogatov 4bf5ba594c Make Imap::set_mdnseen return enum, not int 2019-09-20 17:35:26 +00:00
Dmitry Bogatov 6e2da27f45 Change return type of Imap::set_seen to enum 2019-09-20 17:35:26 +00:00
Dmitry Bogatov 6ee9465d43 Make return type of Image::mv an enum
Replace named constants with enum to improve type-safety and make
exhausiveness checks possible.

Note, that since this enum never pass FFI border, its numeric values
does not need to be specified explicitly and can be left on compiler's
discretion.
2019-09-20 17:35:25 +00:00
Dmitry Bogatov 391a6bf422 Replace numbers with named constants 2019-09-20 17:35:25 +00:00
Dmitry Bogatov 735fc325b1 Add test for export_key_to_asc_file 2019-09-19 21:43:54 +02:00
Dmitry Bogatov 178b216e48 Reduce number of arguments of export_key_to_asc_file
Previously, this function accepted both key id (integer) and is_default
(boolean). If `is_default` flag was set, value `id` parameter wasn't
used. This commit compresses two argument into single `id: Option<i64>`.
2019-09-19 21:43:54 +02:00
Dmitry Bogatov 030aec7373 Read example GPG keys from files using include_str!
For consistency with other tests that use example public and private
keys, replace use of `concat!` macro with `include_str!`. This way, key
data embedded into source with single line of code.
2019-09-19 18:57:39 +02:00
Dmitry Bogatov e0e82e1877 Fix ffi interoperability issue
Clients expect empty "dbfile" argument to be treated as NULL value.
This change fulfills their expectations.

Closes: #530
2019-09-19 07:15:35 +02:00
Dmitry Bogatov 95d8665dbe Refine signature of dc_get_oauth2_access_token()
Previously, `dc_get_oauth2_access_token` accepted "flags" argument,
that actually had only one possible field: 0x1 == DC_REGENERATE.

This change replaces "flags" argument with single boolean argument
"regenerate".
2019-09-18 19:29:39 +02:00
Dmitry Bogatov 8a3bf6a5d9 Remove use of `dbg!' macro
According to documentation[^1], this macro should not be in version
control, and should only be used for debugging.

https://doc.rust-lang.org/std/macro.dbg.html
2019-09-18 14:35:49 +02:00
Dmitry Bogatov d5f361d386 Use include_str! macro instead of embedding key into source
Additionally, this change reduces duplication: now test public key is
stored in only one place, and used in two instead of copy-paste of very
long line.
2019-09-18 14:35:49 +02:00
Dmitry Bogatov 7bb4a27b60 Make Context.cb field private (no code changes) 2019-09-18 14:35:49 +02:00
Dmitry Bogatov d644ca5563 Add property test for simplify_plain_text 2019-09-18 07:34:56 +02:00
Dmitry Bogatov b3b1e37192 Add tests for dc_dehtml 2019-09-18 07:34:56 +02:00
Dmitry Bogatov 38f39c8d32 Add smoke test for Context.get_fresh_msgs 2019-09-18 07:34:56 +02:00
Dmitry Bogatov a773b7929c Add fuzzy-test for dc_mimeparser_parser 2019-09-18 07:33:22 +02:00
Dmitry Bogatov 7b73103133 Add test for mime parsing reportedly crash-inducing message 2019-09-18 07:33:22 +02:00
Dmitry Bogatov bb4081e503 Rename query_row_col to query_get_value
Since function `query_row_col` no longer accept column number argument,
it is misleading to mention column in its name.
2019-09-12 18:42:12 +00:00
Dmitry Bogatov bef25ad5f6 Avoid excessive allocation in dc_search_msgs 2019-09-12 17:12:26 +00:00
Dmitry Bogatov f47652e72d Change argument type of write_asc_to_file from const char * to &Path 2019-09-12 17:12:23 +00:00
Dmitry Bogatov 7c4d7fb3dd Make Aheader::from_imffields accept &str, not const char * 2019-09-12 06:32:13 +00:00
Dmitry Bogatov cdfc7281d0 Simplify Sql.query_row_col function
Function `query_row` executes query and calls callback function to process
row returned. Function query_row_col() is special case, that provides
callback function, which returns value of one particular column of row,
ignoring others.

In all cases, that particular column was 0 (first and only column of
query result), since there is no point to select more than one column
with this function -- they are discarded anyway.

This commit removes that redundancy, removing column number argument of
query_row_col() function and adjusting call sites accordingly.
2019-09-12 05:01:06 +00:00
Dmitry Bogatov 500e80784a Replace some of context.sql.get_config() with context.get_config()
Pattern `context.sql.get_config(context, {foo})` is unnecessary
redundant in Rust: unlike C, Rust has associated functions (methods).
2019-09-12 04:41:06 +00:00
Dmitry Bogatov c5803d9b4c Remove useless catch-all pattern-matching 2019-09-12 04:17:00 +00:00
Dmitry Bogatov ebac00fbde Use safe version of dc_write_file
* src/key.rs(write_asc_to_file): simplify code using safe version of
   dc_write_file() function
2019-09-12 04:11:44 +00:00
Dmitry Bogatov f198ce29b1 Drop unsafe version of dc_get_abs_path 2019-09-12 04:11:43 +00:00
Dmitry Bogatov df47e0ed63 Use safe version of dc_get_abs_path.
* src/dc_mimefactory.rs(build_body_file): use safe version of
   dc_get_abs_path() function.
2019-09-12 04:10:05 +00:00
Dmitry Bogatov 477470ff70 Make dc_msg_get_file return PathBuf, not char*
Adjust call sites as apporiate:

 * src/dc_imex.rs(dc_continue_key_transfer): use if-let pattern
   with dc_read_file_safe() and dc_msg_get_file()

 * src/message.rs(dc_msg_get_setupcodebegin): ditto

 * src/message.rs(dc_get_msg_info): simplify code to print information
   about file inside a message.

 * src/message.rs(dc_msg_get_file): simplify function using
   dc_get_abs_path_safe()

 * deltachat-ffi/src/lib.rs(dc_msg_get_file): convert PathBuf to `char *`
   to preserve C API
2019-09-12 04:10:05 +00:00
Dmitry Bogatov 2eda839303 cargo-fmt 2019-09-11 02:21:39 +00:00
Dmitry Bogatov 71a01d3002 Reduce indentation in dc_continue_key_transfer
Replace `if (ok) { }` pattern with `if (!ok) return` to reduce
indentation level.

Note: This commit fails CI due incorrect formatting. It is done
deliberately to simplify review process.
2019-09-11 02:21:39 +00:00
Dmitry Bogatov c20e8f7613 Use safe version of dc_decode_header_words on one call site 2019-09-10 23:31:29 +00:00
Dmitry Bogatov 5bd4606854 Implement safe version of `dc_decode_header_words' 2019-09-10 23:26:08 +00:00
Dmitry Bogatov e7b198849d Copy comment for dc_encode_headers_words from C code 2019-09-10 22:49:53 +00:00
Dmitry Bogatov 3ab0d74af2 Remove unused `unsafe' block in log_event! macro 2019-09-10 22:35:54 +00:00
Dmitry Bogatov 7ed5a8e72f Reimplement logging macros in terms of log_event!
Avoid copy-paste message formatting code in src/log.rs, forwarding all
arguments of info! warn! error! macros to generic log_event! macro.
2019-09-10 22:34:38 +00:00
Dmitry Bogatov 57daa0f7f0 Remove useless argument of logging macros
Previously, logging macros (info! warn! error!) accepted integer
argument (data1), that was passed to callback function verbatim. In all
call sites this argument was 0.

With this change, that data1 argument is no longer part of macro
interface, 0 is always passed to callback in internals of these macros.
2019-09-10 22:26:47 +00:00
Dmitry Bogatov 2dd3f169db Use set_config_bool instead of set_config_int in boolean context 2019-09-10 22:26:47 +00:00
Dmitry Bogatov b97b618b4b Use sql.get_config_bool to simplify dc_is_configured 2019-09-10 22:26:47 +00:00
Dmitry Bogatov bb12488200 Add Sql.{set,get}_config_bool methods
Previously, boolean configurations were implemented on top of i32
(get_config_int, set_config_it) at call sites.

Having one canonical location, containing boolean <-> database
conversion may help to avoid serialization issues.
2019-09-10 22:26:47 +00:00
Dmitry Bogatov 1cdb9c733a Change return type of `dc_is_configured' to bool 2019-09-10 19:08:55 +00:00
Dmitry Bogatov 1576dc1d13 top_evil_rs: check for all-caps version of ok_to_continue pattern 2019-09-10 17:34:17 +00:00
Dmitry Bogatov 4fbb5fbb25 Make it easier to run src/top_evil_rs.py from git root
Currently, `src/top_evil_rs.py' script recursively scans current
directory for Rust sources and print statistics about them.

When run from git root, it also scans target/ directory, which is
useless.

This commit add cludge that checks if script is run from git root
directory, and `chdir' into `src/' before performing actions.

Unprincipled, but convenient.
2019-09-10 17:34:16 +00:00
Dmitry Bogatov 7d9fc682a0 cargo-fmt 2019-09-07 03:09:01 +00:00
Dmitry Bogatov c4c08f2552 Remove ok_to_continue pattern from msg_prepare_raw()
This commit will fail CI due incorrect formatting. It is done
deliberately to simplify review process.
2019-09-07 03:06:13 +00:00
Dmitry Bogatov 400740fdba Simplify prepare_msg_raw() using early return
This commit will fail CI due incorrect formatting. It is done
deliberately to simplify review process.
2019-09-07 03:03:35 +00:00
Dmitry Bogatov 42bce7c0bf Remove last C string from prepare_msg_raw() 2019-09-07 02:54:28 +00:00
Dmitry Bogatov a2281489a6 Create safe version of msgid-generating function 2019-09-07 02:35:13 +00:00
Dmitry Bogatov 9bf7b0bf96 Use more of Rust, less of C strings in prepare_msg_raw() 2019-09-07 01:39:26 +00:00
Dmitry Bogatov 1f82ba74aa Remove redundant checks in prepare_msg_raw() 2019-09-06 23:24:39 +00:00
Dmitry Bogatov 1062ac6ade Drop unsafe version of get_parent_mime_headers function 2019-09-06 23:15:31 +00:00
Dmitry Bogatov aa5304a4f3 Use safe version of `get_parent_mime_headers()' function 2019-09-06 23:15:31 +00:00
Dmitry Bogatov 3a57ba1142 Implement safe version of `get_parent_mime_headers' function 2019-09-06 23:15:31 +00:00
Dmitry Bogatov c0e7293360 Change return type of clist_search_string_nocase to `bool' 2019-09-06 23:15:31 +00:00
Dmitry Bogatov dc1839760c Simplify clist_search_string_nocase using Iterator interface 2019-09-06 23:15:31 +00:00
Dmitry Bogatov a4e4b0fc17 Rustify type of dc_mimeparser_t.subject 2019-09-06 23:15:31 +00:00
Dmitry Bogatov 743e4deb36 Remove dc_mimepart_unref function
Since there is no longer any manually-managed memory, associated with
`dc_mimepart_t' structure, default Drop instances does everything
automatically.
2019-09-06 23:15:30 +00:00
Dmitry Bogatov 1d75f8478c Rustify type of dc_mimepart_t.msg_raw 2019-09-06 23:15:27 +00:00
Dmitry Bogatov 28cfe36f43 Change type of dc_mimeparser_t.decryption_failed to bool 2019-09-06 03:48:41 +00:00
Dmitry Bogatov e0df78c5f7 Change type of dc_mimepart_t.is_meta to bool 2019-09-06 03:41:18 +00:00
Dmitry Bogatov 4d8b058b65 Change type of dc_mimeparser_t.is_forwarded to bool 2019-09-06 03:36:54 +00:00
Dmitry Bogatov da25611758 Change type of function from `const char *' to &str 2019-09-06 03:05:12 +00:00
Dmitry Bogatov 98d6bdb48a Simplify control flow in dc_DC_JOB_SEND function
Replace `ok_to_continue' control flow variables with early return from
function, since there is no longer need to free memory manually.
2019-09-04 16:44:51 +02:00
Dmitry Bogatov 0391aebaeb Remove C pointer manipulation from do_DC_JOB_SEND()
This change removes several `unsafe' blocks by using safe version of
`dc_read_file' function.

Note, that logic is changed slightly: if get(Param::File) returns
Some(""), it no longer triggers "missing filename warnings".
2019-09-04 16:44:51 +02:00
Dmitry Bogatov e60fc0dc30 Fix minor spelling errors in python/README.rst 2019-09-04 06:19:21 +00:00
Dmitry Bogatov 6288909481 Refactor is_known_rfc724_mid() to use Iterator interface 2019-09-03 16:08:52 +02:00
Dmitry Bogatov c95f134963 Change return type of is_known_rfc724_mid_in_list() to bool 2019-09-03 16:08:52 +02:00
Dmitry Bogatov fb5d53226d Fix errorneous ffi check in dc_send_msg 2019-09-01 22:45:49 +00:00
Dmitry Bogatov 9b70ea0595 Fix one clippy::unneeded_unwrap warning 2019-08-28 00:32:01 +00:00
Dmitry Bogatov a6928c29e8 Fix one clippy::unneeded_unwrap warning 2019-08-28 00:23:15 +00:00
Dmitry Bogatov 3d9129c198 Fix one clippy::unneeded_unwrap warning 2019-08-28 00:17:12 +00:00
Dmitry Bogatov cf8f37449c Fix one clippy::unneeded_unwrap warning 2019-08-28 00:13:37 +00:00