From: Michal Nazarewicz <mpn@google.com>
To: Jason@zx2c4.com
Cc: notmuch@notmuchmail.org
Subject: [PATCH] Minor style changes.
Date: Fri, 7 Dec 2012 12:48:13 +0100 [thread overview]
Message-ID: <84e52691df739ca60507787173b41663caaf99ed.1354880726.git.mina86@mina86.com> (raw)
In-Reply-To: <CAHmME9om0twqigr0L2pwXtbj4ceBVVFz0HqxkwFfB-AnusP2VQ@mail.gmail.com>
From: Michal Nazarewicz <mina86@mina86.com>
---
gmail-notmuch.py | 29 +++++++++--------------------
1 files changed, 9 insertions(+), 20 deletions(-)
On Fri, Dec 07 2012, Jason A. Donenfeld wrote:
> I wrote a script that imports emails and tags from gmail. It's
> resumable and appears to be working reasonably well. I could use some
> experienced eyes looking at it, as my first exposure to notmuch was
> just a few hours ago.
Didn't really use it, but I still have some suggested code changes: ;)
diff --git a/gmail-notmuch.py b/gmail-notmuch.py
index 04a60dc..ef7fa85 100755
--- a/gmail-notmuch.py
+++ b/gmail-notmuch.py
@@ -43,7 +43,7 @@ def main():
(options, args) = parser.parse_args()
if options.username == None or options.password == None:
parser.error("Username and password are required.")
- if not options.username.lower().endswith("@gmail.com") and not options.username.lower().endswith("@googlemail.com"):
+ if options.username.find("@") == -1:
options.username += "@gmail.com"
if len(args) == 0:
parser.error("Maildir location is required.")
@@ -60,7 +60,7 @@ def main():
print("Nothing to do!")
logout(imap)
sys.exit(0)
-
+
download_new_messages(imap, new_messages, destination_dir)
logout(imap)
@@ -84,9 +84,8 @@ def discover_new_messages(imap, old_messages):
for response in data:
imap_seq = response[0:response.find(" ")]
gmail_id = response[response.rfind(" ") + 1:len(response) - 1]
- if gmail_id in old_messages:
- continue
- new_messages.append((gmail_id, imap_seq))
+ if gmail_id not in old_messages:
+ new_messages.append((gmail_id, imap_seq))
return new_messages
def download_new_messages(imap, messages, destination):
@@ -112,7 +111,7 @@ def download_new_messages(imap, messages, destination):
typ, data = imap.fetch(str(imap_seq), "(FLAGS X-GM-LABELS)")
if typ != "OK":
sys.exit("Failed to download labels gmail-%d/imap-%d" % (gmail_id, imap_seq))
-
+
labels = label_parser.search(data[0]).groups()
labels = filter_labels(shlex.split(labels[0], False, True) + labels[1].split(" "))
@@ -149,22 +148,12 @@ def filter_labels(labels):
"\\Important": None, # I realize this is controversial, but I hate the priority inbox.
"Junk": "spam",
"NonJunk": None }
- ret = set()
- for label in labels:
- if label in translation:
- if translation[label] is None:
- continue
- ret.add(translation[label])
- else:
- ret.add(label)
- if "!read!" in ret:
- ret.remove("!read!")
- else:
+ ret = set(translation.get(label, label) for label in labels)
+ if not ret.pop("!read!", None):
ret.add("unread")
- if "" in ret:
- ret.remove("")
+ ret.pop(None, None)
+ ret.pop("", None)
return ret
-
def logout(imap):
imap.close()
--
1.7.7.3
prev parent reply other threads:[~2012-12-07 11:48 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-07 0:24 gmail importer script Jason A. Donenfeld
2012-12-07 4:05 ` Kushal Kumaran
2012-12-07 8:53 ` Rainer M Krug
2012-12-07 9:23 ` Patrick Totzke
2012-12-07 13:49 ` Jason A. Donenfeld
2012-12-08 16:20 ` Patrick Totzke
2012-12-08 17:04 ` Jason A. Donenfeld
2012-12-08 17:19 ` Jason A. Donenfeld
[not found] ` <20121213141917.GD3658@tungsten.lan.mitsi.com>
[not found] ` <CAHmME9op8V+ZJGVwBJPZ653mHYBnMAvxb426LAP-Bu27-rzmYA@mail.gmail.com>
2012-12-13 15:23 ` fREW Schmidt
2012-12-13 15:24 ` Jason A. Donenfeld
2012-12-13 16:48 ` Patrick Totzke
2012-12-15 8:22 ` Jason A. Donenfeld
2012-12-15 10:41 ` Patrick Totzke
2012-12-16 20:44 ` Jason A. Donenfeld
2012-12-16 22:31 ` Patrick Totzke
2012-12-17 8:31 ` Patrick Totzke
2012-12-08 17:46 ` Patrick Totzke
2012-12-09 23:13 ` Jason A. Donenfeld
2012-12-10 9:41 ` Patrick Totzke
2012-12-10 17:46 ` Jason A. Donenfeld
2012-12-11 7:06 ` Jason A. Donenfeld
2012-12-11 9:12 ` Patrick Totzke
2012-12-11 9:12 ` Jason A. Donenfeld
2012-12-11 10:04 ` Patrick Totzke
[not found] ` <20121213142228.GE3658@tungsten.lan.mitsi.com>
2012-12-13 14:30 ` Jason A. Donenfeld
2012-12-13 14:35 ` fREW Schmidt
2012-12-13 15:15 ` Jason A. Donenfeld
2012-12-07 13:48 ` Jason A. Donenfeld
2012-12-07 13:57 ` Rainer M Krug
2012-12-07 15:32 ` Jason A. Donenfeld
2012-12-08 12:40 ` Rainer M Krug
2012-12-08 13:15 ` Jason A. Donenfeld
2012-12-10 9:12 ` Rainer M Krug
2012-12-07 15:30 ` Jason A. Donenfeld
2012-12-07 11:48 ` Michal Nazarewicz [this message]
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=84e52691df739ca60507787173b41663caaf99ed.1354880726.git.mina86@mina86.com \
--to=mpn@google.com \
--cc=Jason@zx2c4.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).