Opened 6 years ago
Closed 4 years ago
#1484467 closed Bugs (fixed)
Subfolders not working on IMAP system using backslash separator
| Reported by: | davidg | Owned by: | till |
|---|---|---|---|
| Priority: | 5 | Milestone: | 0.2.1 |
| Component: | IMAP connection | Version: | git-master |
| Severity: | normal | Keywords: | hierarchical folders subfolders quoted literal string backslash |
| Cc: | sob@… |
Description
Domino 5.0/Lotus Notes uses the backslash (\) character as the mailbox hierarchy delimiter, however RoundCube appears to simply remove all such characters from mailbox names, resulting in a mailbox name of "folder 1\subfolder 2" appearing as "folder 1subfolder 2" and being unusable.
A LIST "" "*" command sent to the server returns lines such as:
* LIST () "\\" {20}
folder 1\subfolder 2
From reading RFC3501, this appears legal, with the quoted string "
" needing to be converted ("\"), and the literal string (second line) taken as is without conversion ("folder 1\subfolder 2")
RoundCube, however, indiscriminately removes all backslashes from both the mailbox name and the delimiter, leaving a null delimiter ("") and a mailbox name without a delimiter ("folder 1subfolder 2"). Here's the code:
[program/lib/imap.inc]
1725 $folder = str_replace("\"", "", $a[count($a)-1]);
. . .
1728 $delim = str_replace("\"", "", $a[count($a)-2]);
I don't know if this is the only place this is done; I suspect not and will do some more looking.
While this is specifically affecting hierarchical folders, it looks to be a more general problem with how strings are being handled. Proper behavior would be to leave literal strings, like the second line of the above example, unchanged. Quoted strings, like "
" in the first line, need to have double-backslashes converted into singles, and single backslashes removed (leaving the characters they are protecting intact).
The code currently takes some shortcuts, treating both quoted and literal strings the same -- as literal strings, with the exception of a blanket removal of all backslashes. In particular, iil_MultLine simply adds quotes around the literal and treats it like a quoted string, ignoring the possibility of characters being present that might need special treatment, such as the backslash.
The simplest solution would probably be for iil_MultLine to add a backslash in front of any backslashes in the literal string (and perhaps in front of other special characters like " characters), and then have a routine to remove them again, properly converting double-backslashes into single ones, in place of the str_replace function currently used.
BTW, I could probably fix some of this stuff and will for my own purposes if need be. Is submitting a ticket like this the best way to help RoundCube development, or what would be involved in becoming a developer and/or submitting code changes more directly?
Change History (9)
comment:1 Changed 6 years ago by till
- Component changed from Client to PHP backend
- Milestone set to 0.1-rc2
- Owner set to till
- Status changed from new to assigned
comment:2 Changed 6 years ago by till
comment:3 Changed 6 years ago by thomasb
- Milestone changed from 0.1-rc2 to 0.1-stable
I can't see any wrong behavior of imap.inc
str_replace("\"", "", does not remove backslashes but quotes.
Please suggest a concrete fix to make it work with your Domino server because we're unable to test it.
comment:4 Changed 6 years ago by seansan
Maybe if we identify the delimiter first we can clean up the code accordingly?
/** * Returns the delimiter that is used by the IMAP server for folder separation * * @return string Delimiter string * @access public */ function get_hierarchy_delimiter(
comment:5 Changed 5 years ago by coolfactor
Just as a precautionary measure, and for clarity, it might be an idea to change the code to using single quotes around the double-quote.
str_replace('"', '', $a[count($a)-1])
In PHP, it's safe to use single quotes in most cases, especially when parsing of the string is not needed/wanted.
comment:6 Changed 5 years ago by till
- Resolution set to wontfix
- Status changed from assigned to closed
I'm closing this bug because a) there is no feedback, b) none of us has access to this mailserver and c) I see nothing in imap.inc where this delimiter would be stripped from.
comment:7 Changed 4 years ago by Sob
- Cc sob@… added
- Keywords backslash added
- Milestone 0.1-stable deleted
- Resolution wontfix deleted
- Status changed from closed to reopened
- Version changed from 0.1-rc1 to svn-trunk
I also have IMAP server (UW IMAP on Windows) with backslashes as hierarchy delimiters. So far I found two problems:
1) delimiters are not detected
It can be solved by changing program/lib/imap.inc@2204 from:
$delimiter = str_replace('"', '', $a[count($a)-2]);
to:
$delimiter = stripslashes(str_replace('"', '', $a[count($a)-2]));
2) messages can't be moved to/from subfolders
Changing program/include/rcube_imap.php@1598 from:
$to_mbox_in = stripslashes($to_mbox); $from_mbox = stripslashes($from_mbox);
to:
$to_mbox_in = $to_mbox;
solves it, but I'm not exactly sure about the change. I mean, those stripslashes() probably weren't there just for fun. :)
comment:8 Changed 4 years ago by alec
- Component changed from PHP backend to IMAP connection
- Milestone set to 0.2.1
Can you provide a test account for me. Write to alec at alec.pl.
comment:9 Changed 4 years ago by alec
- Resolution set to fixed
- Status changed from reopened to closed
Fixed in [b7c1685b].

I know it's been a while, but I'd like to integrate your work into Roundcube.