From e6ab291ca9821a1f7e012481d4fdfb35fd7e996e Mon Sep 17 00:00:00 2001 From: lnu Date: Tue, 15 May 2007 14:04:04 +0000 Subject: Folder creation moved to upload git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@122 f70e237a-67f3-0310-a06c-d2b8a7116972 --- lib/feed2imap/imap.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'lib/feed2imap/imap.rb') diff --git a/lib/feed2imap/imap.rb b/lib/feed2imap/imap.rb index 933a561..3501530 100644 --- a/lib/feed2imap/imap.rb +++ b/lib/feed2imap/imap.rb @@ -50,6 +50,7 @@ class ImapAccount def initialize(uri) @uri = uri + @existing_folders = [] self end @@ -83,26 +84,26 @@ class ImapAccount end end - # Returns true if the folder exist - def folder_exist?(folder) - return !@connection.list('', folder).nil? - end - - # Creates the given folder - def create_folder(folder) - @connection.create(folder) - @connection.subscribe(folder) - self + # tests if the folder exists and create it if not + def create_folder_if_not_exists(folder) + return if @existing_folders.include?(folder) + if !@connection.list('', folder).nil? + @connection.create(folder) + @connection.subscribe(folder) + end + @existing_folders << folder end # Put the mail in the given folder # You should check whether the folder exist first. def putmail(folder, mail, date = Time::now) + create_folder_if_not_exists(folder) @connection.append(folder, mail.gsub(/\n/, "\r\n"), nil, date) end # update a mail def updatemail(folder, mail, idx, date = Time::now) + create_folder_if_not_exists(folder) @connection.select(folder) searchres = @connection.search(['HEADER', 'X-CacheIndex', "-#{idx}-"]) flags = nil -- cgit v1.2.3-54-g00ecf