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

Change folder with description in addition to path #1516

Merged
merged 1 commit into from
Jan 2, 2019

Conversation

austin-ray
Copy link
Contributor

What does this PR do?

Adds the ability to change folders based on description instead of path. With the introduction of named-mailboxes and removal of virtual-mailboxes's special cases, we cannot assume that the user will always provide a path.

Instead of bailing when path probing fails, try to find a mailbox with a matching description. If successful, overwrite the buffer with its path.

Areas to review before merging:

  1. Free allocated memory
    mutt_str_strdup() allocates memory, but I have not included a FREE() call. I believe two FREE() calls are needed: before the return on line 620. and after the mutt_str_replace() call on line 625. Replacing the mutt_str_strdup() with a pointer to m->path may obviate any new FREE() calls.
  2. The affect on hooks.
    This may not be an issue since descriptions would result in bailing before attempting to execute a hook. Since this PR makes sure buf is a path, not a description, we shouldn't run into any issues. However, further analysis is warranted to confirm whether or not this is an issue.

What are the relevant issue numbers?

#1470

@austin-ray austin-ray added the topic:notmuch Notmuch search engine label Jan 1, 2019
@ghost ghost assigned austin-ray Jan 1, 2019
@ghost ghost added the status:in-progress label Jan 1, 2019
index.c Outdated
if (m)
{
magic = m->magic;
buf = mutt_str_strdup(m->path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a leak. I suggest:

Suggested change
buf = mutt_str_strdup(m->path);
mutt_str_strfcpy(buf, m->path, buflen);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, that will not solve our memory leak without introducing a potential seg-fault. There is a high probably that buf will be shorter than m->path if buf is a description. We will not have enough room to store the path.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see.
buflen isn't the length of the string in buf, but the length of the buffer -- which is 1024 bytes.

To be suitable for a mailbox path, this needs changing in mutt_index_menu():

-char buf[LONG_STRING];
+char buf[PATH_MAX];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggested changes resolved the problem. I have amended my commit.

@flatcap
Copy link
Member

flatcap commented Jan 2, 2019

I've just made one slight change: I've reused the Mailbox variable, m.

If the user's searching by description, it'll be NULL anyway, and it'll save a bit of time when it's passed to mx_mbox_open().

The folder-hook call looks OK. We've either found a matching mailbox (path) or bailed out.

@austin-ray
Copy link
Contributor Author

I've just made one slight change: I've reused the Mailbox variable, m

I swear I looked for an existing Mailbox variable, but thank you for simplifying it. Good thing we have these reviews :)

The folder-hook call looks OK.

That was my gut-instinct as well. On a slightly off-topic note, have we considered expanding folder-hooks to work on descriptions? notmuch users work around the path limitation by matching on a unique dummy variable in their queries.

@flatcap
Copy link
Member

flatcap commented Jan 2, 2019

have we considered expanding folder-hooks to work on descriptions?

I certainly hadn't until you raise this PR.

The rules for matching descriptions might have to be tighter, so that we can use brief strings without matching lots of mailboxes.

Please investigate.

Mailbox: find mailbox by description

Introduce `mutt_find_mailbox_desc()`, which takes a pointer to a
description, and tries to find a mailbox that corresponds to it.

With the introduction of `named-mailboxes` and removal of
`virtual-mailboxes` special cases, users may prefer to operate with
descriptions instead of (potentially) ugly paths. We can no longer
assume that a buffer is a path and require a method to find by
description.

This is not included as an `mxapi` function since `desc` is common to
all mailboxes so the backends do not need implement their own function.

Index: try description when changing mailboxes

Since mailbox descriptions are more prevalent with `named-mailboxes` and
`virtual-mailbox` special cases being removed, some users will try to
change folders with a description instead of a path.

This commit modifies `main_change_folder()` to look for a mailbox with a
given description if path probing fails.
@flatcap flatcap merged commit 6b9065a into neomutt:master Jan 2, 2019
@ghost ghost removed the status:in-progress label Jan 2, 2019
@austin-ray austin-ray deleted the devel/issue/1470 branch July 4, 2021 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:notmuch Notmuch search engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants