summaryrefslogtreecommitdiff
path: root/lib/feed2imap
diff options
context:
space:
mode:
authorlnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972>2005-07-19 11:25:20 +0000
committerlnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972>2005-07-19 11:25:20 +0000
commit4a5321b0071bad598265901b04b5f918e3881566 (patch)
tree421ad77cd6579d0e8ec5751aadc9cd63e31136b9 /lib/feed2imap
parent591f5ed2562b7eeecc9c5b6a8fe3d5d5fa5a6b93 (diff)
downloadfeed2imap-4a5321b0071bad598265901b04b5f918e3881566.tar.gz
feed2imap-4a5321b0071bad598265901b04b5f918e3881566.tar.bz2
feed2imap-4a5321b0071bad598265901b04b5f918e3881566.zip
git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@34 f70e237a-67f3-0310-a06c-d2b8a7116972
Diffstat (limited to '')
-rw-r--r--lib/feed2imap/imap.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/feed2imap/imap.rb b/lib/feed2imap/imap.rb
index 8c4c912..bb905e6 100644
--- a/lib/feed2imap/imap.rb
+++ b/lib/feed2imap/imap.rb
@@ -50,6 +50,7 @@ class ImapAccount
def initialize(uri)
@uri = uri
+ self
end
# connects to the IMAP server
@@ -71,6 +72,7 @@ class ImapAccount
@connection = Net::IMAP::new(uri.host, port, usessl)
user, password = uri.userinfo.split(':',2)
@connection.login(user, password)
+ self
end
# disconnect from the IMAP server
@@ -96,6 +98,7 @@ class ImapAccount
@connection.append(folder, mail)
end
+ # update a mail
def updatemail(folder, mail, idx)
@connection.select(folder)
searchres = @connection.search(['HEADER', 'X-CacheIndex', "-#{idx}-"])
@@ -109,8 +112,36 @@ class ImapAccount
@connection.append(folder, mail, flags)
end
+ # convert to string
def to_s
uri.to_s
end
+
+ # remove mails in a folder according to a criteria
+ def cleanup(folder, dryrun = false)
+ puts "-- Considering #{folder}:"
+ @connection.select(folder)
+ a = ['NOT', 'NEW', 'NOT', 'FLAGGED', 'BEFORE', (Date::today - 10).strftime('%d-%b-%Y')]
+ todel = @connection.search(a)
+ todel.each do |m|
+ f = @connection.fetch(m, "FULL")
+ d = f[0].attr['INTERNALDATE']
+ s = f[0].attr['ENVELOPE'].subject
+ if s =~ /^=\?utf-8\?b\?/
+ s = Base64::decode64(s.gsub(/^=\?utf-8\?b\?(.*)\?=$/, '\1')).toISO_8859_1('utf-8')
+ end
+ if dryrun
+ puts "To remove: #{s} (#{d})"
+ else
+ puts "Removing: #{s} (#{d})"
+ @connection.store(m, "+FLAGS", [:Deleted])
+ end
+ end
+ puts "-- Deleted #{todel.length} messages."
+ if not dryrun
+ @connection.expunge
+ end
+ return todel.length
+ end
end