OSDN Git Service

Add web mail viewer 'Maverick'.
[mave/mave.git] / mave_controller.rb
index 991e819..095124d 100644 (file)
@@ -61,6 +61,7 @@ class MaveController
                        :mk_global_import_mail                  => method(:import_mail),
                        :mk_global_fetch_mail_pop               => method(:fetch_mail_pop),
                        :mk_global_send_mail_smtp               => method(:send_mail_smtp),
+                       :mk_global_toggle_what_scache   => method(:toggle_what_scache),
                        :mk_global_toggle_what_charset  => method(:toggle_what_charset),
                        :mk_global_kill_mave                    => method(:kill_mave),
 
@@ -138,7 +139,9 @@ class MaveController
 
                                                @models[:FOLDERS].each(:BIND_PRIORITY) {|folder|
                                                        if(folder.bind?(mail, account))
-                                                               folder.add_mail(mail)
+                                                               sq = folder.add_mail(mail)
+                                                               (it = mail.cc) and it.index(account.mail_from) and folder.ccyou(sq)
+                                                               (it = mail.to) and it.index(account.mail_from) and folder.toyou(sq)
                                                                @models[:FOLDERS].unred(folder)
                                                                break
                                                        end
@@ -153,7 +156,8 @@ class MaveController
                                @models[:STATUS].log([_('Failed to imported mail. file=[%s] reason=[%s]'), target, $!.message.split(/\r?\n/)[0]])
                        end
                }
-               @models[:STATUS].log([_('%1$s mail%2$s imported.'), (it = m_mail) == 0 ? 'no' : it.to_s, it == 1 ? '' : 's'])
+               result_message = (it = m_mail) != 0 ? '%1$s mail%2$s imported.' : 'no mails imported.'
+               @models[:STATUS].log([_(result_message), it.to_s, it == 1 ? '' : 's'])
                @models[:FOLDERS].dirty                                                                 # メール数の再表示
        end
 
@@ -182,9 +186,11 @@ class MaveController
 
                                        debug('Subject: %s' % mail.subject.decode_mh) if(debug = false) # 振り分けのデバッグ
                                        @models[:FOLDERS].each(:BIND_PRIORITY) {|folder|
-                                               debug('  %5s %3d: %s' % [folder.bind?(mail, account), folder.configs[:BIND_PRIORITY], folder.name]) if(debug)
+                                               debug('  %5s %3d: [%s] %s [%s]' % [folder.bind?(mail, account), folder.configs[:BIND_PRIORITY], mail.binding, folder.name, account[:TRASH_FOLDER]]) if(debug)
                                                if(folder.bind?(mail, account))
-                                                       folder.add_mail(mail)
+                                                       sq = folder.add_mail(mail)
+                                                       (it = mail.cc) and it.index(account.mail_from) and folder.ccyou(sq)
+                                                       (it = mail.to) and it.index(account.mail_from) and folder.toyou(sq)
                                                        @models[:FOLDERS].unred(folder)
                                                        @pop_directory.delete(halfname) unless(RUBY_PLATFORM =~ /i.86-mswin32/) ####
                                                        break
@@ -198,7 +204,8 @@ class MaveController
                                @models[:STATUS].log([_('Failed to pop mail. reason=[%s]'), $!.message.split(/\r?\n/)[0]])
                        end
                }
-               @models[:STATUS].log([_('%1$s mail%2$s popped.'), (it = m_mail) == 0 ? 'no' : it.to_s, it == 1 ? '' : 's'])
+               result_message = (it = m_mail) != 0 ? '%1$s mail%2$s popped.(%3$s)' : 'no mails popped.(%3$s)'
+               @models[:STATUS].log([_(result_message), it.to_s, it == 1 ? '' : 's', Time.now.myexectime])
                @models[:FOLDERS].dirty                                                                 # メール数の再表示
        end
 
@@ -208,8 +215,8 @@ class MaveController
        #
        def send_mail_smtp
                m_mail = 0
-               @models[:ACCOUNTS].each {|account|
-                       next unless(account.smtp_server)
+               account = @models[:ACCOUNTS].regular
+               if(account.smtp_server)
                        begin
                                n_mail = 0; max_n_mail = 9999
                                outbox_folder = @models[:FOLDERS].open_folder(account[:OUTBOX_FOLDER])
@@ -263,8 +270,9 @@ class MaveController
                        rescue
                                @models[:STATUS].log([_('Failed to send mail. reason=[%s]'), $!.message.split(/\r?\n/)[0]])
                        end
-               }
-               @models[:STATUS].log([_('%1$s mail%2$s sent.'), (it = m_mail) == 0 ? 'no' : it.to_s, it == 1 ? '' : 's'])
+               end
+               result_message = (it = m_mail) != 0 ? '%1$s mail%2$s sent.(%3$s)' : 'no mails sent.(%3$s)'
+               @models[:STATUS].log([_(result_message), it.to_s, it == 1 ? '' : 's', Time.now.myexectime])
                @models[:FOLDERS].dirty                                                                 # メール数の再表示
        end
 
