From 4a5321b0071bad598265901b04b5f918e3881566 Mon Sep 17 00:00:00 2001 From: lnu Date: Tue, 19 Jul 2005 11:25:20 +0000 Subject: git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@34 f70e237a-67f3-0310-a06c-d2b8a7116972 --- lib/feed2imap/imap.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'lib/feed2imap/imap.rb') 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 -- cgit v1.2.3-54-g00ecf