unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* BUG: maildir flags sync with database relative path results in corrupted filename
@ 2015-06-07 15:12 Morgan Veyret
  2015-06-08  6:02 ` David Bremner
  0 siblings, 1 reply; 8+ messages in thread
From: Morgan Veyret @ 2015-06-07 15:12 UTC (permalink / raw)
  To: notmuch


[-- Attachment #1.1: Type: text/plain, Size: 578 bytes --]

Calling Message.tags_to_maildir_flags() when the database has been opened
with a relative path results in a corrupted filename entry in the database.
The actual filename is changed properly but the filename in the database
gets
the relative path prepended.

As I understand it's expected that the database path should be absolute but
corrupting the database when the path is relative sounds dangerous.

Attached is a python script showing the problem.
Run it as follows:

   python ./retag_bug.py db_path +tag,-tag search_query

Also attached is the output showing the problem.

[-- Attachment #1.2: Type: text/html, Size: 807 bytes --]

[-- Attachment #2: retag_bug.txt --]
[-- Type: text/plain, Size: 694 bytes --]

$ notmuch search thread:00000000000005a2
thread:00000000000005a2     March 07 [1/1] Mathieu de Verdiere; [fablab brest] Echange PC DUINO contre ARDUINO MEGA+ramp? (inbox unread)
$ python2 ./test.py ./maildir/ -unread thread:00000000000005a2 
Using db at ./maildir/
Changing tags: -unread
Search query: thread:00000000000005a2
Adding tags: []
Removing tags: ['unread']
Filename: ./maildir/cur/1425822991_0.10764.minux,U=2618,FMD5=7b0d668e0b18d8601b8bce4eec0ed930:2,
Retagging thread:00000000000005a2
Adding []
Removing ['unread']
Sync maildir: True
Found 1 messages to retag
Retag done
Filename: ./maildir/./maildir/cur/1425822991_0.10764.minux,U=2618,FMD5=7b0d668e0b18d8601b8bce4eec0ed930:2,S


[-- Attachment #3: retag_bug.py --]
[-- Type: text/x-python, Size: 2150 bytes --]

import notmuch
import sys

def retag(db,search_query,add_list,remove_list,sync_maildir):
    query = db.create_query(search_query)
    print "Retagging %s"%search_query
    print "Adding %s"%add_list
    print "Removing %s"%remove_list
    print "Sync maildir: %s"%sync_maildir
    try:
        msg_list = list(query.search_messages())
        print "Found %d messages to retag"%len(msg_list)
        db.begin_atomic()
        for msg in msg_list:
            msg.freeze()
            if remove_list == True:
                msg.remove_all_tags()
            else:
                for t in remove_list:
                    msg.remove_tag(t)
            for t in add_list:
                msg.add_tag(t)
            msg.thaw()
            if sync_maildir:
                if msg.tags_to_maildir_flags() != notmuch.STATUS.SUCCESS:
                    raise notmuch.NotmuchError()
        if db.end_atomic() != notmuch.STATUS.SUCCESS:
            raise notmuch.NotmuchError()
        print "Retag done"
    except notmuch.NotmuchError as e:
        print "Failed to retag"
        print e
        return False
    return True

def show_filename(db,search_query):
    query = db.create_query(search_query)
    for msg in query.search_messages():
        print "Filename: %s"%msg.get_filename()

notmuch_path = sys.argv[1]
notmuch_tags = sys.argv[2]
notmuch_query = ' '.join(sys.argv[3:])

print "Using db at %s"%notmuch_path
print "Changing tags: %s"%notmuch_tags
print "Search query: %s"%notmuch_query

add_list = list()
remove_list = list()

for it in notmuch_tags.split(','):
    if it[0] == '+':
        add_list.append(it[1:])
    elif it[0] == '-':
        remove_list.append(it[1:])

print "Adding tags: %s"%add_list
print "Removing tags: %s"%remove_list



db = notmuch.Database(path=notmuch_path, mode=notmuch.Database.MODE.READ_ONLY)
show_filename(db,notmuch_query)
db.close()

db = notmuch.Database(path=notmuch_path, mode=notmuch.Database.MODE.READ_WRITE)
retag(db,notmuch_query,add_list,remove_list,True)
db.close()


db = notmuch.Database(path=notmuch_path, mode=notmuch.Database.MODE.READ_ONLY)
show_filename(db,notmuch_query)
db.close()


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-06-12  5:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-07 15:12 BUG: maildir flags sync with database relative path results in corrupted filename Morgan Veyret
2015-06-08  6:02 ` David Bremner
2015-06-08 18:41   ` Morgan Veyret
2015-06-08 20:37     ` David Bremner
2015-06-10  7:17       ` [PATCH 1/2] lib: add NOTMUCH_STATUS_PATH_ERROR David Bremner
2015-06-10  7:17         ` [PATCH 2/2] lib: reject relative paths in n_d_{create,open}_verbose David Bremner
2015-06-11 20:21         ` [PATCH 1/2] lib: add NOTMUCH_STATUS_PATH_ERROR Tomi Ollila
2015-06-12  5:40           ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).