@@ -403,6 +411,7 @@ class MaveController
                        unless(@configs[:VIEWER_TYPE] == 'forkexec')            # 一旦 Curse を閉じて、ビューアアプリを起動する場合
                                @views.close
                                system(@configs[:VIEWER] % (@pop_directory.path + '/' + params[:HALFNAME]))
+#                              pickup_file_force
                                @pop_directory.delete(params[:HALFNAME]) unless(RUBY_PLATFORM =~ /i.86-mswin32/)        ####
                                @views.reopen
                        else                                                                                            # 別途ウィンドウで、ビューアアプリを起動する場合
@@ -488,6 +497,7 @@ class MaveController
                                                create_new_relations(mail, editfile[:MAIL].folder)              # 新規関連ファイル作成処理
                                                extract_attachments(mail, editfile[:MAIL].folder)               # 添付ファイル展開処理
                                                editfile[:MAIL].folder.overwrite_mail(mail, editfile[:MAIL])
+                                               editfile[:MAIL].folder.delete_abstract(editfile[:MAIL].sq)
                                                @models[:STATUS].log([_('The message was overwrited.')])
                                        else
                                                create_new_relations(mail, editfile[:MAIL].folder)              # 新規関連ファイル作成処理
@@ -499,21 +509,24 @@ class MaveController
                                end
                        elsif(editfile[:FOLDER])
                                if(editfile[:SOURCEHASH] == editfile[:FOLDER].md5)                              # (編集前 == 現在)?
-                                       @models[:FOLDERS].overwrite_folder_configs(editfile[:FOLDER], File.new(@pop_directory.path + '/' + editfile[:HALFNAME]))
-                                       @models[:STATUS].log([_('Folder configs ware overwrited.')])
+                                       folder = @models[:FOLDERS].overwrite_folder_configs(editfile[:FOLDER], File.new(@pop_directory.path + '/' + editfile[:HALFNAME]))
+                                       @views[:SUMMARY].tie(folder)
+                                       @views[:FOLDERLIST].list_items; @views[:FOLDERLIST].target_cursor(folder)
+                                       @models[:STATUS].log([_('Folder configs were overwrited.')])
                                else
 #                                      editfile[:FOLDER].folder.add_mail(mail)                                         #### 別名で保存しておく
-                                       @models[:STATUS].log([_('Folder configs ware discarded (edit collision was detected).')])
+                                       @models[:STATUS].log([_('Folder configs were discarded (edit collision was detected).')])
                                end
                        else
                                @models[:STATUS].log([_('The file was discarded (unexpected type).')])
                        end
                else
                        @models[:STATUS].log([_('The message was discarded.')])         if(editfile[:MAIL])
-                       @models[:STATUS].log([_('Folder configs ware discarded.')])     if(editfile[:FOLDER])
+                       @models[:STATUS].log([_('Folder configs were discarded.')])     if(editfile[:FOLDER])
                end
                @pop_directory.delete(editfile[:HALFNAME]) unless(RUBY_PLATFORM =~ /i.86-mswin32/)      ####
                @models[:FOLDERS].dirty                                                                 # メール数の再表示
+               @views[:PREVIEW].untie
        end
 
        #-----------------------------------------------------------
@@ -581,6 +594,7 @@ class MaveController
                                unless(@configs[:FILE_MANAGER_TYPE] == 'forkexec')
                                        @views.close
                                        system(@configs[:FILE_MANAGER] % target_dir)
+#                                      pickup_file_force
                                        @views.reopen
                                else
                                        pid = fork {
@@ -595,6 +609,16 @@ class MaveController
 
        #-----------------------------------------------------------
        #
+       #       メールの概要キャッシュ(インクリメンタルサーチ用)表示、切り替え
+       #
+       def toggle_what_scache
+               state = MaveFolder.toggle_what_scache
+               @models[:STATUS].log(['what search cache: %s', state.to_s])
+               @views[:SUMMARY].list_items
+       end
+
+       #-----------------------------------------------------------
+       #
        #       キャラクタセット情報の表示、切り替え(デバッグ用)
        #
        def toggle_what_charset
@@ -611,7 +635,10 @@ class MaveController
                        @models[:STATUS].log([_('%1$d editor%2$s alive.'), it, it == 1 ? ' is' : 's are'])
                        @force_kill = true
                else
+                       @models[:FOLDERS].close
                        @models[:ACCOUNTS].close
+                       @models[:ADDRESS_BOOK].close
+                       @pop_directory.close if(@pop_directory)
                        raise 'Full stop.'
                end
        end