unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Michal Nazarewicz <mina86@mina86.com>
To: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>, notmuch@notmuchmail.org
Subject: Re: [PATCH] Add notmuch-remove-duplicates.py script to contrib.
Date: Tue, 04 Sep 2012 22:26:16 +0200	[thread overview]
Message-ID: <xa1tipbtk00n.fsf@mina86.com> (raw)
In-Reply-To: <87d321sg20.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3299 bytes --]

>> On Tue, Sep 04 2012, Dmitry Kurochkin wrote:
>>> +class MailComparator:
>>> +    """Checks if mail files are duplicates."""
>>> +    def __init__(self, filename):
>>> +        self.filename = filename
>>> +        self.mail = self.readFile(self.filename)
>>> +
>>> +    def isDuplicate(self, filename):
>>> +        return self.mail == self.readFile(filename)
>>> +
>>> +    @staticmethod
>>> +    def readFile(filename):
>>> +        with open(filename) as f:
>>> +            data = ""
>>> +            while True:
>>> +                line = f.readline()
>>> +                for header in IGNORED_HEADERS:
>>> +                    if line.startswith(header):

> Michal Nazarewicz <mina86@mina86.com> writes:
>> Case of headers should be ignored, but this does not ignore it.

On Tue, Sep 04 2012, Dmitry Kurochkin wrote:
> It does.

Wait, how?  If line is “received:” how does it starts with “Received:”?

>>> +            if os.path.realpath(comparator.filename) == os.path.realpath(filename):
>>> +                print "Message '%s' has filenames pointing to the
>>> same file: '%s' '%s'" % (msg.get_message_id(), comparator.filename,
>>> filename)
>>
>> So why aren't those removed?
>>
>
> Because it is the same file indexed twice (probably because of
> symlinks).  We do not want to remove the only message file.

Ah, right, with symlinks this is troublesome, but than again, we can
check if there is at least one non-symlink.  If there is, delete
everything else, if there is not, delete all but one arbitrarily chosen
symlink.

>>> +            elif comparator.isDuplicate(filename):
>>> +                os.remove(filename)
>>> +                duplicates_count += 1
>>> +            else:
>>> +                #print "Potential duplicates: %s" % msg.get_message_id()
>>> +                suspected_duplicates_count += 1
>>> +
>>> +    new_timestamp = time.time()
>>> +    if new_timestamp - timestamp > 1:
>>> +        timestamp = new_timestamp
>>> +        sys.stdout.write("\rProcessed %s messages, removed %s duplicates..." % (msg_count, duplicates_count))
>>> +        sys.stdout.flush()
>>> +
>>> +print "\rFinished. Processed %s messages, removed %s duplicates." % (msg_count, duplicates_count)
>>> +if duplicates_count > 0:
>>> +    print "You might want to run 'notmuch new' now."
>>> +
>>> +if suspected_duplicates_count > 0:
>>> +    print
>>> +    print "Found %s messages with duplicate IDs but different content." % suspected_duplicates_count
>>> +    print "Perhaps we should ignore more headers."
>>
>> Please consider the following instead (not tested):

> Thanks for reviewing my poor python code :) I am afraid I do not have
> enough interest in improving it.  I just implemented a simple solution
> for my problem.  Though it looks like you already took time to rewrite
> the script.  Would be great if you send it as a proper patch obsoleting
> this one.

Bah, I'll probably won't have time to properly test it.

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo--

[-- Attachment #2.1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #2.2: Type: application/pgp-signature, Size: 835 bytes --]

  reply	other threads:[~2012-09-04 20:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-04 18:53 [PATCH] Add notmuch-remove-duplicates.py script to contrib Dmitry Kurochkin
2012-09-04 19:43 ` Michal Nazarewicz
2012-09-04 20:12   ` Dmitry Kurochkin
2012-09-04 20:26     ` Michal Nazarewicz [this message]
2012-09-04 20:33       ` Dmitry Kurochkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xa1tipbtk00n.fsf@mina86.com \
    --to=mina86@mina86.com \
    --cc=dmitry.kurochkin@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).