|
@@ -4,6 +4,7 @@ import email.header
|
|
|
import sqlite3
|
|
|
import hashlib
|
|
|
import time
|
|
|
+import datetime
|
|
|
|
|
|
conn = sqlite3.connect("mailboxes.db")
|
|
|
conn.row_factory = sqlite3.Row
|
|
@@ -15,9 +16,15 @@ def connect(server, username, password, folder):
|
|
|
c.select(folder, readonly=True)
|
|
|
return c
|
|
|
|
|
|
-def mailbox(c, id):
|
|
|
+def mailbox(c, id, last_fetch):
|
|
|
+ today = datetime.datetime.today().strftime("%d-%b-%Y")
|
|
|
|
|
|
- r, data = c.search(None, "ALL")
|
|
|
+ if last_fetch:
|
|
|
+ search_string = "(SINCE " + last_fetch + ")"
|
|
|
+ else:
|
|
|
+ search_string = "ALL"
|
|
|
+
|
|
|
+ r, data = c.search(None, search_string)
|
|
|
for num in data[0].split():
|
|
|
r, data = c.fetch(num, '(RFC822)')
|
|
|
msg = email.message_from_string(data[0][1])
|
|
@@ -28,7 +35,6 @@ def mailbox(c, id):
|
|
|
|
|
|
print(subject)
|
|
|
|
|
|
-
|
|
|
sql.execute("SELECT * FROM mails WHERE mailid = ?", (mailid, ))
|
|
|
if sql.fetchone() != None:
|
|
|
continue
|
|
@@ -46,6 +52,7 @@ def mailbox(c, id):
|
|
|
sql.execute("UPDATE mails SET has_attachments = 1 WHERE mailid = ?", (mailid, ))
|
|
|
sql.execute("INSERT INTO attachments (mailid, filename) VALUES (?, ?)", (mailid, filename, ))
|
|
|
|
|
|
+ sql.execute("UPDATE accounts SET last_fetch = ? WHERE id = ?", (today, id,))
|
|
|
|
|
|
|
|
|
|
|
@@ -53,7 +60,7 @@ def main():
|
|
|
sql.execute("SELECT * FROM accounts")
|
|
|
accounts = sql.fetchall()
|
|
|
for account in accounts:
|
|
|
- mailbox(connect(account["server"], account["username"], account["password"], account["folder"]), account["id"])
|
|
|
+ mailbox(connect(account["server"], account["username"], account["password"], account["folder"]), account["id"], account["last_fetch"])
|
|
|
|
|
|
main()
|
|
|
|