Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maildir overhaul #4112

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

maildir overhaul #4112

wants to merge 2 commits into from

Conversation

flatcap
Copy link
Member

@flatcap flatcap commented Nov 22, 2023

Early WIP

The Maildir backend needs an overhaul.
In particular, I need it to send notifications of the specific changes to Mailbox.emails[].
So far, this PR only tackles mbox_open() -- the easy bit.

Current maildir_mbox_open()

The functions mix up Maildir and Hcache code.
Note: The functions' maildir_ prefix has been omitted for clarity.

m1

source: gv svg

New maildir_mbox_open()

Maildir (yellow) and Hcache (blue) are separate.
The red dot denotes functions that can be interrupted by Ctrl-C (SIGINT) -- new feature!

m2

source: gv svg

Comment on lines +1508 to +1512
if (merge_flags2(e, flags, custom))
{
// need to hcache_store()
}

Check notice

Code scanning / CodeQL

Futile conditional Note

If-statement with an empty then-branch and no else-branch.
if (rc != MX_OPEN_OK)
goto done;

// maildir_parse_all_flags(&ea, &ea_cha);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Comment on lines +1743 to +1745
// dump_filenames(&fa_sca, "Scanned");
// dump_filenames(&fa_cha, "Changed");

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
struct EmailArray ea_cha = ARRAY_HEAD_INITIALIZER; ///< Emails: changed
struct EmailArray ea_del = ARRAY_HEAD_INITIALIZER; ///< Emails: deleted
const char *path = mailbox_path(m);
// struct MaildirMboxData *mdata = maildir_mdata_get(m);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
if (rc != MX_OPEN_OK)
goto done;

// maildir_parse_all_flags(&ea, &ea_cha);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
m->msg_count++;
}

// ARRAY_FREE(ea);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
size_t nlen = 0;

if (start > 0)
nlen += sprintf(name + nlen, "%.*s", start, filename);

Check failure

Code scanning / CodeQL

Unbounded write Critical

This 'call to sprintf' with input from
string read by fread
may overflow the destination.
This 'call to sprintf' with input from
string read by fread
may overflow the destination.
This 'call to sprintf' with input from
string read by fgets
may overflow the destination.
This 'call to sprintf' with input from
string read by fgets
may overflow the destination.
if (start > 0)
nlen += sprintf(name + nlen, "%.*s", start, filename);

nlen += sprintf(name + nlen, "\033[1;4;33m%.*s\033[0m", length, filename + start);

Check failure

Code scanning / CodeQL

Unbounded write Critical

This 'call to sprintf' with input from
string read by fread
may overflow the destination.
This 'call to sprintf' with input from
string read by fread
may overflow the destination.
This 'call to sprintf' with input from
string read by fgets
may overflow the destination.
This 'call to sprintf' with input from
string read by fgets
may overflow the destination.
nlen += sprintf(name + nlen, "\033[1;4;33m%.*s\033[0m", length, filename + start);

if (filename[start + length] != '\0')
nlen += sprintf(name + nlen, "%s", filename + start + length);

Check failure

Code scanning / CodeQL

Unbounded write Critical

This 'call to sprintf' with input from
string read by fread
may overflow the destination.
This 'call to sprintf' with input from
string read by fread
may overflow the destination.
This 'call to sprintf' with input from
string read by fgets
may overflow the destination.
This 'call to sprintf' with input from
string read by fgets
may overflow the destination.
buf_concat_path(path_file, mbox_path, fn->sub_name);

struct Email *e = maildir_email_new();
if (maildir_parse_message(buf_string(path_file), fn->is_cur, e))

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This argument to a file access function is derived from
user input (string read by fread)
and then passed to maildir_parse_message(fname), which calls mutt_file_fopen_full(path), which calls fopen(__filename).
This argument to a file access function is derived from
user input (string read by fread)
and then passed to maildir_parse_message(fname), which calls mutt_file_fopen_full(path), which calls mutt_file_open(path), which calls open(__path).
This argument to a file access function is derived from
user input (string read by fread)
and then passed to maildir_parse_message(fname), which calls mutt_file_fopen_full(path), which calls fopen(__filename).
This argument to a file access function is derived from
user input (string read by fread)
and then passed to maildir_parse_message(fname), which calls mutt_file_fopen_full(path), which calls mutt_file_open(path), which calls open(__path).
This argument to a file access function is derived from
user input (string read by fgets)
and then passed to maildir_parse_message(fname), which calls mutt_file_fopen_full(path), which calls fopen(__filename).
This argument to a file access function is derived from
user input (string read by fgets)
and then passed to maildir_parse_message(fname), which calls mutt_file_fopen_full(path), which calls mutt_file_open(path), which calls open(__path).
This argument to a file access function is derived from
user input (string read by fgets)
and then passed to maildir_parse_message(fname), which calls mutt_file_fopen_full(path), which calls fopen(__filename).
This argument to a file access function is derived from
user input (string read by fgets)
and then passed to maildir_parse_message(fname), which calls mutt_file_fopen_full(path), which calls mutt_file_open(path), which calls open(__path).
@flatcap flatcap force-pushed the devel/maildir branch 3 times, most recently from f959a81 to b2bcbbc Compare March 29, 2024 01:43
@flatcap flatcap force-pushed the devel/maildir branch 3 times, most recently from 15d05aa to b811d42 Compare April 5, 2024 23:22
@flatcap flatcap force-pushed the devel/maildir branch 3 times, most recently from c039915 to 1dbca90 Compare April 17, 2024 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:refactoring Code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant