go-imap-sql icon indicating copy to clipboard operation
go-imap-sql copied to clipboard

Flags/PermanentFlags somehow contains an empty string

Open ptrcnull opened this issue 2 years ago • 2 comments

originally reported here: https://github.com/emersion/go-imap/issues/544
tl;dr: go-imap-sql inserts an empty string to Flags, which then gets incorrectly serialized in go-imap for the SELECT response and becomes impossible to get parsed back by go-imap itself

looks like the logic for collecting flags from the mailbox is wrong: https://github.com/foxcpp/go-imap-sql/blob/c0176dad/mailbox.go#L128-L137

the simplest fix would be

if flag == "" {
    continue
}

though i'm not sure why it even happens

ptrcnull avatar Sep 11 '23 00:09 ptrcnull

checking the SQL database itself, there indeed is at least one record in the flags table where the flag itself is an empty string:

maddy> SELECT DISTINCT flag FROM flags;
+------------------+
| flag             |
|------------------|
| \Deleted         |
| $mdnsent         |
| $Label4          |
| nonjunk          |
| $label4          |
| $forwarded       |
| $label1          |
| \Answered        |
| \Seen            |
| junk             |
| loadremoteimages |
|                  |
| \Draft           |
| \Recent          |
| \Flagged         |
| $Label1          |
| yeet             |
+------------------+
SELECT 17
Time: 0.053s
maddy>

ptrcnull avatar Sep 11 '23 01:09 ptrcnull

it looks like there's quite a lot of them actually...

maddy> select count(*) from flags;
+--------+
| count  |
|--------|
| 126760 |
+--------+
SELECT 1
Time: 0.040s
maddy> select count(*) from flags where flag = '';
+-------+
| count |
|-------|
| 39784 |
+-------+
SELECT 1
Time: 0.051s
maddy>

so i assume it's not an accidental insert, and instead the parsing should be fixed to not include the empty string

ptrcnull avatar Sep 11 '23 01:09 ptrcnull