daemon-kit 0.1.8rc1 → 0.1.8rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/Rakefile +1 -1
- data/daemon-kit.gemspec +6 -37
- data/lib/daemon_kit.rb +1 -1
- data/lib/daemon_kit/error_handlers/base.rb +3 -3
- data/lib/daemon_kit/error_handlers/hoptoad.rb +135 -22
- data/lib/daemon_kit/safety.rb +0 -1
- data/lib/generators/daemon_kit/app/templates/config/boot.rb +7 -3
- data/lib/generators/daemon_kit/app/templates/config/environment.rb.tt +5 -2
- metadata +3 -34
- data/Manifest.txt +0 -176
- data/lib/daemon_kit/error_handlers/mail.rb +0 -85
- data/vendor/tmail-1.2.3/tmail.rb +0 -5
- data/vendor/tmail-1.2.3/tmail/address.rb +0 -426
- data/vendor/tmail-1.2.3/tmail/attachments.rb +0 -46
- data/vendor/tmail-1.2.3/tmail/base64.rb +0 -46
- data/vendor/tmail-1.2.3/tmail/compat.rb +0 -41
- data/vendor/tmail-1.2.3/tmail/config.rb +0 -67
- data/vendor/tmail-1.2.3/tmail/core_extensions.rb +0 -63
- data/vendor/tmail-1.2.3/tmail/encode.rb +0 -581
- data/vendor/tmail-1.2.3/tmail/header.rb +0 -960
- data/vendor/tmail-1.2.3/tmail/index.rb +0 -9
- data/vendor/tmail-1.2.3/tmail/interface.rb +0 -1130
- data/vendor/tmail-1.2.3/tmail/loader.rb +0 -3
- data/vendor/tmail-1.2.3/tmail/mail.rb +0 -578
- data/vendor/tmail-1.2.3/tmail/mailbox.rb +0 -495
- data/vendor/tmail-1.2.3/tmail/main.rb +0 -6
- data/vendor/tmail-1.2.3/tmail/mbox.rb +0 -3
- data/vendor/tmail-1.2.3/tmail/net.rb +0 -248
- data/vendor/tmail-1.2.3/tmail/obsolete.rb +0 -132
- data/vendor/tmail-1.2.3/tmail/parser.rb +0 -1476
- data/vendor/tmail-1.2.3/tmail/port.rb +0 -379
- data/vendor/tmail-1.2.3/tmail/quoting.rb +0 -118
- data/vendor/tmail-1.2.3/tmail/require_arch.rb +0 -58
- data/vendor/tmail-1.2.3/tmail/scanner.rb +0 -49
- data/vendor/tmail-1.2.3/tmail/scanner_r.rb +0 -261
- data/vendor/tmail-1.2.3/tmail/stringio.rb +0 -280
- data/vendor/tmail-1.2.3/tmail/utils.rb +0 -337
- data/vendor/tmail-1.2.3/tmail/version.rb +0 -39
- data/vendor/tmail.rb +0 -13
    
        data/Manifest.txt
    DELETED
    
    | @@ -1,176 +0,0 @@ | |
| 1 | 
            -
            Configuration.txt
         | 
| 2 | 
            -
            Deployment.txt
         | 
| 3 | 
            -
            History.txt
         | 
| 4 | 
            -
            Logging.txt
         | 
| 5 | 
            -
            Manifest.txt
         | 
| 6 | 
            -
            PostInstall.txt
         | 
| 7 | 
            -
            README.rdoc
         | 
| 8 | 
            -
            Rakefile
         | 
| 9 | 
            -
            RuoteParticipants.txt
         | 
| 10 | 
            -
            TODO.txt
         | 
| 11 | 
            -
            app_generators/daemon_kit/USAGE
         | 
| 12 | 
            -
            app_generators/daemon_kit/daemon_kit_generator.rb
         | 
| 13 | 
            -
            app_generators/daemon_kit/templates/README
         | 
| 14 | 
            -
            app_generators/daemon_kit/templates/Rakefile
         | 
| 15 | 
            -
            app_generators/daemon_kit/templates/bin/daemon.erb
         | 
| 16 | 
            -
            app_generators/daemon_kit/templates/config/arguments.rb
         | 
| 17 | 
            -
            app_generators/daemon_kit/templates/config/boot.rb
         | 
| 18 | 
            -
            app_generators/daemon_kit/templates/config/environment.rb
         | 
| 19 | 
            -
            app_generators/daemon_kit/templates/config/environments/development.rb
         | 
| 20 | 
            -
            app_generators/daemon_kit/templates/config/environments/production.rb
         | 
| 21 | 
            -
            app_generators/daemon_kit/templates/config/environments/test.rb
         | 
| 22 | 
            -
            app_generators/daemon_kit/templates/config/post-daemonize/readme
         | 
| 23 | 
            -
            app_generators/daemon_kit/templates/config/pre-daemonize/readme
         | 
| 24 | 
            -
            app_generators/daemon_kit/templates/lib/daemon.rb
         | 
| 25 | 
            -
            app_generators/daemon_kit/templates/libexec/daemon.erb
         | 
| 26 | 
            -
            app_generators/daemon_kit/templates/script/console
         | 
| 27 | 
            -
            app_generators/daemon_kit/templates/script/destroy
         | 
| 28 | 
            -
            app_generators/daemon_kit/templates/script/generate
         | 
| 29 | 
            -
            bin/daemon-kit
         | 
| 30 | 
            -
            daemon_generators/amqp/USAGE
         | 
| 31 | 
            -
            daemon_generators/amqp/amqp_generator.rb
         | 
| 32 | 
            -
            daemon_generators/amqp/templates/config/amqp.yml
         | 
| 33 | 
            -
            daemon_generators/amqp/templates/config/initializers/amqp.rb
         | 
| 34 | 
            -
            daemon_generators/amqp/templates/libexec/daemon.rb
         | 
| 35 | 
            -
            daemon_generators/cron/USAGE
         | 
| 36 | 
            -
            daemon_generators/cron/cron_generator.rb
         | 
| 37 | 
            -
            daemon_generators/cron/templates/config/initializers/cron.rb
         | 
| 38 | 
            -
            daemon_generators/cron/templates/libexec/daemon.rb
         | 
| 39 | 
            -
            daemon_generators/cucumber/USAGE
         | 
| 40 | 
            -
            daemon_generators/cucumber/cucumber_generator.rb
         | 
| 41 | 
            -
            daemon_generators/cucumber/templates/cucumber
         | 
| 42 | 
            -
            daemon_generators/cucumber/templates/cucumber.rake
         | 
| 43 | 
            -
            daemon_generators/cucumber/templates/cucumber_environment.rb
         | 
| 44 | 
            -
            daemon_generators/cucumber/templates/env.rb
         | 
| 45 | 
            -
            daemon_generators/deploy_capistrano/deploy_capistrano_generator.rb
         | 
| 46 | 
            -
            daemon_generators/deploy_capistrano/templates/Capfile
         | 
| 47 | 
            -
            daemon_generators/deploy_capistrano/templates/USAGE
         | 
| 48 | 
            -
            daemon_generators/deploy_capistrano/templates/config/deploy.rb
         | 
| 49 | 
            -
            daemon_generators/deploy_capistrano/templates/config/deploy/production.rb
         | 
| 50 | 
            -
            daemon_generators/deploy_capistrano/templates/config/deploy/staging.rb
         | 
| 51 | 
            -
            daemon_generators/deploy_capistrano/templates/config/environments/staging.rb
         | 
| 52 | 
            -
            daemon_generators/jabber/USAGE
         | 
| 53 | 
            -
            daemon_generators/jabber/jabber_generator.rb
         | 
| 54 | 
            -
            daemon_generators/jabber/templates/config/initializers/jabber.rb
         | 
| 55 | 
            -
            daemon_generators/jabber/templates/config/jabber.yml
         | 
| 56 | 
            -
            daemon_generators/jabber/templates/libexec/daemon.rb
         | 
| 57 | 
            -
            daemon_generators/nanite_agent/USAGE
         | 
| 58 | 
            -
            daemon_generators/nanite_agent/nanite_agent_generator.rb
         | 
| 59 | 
            -
            daemon_generators/nanite_agent/templates/config/initializers/nanite_agent.rb
         | 
| 60 | 
            -
            daemon_generators/nanite_agent/templates/config/nanite.yml
         | 
| 61 | 
            -
            daemon_generators/nanite_agent/templates/lib/actors/sample.rb
         | 
| 62 | 
            -
            daemon_generators/nanite_agent/templates/libexec/daemon.rb
         | 
| 63 | 
            -
            daemon_generators/rspec/USAGE
         | 
| 64 | 
            -
            daemon_generators/rspec/rspec_generator.rb
         | 
| 65 | 
            -
            daemon_generators/rspec/templates/spec.rb
         | 
| 66 | 
            -
            daemon_generators/rspec/templates/spec/spec.opts
         | 
| 67 | 
            -
            daemon_generators/rspec/templates/spec/spec_helper.rb
         | 
| 68 | 
            -
            daemon_generators/rspec/templates/tasks/rspec.rake
         | 
| 69 | 
            -
            daemon_generators/ruote/USAGE
         | 
| 70 | 
            -
            daemon_generators/ruote/ruote_generator.rb
         | 
| 71 | 
            -
            daemon_generators/ruote/templates/config/amqp.yml
         | 
| 72 | 
            -
            daemon_generators/ruote/templates/config/initializers/ruote.rb
         | 
| 73 | 
            -
            daemon_generators/ruote/templates/config/ruote.yml
         | 
| 74 | 
            -
            daemon_generators/ruote/templates/lib/daemon.rb
         | 
| 75 | 
            -
            daemon_generators/ruote/templates/lib/sample.rb
         | 
| 76 | 
            -
            daemon_generators/ruote/templates/libexec/daemon.rb
         | 
| 77 | 
            -
            daemon_generators/test_unit/USAGE
         | 
| 78 | 
            -
            daemon_generators/test_unit/templates/tasks/test_unit.rake
         | 
| 79 | 
            -
            daemon_generators/test_unit/templates/test/test.rb
         | 
| 80 | 
            -
            daemon_generators/test_unit/templates/test/test_helper.rb
         | 
| 81 | 
            -
            daemon_generators/test_unit/test_unit_generator.rb
         | 
| 82 | 
            -
            daemon_generators/xmpp/templates/config/initializers/xmpp.rb
         | 
| 83 | 
            -
            daemon_generators/xmpp/templates/config/xmpp.yml
         | 
| 84 | 
            -
            daemon_generators/xmpp/templates/libexec/daemon.rb
         | 
| 85 | 
            -
            daemon_generators/xmpp/xmpp_generator.rb
         | 
| 86 | 
            -
            lib/daemon_kit.rb
         | 
| 87 | 
            -
            lib/daemon_kit/abstract_logger.rb
         | 
| 88 | 
            -
            lib/daemon_kit/amqp.rb
         | 
| 89 | 
            -
            lib/daemon_kit/application.rb
         | 
| 90 | 
            -
            lib/daemon_kit/arguments.rb
         | 
| 91 | 
            -
            lib/daemon_kit/commands/console.rb
         | 
| 92 | 
            -
            lib/daemon_kit/config.rb
         | 
| 93 | 
            -
            lib/daemon_kit/console_daemon.rb
         | 
| 94 | 
            -
            lib/daemon_kit/core_ext.rb
         | 
| 95 | 
            -
            lib/daemon_kit/core_ext/configurable.rb
         | 
| 96 | 
            -
            lib/daemon_kit/core_ext/string.rb
         | 
| 97 | 
            -
            lib/daemon_kit/cron.rb
         | 
| 98 | 
            -
            lib/daemon_kit/cucumber/world.rb
         | 
| 99 | 
            -
            lib/daemon_kit/deployment/capistrano.rb
         | 
| 100 | 
            -
            lib/daemon_kit/em.rb
         | 
| 101 | 
            -
            lib/daemon_kit/error_handlers/base.rb
         | 
| 102 | 
            -
            lib/daemon_kit/error_handlers/hoptoad.rb
         | 
| 103 | 
            -
            lib/daemon_kit/error_handlers/mail.rb
         | 
| 104 | 
            -
            lib/daemon_kit/exceptions.rb
         | 
| 105 | 
            -
            lib/daemon_kit/initializer.rb
         | 
| 106 | 
            -
            lib/daemon_kit/jabber.rb
         | 
| 107 | 
            -
            lib/daemon_kit/nanite.rb
         | 
| 108 | 
            -
            lib/daemon_kit/nanite/agent.rb
         | 
| 109 | 
            -
            lib/daemon_kit/pid_file.rb
         | 
| 110 | 
            -
            lib/daemon_kit/ruote_participants.rb
         | 
| 111 | 
            -
            lib/daemon_kit/ruote_pseudo_participant.rb
         | 
| 112 | 
            -
            lib/daemon_kit/ruote_workitem.rb
         | 
| 113 | 
            -
            lib/daemon_kit/safety.rb
         | 
| 114 | 
            -
            lib/daemon_kit/tasks.rb
         | 
| 115 | 
            -
            lib/daemon_kit/tasks/environment.rake
         | 
| 116 | 
            -
            lib/daemon_kit/tasks/framework.rake
         | 
| 117 | 
            -
            lib/daemon_kit/tasks/god.rake
         | 
| 118 | 
            -
            lib/daemon_kit/tasks/log.rake
         | 
| 119 | 
            -
            lib/daemon_kit/tasks/monit.rake
         | 
| 120 | 
            -
            script/console
         | 
| 121 | 
            -
            script/destroy
         | 
| 122 | 
            -
            script/generate
         | 
| 123 | 
            -
            script/txt2html
         | 
| 124 | 
            -
            spec/abstract_logger_spec.rb
         | 
| 125 | 
            -
            spec/argument_spec.rb
         | 
| 126 | 
            -
            spec/config_spec.rb
         | 
| 127 | 
            -
            spec/configurable_spec.rb
         | 
| 128 | 
            -
            spec/daemon_kit_spec.rb
         | 
| 129 | 
            -
            spec/error_handlers_spec.rb
         | 
| 130 | 
            -
            spec/fixtures/env.yml
         | 
| 131 | 
            -
            spec/fixtures/noenv.yml
         | 
| 132 | 
            -
            spec/initializer_spec.rb
         | 
| 133 | 
            -
            spec/spec.opts
         | 
| 134 | 
            -
            spec/spec_helper.rb
         | 
| 135 | 
            -
            tasks/rspec.rake
         | 
| 136 | 
            -
            templates/god/god.erb
         | 
| 137 | 
            -
            templates/monit/monit.erb
         | 
| 138 | 
            -
            test/test_amqp_generator.rb
         | 
| 139 | 
            -
            test/test_cron_generator.rb
         | 
| 140 | 
            -
            test/test_daemon-kit_generator.rb
         | 
| 141 | 
            -
            test/test_daemon_kit_config.rb
         | 
| 142 | 
            -
            test/test_deploy_capistrano_generator.rb
         | 
| 143 | 
            -
            test/test_generator_helper.rb
         | 
| 144 | 
            -
            test/test_helper.rb
         | 
| 145 | 
            -
            test/test_jabber_generator.rb
         | 
| 146 | 
            -
            test/test_nanite_agent_generator.rb
         | 
| 147 | 
            -
            test/test_ruote_generator.rb
         | 
| 148 | 
            -
            test/test_test_unit_generator.rb
         | 
| 149 | 
            -
            vendor/tmail-1.2.3/tmail.rb
         | 
| 150 | 
            -
            vendor/tmail-1.2.3/tmail/address.rb
         | 
| 151 | 
            -
            vendor/tmail-1.2.3/tmail/attachments.rb
         | 
| 152 | 
            -
            vendor/tmail-1.2.3/tmail/base64.rb
         | 
| 153 | 
            -
            vendor/tmail-1.2.3/tmail/compat.rb
         | 
| 154 | 
            -
            vendor/tmail-1.2.3/tmail/config.rb
         | 
| 155 | 
            -
            vendor/tmail-1.2.3/tmail/core_extensions.rb
         | 
| 156 | 
            -
            vendor/tmail-1.2.3/tmail/encode.rb
         | 
| 157 | 
            -
            vendor/tmail-1.2.3/tmail/header.rb
         | 
| 158 | 
            -
            vendor/tmail-1.2.3/tmail/index.rb
         | 
| 159 | 
            -
            vendor/tmail-1.2.3/tmail/interface.rb
         | 
| 160 | 
            -
            vendor/tmail-1.2.3/tmail/loader.rb
         | 
| 161 | 
            -
            vendor/tmail-1.2.3/tmail/mail.rb
         | 
| 162 | 
            -
            vendor/tmail-1.2.3/tmail/mailbox.rb
         | 
| 163 | 
            -
            vendor/tmail-1.2.3/tmail/main.rb
         | 
| 164 | 
            -
            vendor/tmail-1.2.3/tmail/mbox.rb
         | 
| 165 | 
            -
            vendor/tmail-1.2.3/tmail/net.rb
         | 
| 166 | 
            -
            vendor/tmail-1.2.3/tmail/obsolete.rb
         | 
| 167 | 
            -
            vendor/tmail-1.2.3/tmail/parser.rb
         | 
| 168 | 
            -
            vendor/tmail-1.2.3/tmail/port.rb
         | 
| 169 | 
            -
            vendor/tmail-1.2.3/tmail/quoting.rb
         | 
| 170 | 
            -
            vendor/tmail-1.2.3/tmail/require_arch.rb
         | 
| 171 | 
            -
            vendor/tmail-1.2.3/tmail/scanner.rb
         | 
| 172 | 
            -
            vendor/tmail-1.2.3/tmail/scanner_r.rb
         | 
| 173 | 
            -
            vendor/tmail-1.2.3/tmail/stringio.rb
         | 
| 174 | 
            -
            vendor/tmail-1.2.3/tmail/utils.rb
         | 
| 175 | 
            -
            vendor/tmail-1.2.3/tmail/version.rb
         | 
| 176 | 
            -
            vendor/tmail.rb
         | 
| @@ -1,85 +0,0 @@ | |
| 1 | 
            -
            require DaemonKit.framework_root + '/vendor/tmail'
         | 
| 2 | 
            -
            require 'net/smtp'
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            module DaemonKit
         | 
| 5 | 
            -
              module ErrorHandlers
         | 
| 6 | 
            -
                # Send an email notification of the exception via SMTP.
         | 
| 7 | 
            -
                class Mail < Base
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                  # SMTP hostname
         | 
| 10 | 
            -
                  @host = 'localhost'
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                  # SMTP port
         | 
| 13 | 
            -
                  @port = 25
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                  # Recipients of the notification
         | 
| 16 | 
            -
                  @recipients = []
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                  # Subject prefix
         | 
| 19 | 
            -
                  @prefix = '[DAEMON-KIT]'
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                  # Sender address
         | 
| 22 | 
            -
                  @sender = 'daemon-kit'
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                  # SMTP username
         | 
| 25 | 
            -
                  @username = nil
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                  # SMTP password
         | 
| 28 | 
            -
                  @password = nil
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                  # Authentication mechanism (:plain, :login, or :cram_md5)
         | 
| 31 | 
            -
                  @authentication = nil
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                  # Use TLS?
         | 
| 34 | 
            -
                  @tls = false
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                  # Domain used when talking to SMTP server
         | 
| 37 | 
            -
                  @domain = 'localhost.localdomain'
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                  class << self
         | 
| 40 | 
            -
                    attr_accessor :host, :port, :recipients, :prefix, :sender, :username,
         | 
| 41 | 
            -
                    :password, :authentication, :tls, :domain
         | 
| 42 | 
            -
                  end
         | 
| 43 | 
            -
             | 
| 44 | 
            -
                  [ :host, :port, :recipients, :prefix, :sender, :username, :password,
         | 
| 45 | 
            -
                    :authentication, :tls, :domain ].each do |cm|
         | 
| 46 | 
            -
                    class_eval(<<-EOM, __FILE__, __LINE__)
         | 
| 47 | 
            -
                      def #{cm}=( val )
         | 
| 48 | 
            -
                        self.class.#{cm} = val
         | 
| 49 | 
            -
                      end
         | 
| 50 | 
            -
                    EOM
         | 
| 51 | 
            -
                  end
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                  def handle_exception( exception )
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                    mail = TMail::Mail.new
         | 
| 56 | 
            -
                    mail.to = self.class.recipients
         | 
| 57 | 
            -
                    mail.from = self.class.sender
         | 
| 58 | 
            -
                    mail.subject = "#{self.class.prefix} #{exception.message}"
         | 
| 59 | 
            -
                    mail.set_content_type 'text', 'plain'
         | 
| 60 | 
            -
                    mail.mime_version = '1.0'
         | 
| 61 | 
            -
                    mail.date = Time.now
         | 
| 62 | 
            -
             | 
| 63 | 
            -
                    mail.body = <<EOF
         | 
| 64 | 
            -
            DaemonKit caught an exception inside #{DaemonKit.configuration.daemon_name}.
         | 
| 65 | 
            -
             | 
| 66 | 
            -
            Message: #{exception.message}
         | 
| 67 | 
            -
            Backtrace:
         | 
| 68 | 
            -
            #{exception.backtrace.join("\n  ")}
         | 
| 69 | 
            -
             | 
| 70 | 
            -
            Environment: #{ENV.inspect}
         | 
| 71 | 
            -
            EOF
         | 
| 72 | 
            -
                    begin
         | 
| 73 | 
            -
                      smtp = Net::SMTP.new( self.class.host, self.class.port )
         | 
| 74 | 
            -
                      smtp.enable_starttls_auto if self.class.tls && smtp.respond_to?(:enable_starttls_auto)
         | 
| 75 | 
            -
                      smtp.start( self.class.domain, self.class.username, self.class.password,
         | 
| 76 | 
            -
                                  self.class.authentication ) do |smtp|
         | 
| 77 | 
            -
                        smtp.sendmail( mail.to_s, mail.from, mail.to )
         | 
| 78 | 
            -
                      end
         | 
| 79 | 
            -
                    rescue => e
         | 
| 80 | 
            -
                      DaemonKit.logger.error "Failed to send exception mail: #{e.message}" if DaemonKit.logger
         | 
| 81 | 
            -
                    end
         | 
| 82 | 
            -
                  end
         | 
| 83 | 
            -
                end
         | 
| 84 | 
            -
              end
         | 
| 85 | 
            -
            end
         | 
    
        data/vendor/tmail-1.2.3/tmail.rb
    DELETED
    
    
| @@ -1,426 +0,0 @@ | |
| 1 | 
            -
            =begin rdoc
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            = Address handling class
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            =end
         | 
| 6 | 
            -
            #--
         | 
| 7 | 
            -
            # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
         | 
| 8 | 
            -
            #
         | 
| 9 | 
            -
            # Permission is hereby granted, free of charge, to any person obtaining
         | 
| 10 | 
            -
            # a copy of this software and associated documentation files (the
         | 
| 11 | 
            -
            # "Software"), to deal in the Software without restriction, including
         | 
| 12 | 
            -
            # without limitation the rights to use, copy, modify, merge, publish,
         | 
| 13 | 
            -
            # distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 14 | 
            -
            # permit persons to whom the Software is furnished to do so, subject to
         | 
| 15 | 
            -
            # the following conditions:
         | 
| 16 | 
            -
            #
         | 
| 17 | 
            -
            # The above copyright notice and this permission notice shall be
         | 
| 18 | 
            -
            # included in all copies or substantial portions of the Software.
         | 
| 19 | 
            -
            #
         | 
| 20 | 
            -
            # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 21 | 
            -
            # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 22 | 
            -
            # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 23 | 
            -
            # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 24 | 
            -
            # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 25 | 
            -
            # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 26 | 
            -
            # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
| 27 | 
            -
            #
         | 
| 28 | 
            -
            # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
         | 
| 29 | 
            -
            # with permission of Minero Aoki.
         | 
| 30 | 
            -
            #++
         | 
| 31 | 
            -
             | 
| 32 | 
            -
            require 'tmail/encode'
         | 
| 33 | 
            -
            require 'tmail/parser'
         | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
            module TMail
         | 
| 37 | 
            -
             | 
| 38 | 
            -
              # = Class Address
         | 
| 39 | 
            -
              # 
         | 
| 40 | 
            -
              # Provides a complete handling library for email addresses. Can parse a string of an
         | 
| 41 | 
            -
              # address directly or take in preformatted addresses themselves.  Allows you to add
         | 
| 42 | 
            -
              # and remove phrases from the front of the address and provides a compare function for
         | 
| 43 | 
            -
              # email addresses.
         | 
| 44 | 
            -
              # 
         | 
| 45 | 
            -
              # == Parsing and Handling a Valid Address:
         | 
| 46 | 
            -
              # 
         | 
| 47 | 
            -
              # Just pass the email address in as a string to Address.parse:
         | 
| 48 | 
            -
              # 
         | 
| 49 | 
            -
              #  email = TMail::Address.parse('Mikel Lindsaar <mikel@lindsaar.net>)
         | 
| 50 | 
            -
              #  #=> #<TMail::Address mikel@lindsaar.net>
         | 
| 51 | 
            -
              #  email.address
         | 
| 52 | 
            -
              #  #=> "mikel@lindsaar.net"
         | 
| 53 | 
            -
              #  email.local
         | 
| 54 | 
            -
              #  #=> "mikel"
         | 
| 55 | 
            -
              #  email.domain
         | 
| 56 | 
            -
              #  #=> "lindsaar.net"
         | 
| 57 | 
            -
              #  email.name             # Aliased as phrase as well
         | 
| 58 | 
            -
              #  #=> "Mikel Lindsaar"
         | 
| 59 | 
            -
              # 
         | 
| 60 | 
            -
              # == Detecting an Invalid Address
         | 
| 61 | 
            -
              # 
         | 
| 62 | 
            -
              # If you want to check the syntactical validity of an email address, just pass it to
         | 
| 63 | 
            -
              # Address.parse and catch any SyntaxError:
         | 
| 64 | 
            -
              # 
         | 
| 65 | 
            -
              #  begin
         | 
| 66 | 
            -
              #    TMail::Mail.parse("mikel   2@@@@@ me .com")
         | 
| 67 | 
            -
              #  rescue TMail::SyntaxError
         | 
| 68 | 
            -
              #    puts("Invalid Email Address Detected")
         | 
| 69 | 
            -
              #  else
         | 
| 70 | 
            -
              #    puts("Address is valid")
         | 
| 71 | 
            -
              #  end
         | 
| 72 | 
            -
              #  #=> "Invalid Email Address Detected"
         | 
| 73 | 
            -
              class Address
         | 
| 74 | 
            -
             | 
| 75 | 
            -
                include TextUtils #:nodoc:
         | 
| 76 | 
            -
                
         | 
| 77 | 
            -
                # Sometimes you need to parse an address, TMail can do it for you and provide you with
         | 
| 78 | 
            -
                # a fairly robust method of detecting a valid address.
         | 
| 79 | 
            -
                # 
         | 
| 80 | 
            -
                # Takes in a string, returns a TMail::Address object.
         | 
| 81 | 
            -
                # 
         | 
| 82 | 
            -
                # Raises a TMail::SyntaxError on invalid email format
         | 
| 83 | 
            -
                def Address.parse( str )
         | 
| 84 | 
            -
                  Parser.parse :ADDRESS, special_quote_address(str)
         | 
| 85 | 
            -
                end
         | 
| 86 | 
            -
                
         | 
| 87 | 
            -
                def Address.special_quote_address(str) #:nodoc:
         | 
| 88 | 
            -
                  # Takes a string which is an address and adds quotation marks to special
         | 
| 89 | 
            -
                  # edge case methods that the RACC parser can not handle.
         | 
| 90 | 
            -
                  #
         | 
| 91 | 
            -
                  # Right now just handles two edge cases:
         | 
| 92 | 
            -
                  #
         | 
| 93 | 
            -
                  # Full stop as the last character of the display name:
         | 
| 94 | 
            -
                  #   Mikel L. <mikel@me.com>
         | 
| 95 | 
            -
                  # Returns:
         | 
| 96 | 
            -
                  #   "Mikel L." <mikel@me.com>
         | 
| 97 | 
            -
                  #
         | 
| 98 | 
            -
                  # Unquoted @ symbol in the display name:
         | 
| 99 | 
            -
                  #   mikel@me.com <mikel@me.com>
         | 
| 100 | 
            -
                  # Returns:
         | 
| 101 | 
            -
                  #   "mikel@me.com" <mikel@me.com>
         | 
| 102 | 
            -
                  #
         | 
| 103 | 
            -
                  # Any other address not matching these patterns just gets returned as is. 
         | 
| 104 | 
            -
                  case
         | 
| 105 | 
            -
                  # This handles the missing "" in an older version of Apple Mail.app
         | 
| 106 | 
            -
                  # around the display name when the display name contains a '@'
         | 
| 107 | 
            -
                  # like 'mikel@me.com <mikel@me.com>'
         | 
| 108 | 
            -
                  # Just quotes it to: '"mikel@me.com" <mikel@me.com>'
         | 
| 109 | 
            -
                  when str =~ /\A([^"].+@.+[^"])\s(<.*?>)\Z/
         | 
| 110 | 
            -
                    return "\"#{$1}\" #{$2}"
         | 
| 111 | 
            -
                  # This handles cases where 'Mikel A. <mikel@me.com>' which is a trailing
         | 
| 112 | 
            -
                  # full stop before the address section.  Just quotes it to
         | 
| 113 | 
            -
                  # '"Mikel A. <mikel@me.com>"
         | 
| 114 | 
            -
                  when str =~ /\A(.*?\.)\s(<.*?>)\Z/
         | 
| 115 | 
            -
                    return "\"#{$1}\" #{$2}"
         | 
| 116 | 
            -
                  else
         | 
| 117 | 
            -
                    str
         | 
| 118 | 
            -
                  end
         | 
| 119 | 
            -
                end
         | 
| 120 | 
            -
             | 
| 121 | 
            -
                def address_group? #:nodoc:
         | 
| 122 | 
            -
                  false
         | 
| 123 | 
            -
                end
         | 
| 124 | 
            -
             | 
| 125 | 
            -
                # Address.new(local, domain)
         | 
| 126 | 
            -
                # 
         | 
| 127 | 
            -
                # Accepts:
         | 
| 128 | 
            -
                # 
         | 
| 129 | 
            -
                # * local - Left of the at symbol
         | 
| 130 | 
            -
                # 
         | 
| 131 | 
            -
                # * domain - Array of the domain split at the periods.
         | 
| 132 | 
            -
                # 
         | 
| 133 | 
            -
                # For example:
         | 
| 134 | 
            -
                # 
         | 
| 135 | 
            -
                #  Address.new("mikel", ["lindsaar", "net"])
         | 
| 136 | 
            -
                #  #=> "#<TMail::Address mikel@lindsaar.net>"
         | 
| 137 | 
            -
                def initialize( local, domain )
         | 
| 138 | 
            -
                  if domain
         | 
| 139 | 
            -
                    domain.each do |s|
         | 
| 140 | 
            -
                      raise SyntaxError, 'empty word in domain' if s.empty?
         | 
| 141 | 
            -
                    end
         | 
| 142 | 
            -
                  end
         | 
| 143 | 
            -
                  
         | 
| 144 | 
            -
                  # This is to catch an unquoted "@" symbol in the local part of the
         | 
| 145 | 
            -
                  # address.  Handles addresses like <"@"@me.com> and makes sure they
         | 
| 146 | 
            -
                  # stay like <"@"@me.com> (previously were becoming <@@me.com>)
         | 
| 147 | 
            -
                  if local && (local.join == '@' || local.join =~ /\A[^"].*?@.*?[^"]\Z/)
         | 
| 148 | 
            -
                    @local = "\"#{local.join}\""
         | 
| 149 | 
            -
                  else
         | 
| 150 | 
            -
                    @local = local
         | 
| 151 | 
            -
                  end
         | 
| 152 | 
            -
             | 
| 153 | 
            -
                  @domain = domain
         | 
| 154 | 
            -
                  @name   = nil
         | 
| 155 | 
            -
                  @routes = []
         | 
| 156 | 
            -
                end
         | 
| 157 | 
            -
             | 
| 158 | 
            -
                # Provides the name or 'phrase' of the email address.
         | 
| 159 | 
            -
                # 
         | 
| 160 | 
            -
                # For Example:
         | 
| 161 | 
            -
                # 
         | 
| 162 | 
            -
                #  email = TMail::Address.parse("Mikel Lindsaar <mikel@lindsaar.net>")
         | 
| 163 | 
            -
                #  email.name
         | 
| 164 | 
            -
                #  #=> "Mikel Lindsaar"
         | 
| 165 | 
            -
                def name
         | 
| 166 | 
            -
                  @name
         | 
| 167 | 
            -
                end
         | 
| 168 | 
            -
             | 
| 169 | 
            -
                # Setter method for the name or phrase of the email
         | 
| 170 | 
            -
                # 
         | 
| 171 | 
            -
                # For Example:
         | 
| 172 | 
            -
                # 
         | 
| 173 | 
            -
                #  email = TMail::Address.parse("mikel@lindsaar.net")
         | 
| 174 | 
            -
                #  email.name
         | 
| 175 | 
            -
                #  #=> nil
         | 
| 176 | 
            -
                #  email.name = "Mikel Lindsaar"
         | 
| 177 | 
            -
                #  email.to_s
         | 
| 178 | 
            -
                #  #=> "Mikel Lindsaar <mikel@me.com>"
         | 
| 179 | 
            -
                def name=( str )
         | 
| 180 | 
            -
                  @name = str
         | 
| 181 | 
            -
                  @name = nil if str and str.empty?
         | 
| 182 | 
            -
                end
         | 
| 183 | 
            -
             | 
| 184 | 
            -
                #:stopdoc:
         | 
| 185 | 
            -
                alias phrase  name
         | 
| 186 | 
            -
                alias phrase= name=
         | 
| 187 | 
            -
                #:startdoc:
         | 
| 188 | 
            -
                
         | 
| 189 | 
            -
                # This is still here from RFC 822, and is now obsolete per RFC2822 Section 4.
         | 
| 190 | 
            -
                # 
         | 
| 191 | 
            -
                # "When interpreting addresses, the route portion SHOULD be ignored."
         | 
| 192 | 
            -
                # 
         | 
| 193 | 
            -
                # It is still here, so you can access it.
         | 
| 194 | 
            -
                # 
         | 
| 195 | 
            -
                # Routes return the route portion at the front of the email address, if any.
         | 
| 196 | 
            -
                # 
         | 
| 197 | 
            -
                # For Example:
         | 
| 198 | 
            -
                #  email = TMail::Address.parse( "<@sa,@another:Mikel@me.com>")
         | 
| 199 | 
            -
                #  => #<TMail::Address Mikel@me.com>
         | 
| 200 | 
            -
                #  email.to_s
         | 
| 201 | 
            -
                #  => "<@sa,@another:Mikel@me.com>"
         | 
| 202 | 
            -
                #  email.routes
         | 
| 203 | 
            -
                #  => ["sa", "another"]
         | 
| 204 | 
            -
                def routes
         | 
| 205 | 
            -
                  @routes
         | 
| 206 | 
            -
                end
         | 
| 207 | 
            -
                
         | 
| 208 | 
            -
                def inspect #:nodoc:
         | 
| 209 | 
            -
                  "#<#{self.class} #{address()}>"
         | 
| 210 | 
            -
                end
         | 
| 211 | 
            -
             | 
| 212 | 
            -
                # Returns the local part of the email address
         | 
| 213 | 
            -
                # 
         | 
| 214 | 
            -
                # For Example:
         | 
| 215 | 
            -
                # 
         | 
| 216 | 
            -
                #  email = TMail::Address.parse("mikel@lindsaar.net")
         | 
| 217 | 
            -
                #  email.local
         | 
| 218 | 
            -
                #  #=> "mikel"
         | 
| 219 | 
            -
                def local
         | 
| 220 | 
            -
                  return nil unless @local
         | 
| 221 | 
            -
                  return '""' if @local.size == 1 and @local[0].empty?
         | 
| 222 | 
            -
                  # Check to see if it is an array before trying to map it
         | 
| 223 | 
            -
                  if @local.respond_to?(:map)
         | 
| 224 | 
            -
                    @local.map {|i| quote_atom(i) }.join('.')
         | 
| 225 | 
            -
                  else
         | 
| 226 | 
            -
                    quote_atom(@local)
         | 
| 227 | 
            -
                  end
         | 
| 228 | 
            -
                end
         | 
| 229 | 
            -
             | 
| 230 | 
            -
                # Returns the domain part of the email address
         | 
| 231 | 
            -
                # 
         | 
| 232 | 
            -
                # For Example:
         | 
| 233 | 
            -
                # 
         | 
| 234 | 
            -
                #  email = TMail::Address.parse("mikel@lindsaar.net")
         | 
| 235 | 
            -
                #  email.local
         | 
| 236 | 
            -
                #  #=> "lindsaar.net"
         | 
| 237 | 
            -
                def domain
         | 
| 238 | 
            -
                  return nil unless @domain
         | 
| 239 | 
            -
                  join_domain(@domain)
         | 
| 240 | 
            -
                end
         | 
| 241 | 
            -
             | 
| 242 | 
            -
                # Returns the full specific address itself
         | 
| 243 | 
            -
                # 
         | 
| 244 | 
            -
                # For Example:
         | 
| 245 | 
            -
                # 
         | 
| 246 | 
            -
                #  email = TMail::Address.parse("mikel@lindsaar.net")
         | 
| 247 | 
            -
                #  email.address
         | 
| 248 | 
            -
                #  #=> "mikel@lindsaar.net"
         | 
| 249 | 
            -
                def spec
         | 
| 250 | 
            -
                  s = self.local
         | 
| 251 | 
            -
                  d = self.domain
         | 
| 252 | 
            -
                  if s and d
         | 
| 253 | 
            -
                    s + '@' + d
         | 
| 254 | 
            -
                  else
         | 
| 255 | 
            -
                    s
         | 
| 256 | 
            -
                  end
         | 
| 257 | 
            -
                end
         | 
| 258 | 
            -
             | 
| 259 | 
            -
                alias address spec
         | 
| 260 | 
            -
             | 
| 261 | 
            -
                # Provides == function to the email.  Only checks the actual address
         | 
| 262 | 
            -
                # and ignores the name/phrase component
         | 
| 263 | 
            -
                # 
         | 
| 264 | 
            -
                # For Example
         | 
| 265 | 
            -
                # 
         | 
| 266 | 
            -
                #  addr1 = TMail::Address.parse("My Address <mikel@lindsaar.net>")
         | 
| 267 | 
            -
                #  #=> "#<TMail::Address mikel@lindsaar.net>"
         | 
| 268 | 
            -
                #  addr2 = TMail::Address.parse("Another <mikel@lindsaar.net>")
         | 
| 269 | 
            -
                #  #=> "#<TMail::Address mikel@lindsaar.net>"
         | 
| 270 | 
            -
                #  addr1 == addr2
         | 
| 271 | 
            -
                #  #=> true
         | 
| 272 | 
            -
                def ==( other )
         | 
| 273 | 
            -
                  other.respond_to? :spec and self.spec == other.spec
         | 
| 274 | 
            -
                end
         | 
| 275 | 
            -
             | 
| 276 | 
            -
                alias eql? ==
         | 
| 277 | 
            -
             | 
| 278 | 
            -
                # Provides a unique hash value for this record against the local and domain
         | 
| 279 | 
            -
                # parts, ignores the name/phrase value
         | 
| 280 | 
            -
                # 
         | 
| 281 | 
            -
                #  email = TMail::Address.parse("mikel@lindsaar.net")
         | 
| 282 | 
            -
                #  email.hash
         | 
| 283 | 
            -
                #  #=> 18767598
         | 
| 284 | 
            -
                def hash
         | 
| 285 | 
            -
                  @local.hash ^ @domain.hash
         | 
| 286 | 
            -
                end
         | 
| 287 | 
            -
             | 
| 288 | 
            -
                # Duplicates a TMail::Address object returning the duplicate
         | 
| 289 | 
            -
                # 
         | 
| 290 | 
            -
                #  addr1 = TMail::Address.parse("mikel@lindsaar.net")
         | 
| 291 | 
            -
                #  addr2 = addr1.dup
         | 
| 292 | 
            -
                #  addr1.id == addr2.id
         | 
| 293 | 
            -
                #  #=> false
         | 
| 294 | 
            -
                def dup
         | 
| 295 | 
            -
                  obj = self.class.new(@local.dup, @domain.dup)
         | 
| 296 | 
            -
                  obj.name = @name.dup if @name
         | 
| 297 | 
            -
                  obj.routes.replace @routes
         | 
| 298 | 
            -
                  obj
         | 
| 299 | 
            -
                end
         | 
| 300 | 
            -
             | 
| 301 | 
            -
                include StrategyInterface #:nodoc:
         | 
| 302 | 
            -
             | 
| 303 | 
            -
                def accept( strategy, dummy1 = nil, dummy2 = nil ) #:nodoc:
         | 
| 304 | 
            -
                  unless @local
         | 
| 305 | 
            -
                    strategy.meta '<>'   # empty return-path
         | 
| 306 | 
            -
                    return
         | 
| 307 | 
            -
                  end
         | 
| 308 | 
            -
             | 
| 309 | 
            -
                  spec_p = (not @name and @routes.empty?)
         | 
| 310 | 
            -
                  if @name
         | 
| 311 | 
            -
                    strategy.phrase @name
         | 
| 312 | 
            -
                    strategy.space
         | 
| 313 | 
            -
                  end
         | 
| 314 | 
            -
                  tmp = spec_p ? '' : '<'
         | 
| 315 | 
            -
                  unless @routes.empty?
         | 
| 316 | 
            -
                    tmp << @routes.map {|i| '@' + i }.join(',') << ':'
         | 
| 317 | 
            -
                  end
         | 
| 318 | 
            -
                  tmp << self.spec
         | 
| 319 | 
            -
                  tmp << '>' unless spec_p
         | 
| 320 | 
            -
                  strategy.meta tmp
         | 
| 321 | 
            -
                  strategy.lwsp ''
         | 
| 322 | 
            -
                end
         | 
| 323 | 
            -
             | 
| 324 | 
            -
              end
         | 
| 325 | 
            -
             | 
| 326 | 
            -
             | 
| 327 | 
            -
              class AddressGroup
         | 
| 328 | 
            -
             | 
| 329 | 
            -
                include Enumerable
         | 
| 330 | 
            -
             | 
| 331 | 
            -
                def address_group?
         | 
| 332 | 
            -
                  true
         | 
| 333 | 
            -
                end
         | 
| 334 | 
            -
             | 
| 335 | 
            -
                def initialize( name, addrs )
         | 
| 336 | 
            -
                  @name = name
         | 
| 337 | 
            -
                  @addresses = addrs
         | 
| 338 | 
            -
                end
         | 
| 339 | 
            -
             | 
| 340 | 
            -
                attr_reader :name
         | 
| 341 | 
            -
                
         | 
| 342 | 
            -
                def ==( other )
         | 
| 343 | 
            -
                  other.respond_to? :to_a and @addresses == other.to_a
         | 
| 344 | 
            -
                end
         | 
| 345 | 
            -
             | 
| 346 | 
            -
                alias eql? ==
         | 
| 347 | 
            -
             | 
| 348 | 
            -
                def hash
         | 
| 349 | 
            -
                  map {|i| i.hash }.hash
         | 
| 350 | 
            -
                end
         | 
| 351 | 
            -
             | 
| 352 | 
            -
                def []( idx )
         | 
| 353 | 
            -
                  @addresses[idx]
         | 
| 354 | 
            -
                end
         | 
| 355 | 
            -
             | 
| 356 | 
            -
                def size
         | 
| 357 | 
            -
                  @addresses.size
         | 
| 358 | 
            -
                end
         | 
| 359 | 
            -
             | 
| 360 | 
            -
                def empty?
         | 
| 361 | 
            -
                  @addresses.empty?
         | 
| 362 | 
            -
                end
         | 
| 363 | 
            -
             | 
| 364 | 
            -
                def each( &block )
         | 
| 365 | 
            -
                  @addresses.each(&block)
         | 
| 366 | 
            -
                end
         | 
| 367 | 
            -
             | 
| 368 | 
            -
                def to_a
         | 
| 369 | 
            -
                  @addresses.dup
         | 
| 370 | 
            -
                end
         | 
| 371 | 
            -
             | 
| 372 | 
            -
                alias to_ary to_a
         | 
| 373 | 
            -
             | 
| 374 | 
            -
                def include?( a )
         | 
| 375 | 
            -
                  @addresses.include? a
         | 
| 376 | 
            -
                end
         | 
| 377 | 
            -
             | 
| 378 | 
            -
                def flatten
         | 
| 379 | 
            -
                  set = []
         | 
| 380 | 
            -
                  @addresses.each do |a|
         | 
| 381 | 
            -
                    if a.respond_to? :flatten
         | 
| 382 | 
            -
                      set.concat a.flatten
         | 
| 383 | 
            -
                    else
         | 
| 384 | 
            -
                      set.push a
         | 
| 385 | 
            -
                    end
         | 
| 386 | 
            -
                  end
         | 
| 387 | 
            -
                  set
         | 
| 388 | 
            -
                end
         | 
| 389 | 
            -
             | 
| 390 | 
            -
                def each_address( &block )
         | 
| 391 | 
            -
                  flatten.each(&block)
         | 
| 392 | 
            -
                end
         | 
| 393 | 
            -
             | 
| 394 | 
            -
                def add( a )
         | 
| 395 | 
            -
                  @addresses.push a
         | 
| 396 | 
            -
                end
         | 
| 397 | 
            -
             | 
| 398 | 
            -
                alias push add
         | 
| 399 | 
            -
                
         | 
| 400 | 
            -
                def delete( a )
         | 
| 401 | 
            -
                  @addresses.delete a
         | 
| 402 | 
            -
                end
         | 
| 403 | 
            -
             | 
| 404 | 
            -
                include StrategyInterface
         | 
| 405 | 
            -
             | 
| 406 | 
            -
                def accept( strategy, dummy1 = nil, dummy2 = nil )
         | 
| 407 | 
            -
                  strategy.phrase @name
         | 
| 408 | 
            -
                  strategy.meta ':'
         | 
| 409 | 
            -
                  strategy.space
         | 
| 410 | 
            -
                  first = true
         | 
| 411 | 
            -
                  each do |mbox|
         | 
| 412 | 
            -
                    if first
         | 
| 413 | 
            -
                      first = false
         | 
| 414 | 
            -
                    else
         | 
| 415 | 
            -
                      strategy.meta ','
         | 
| 416 | 
            -
                    end
         | 
| 417 | 
            -
                    strategy.space
         | 
| 418 | 
            -
                    mbox.accept strategy
         | 
| 419 | 
            -
                  end
         | 
| 420 | 
            -
                  strategy.meta ';'
         | 
| 421 | 
            -
                  strategy.lwsp ''
         | 
| 422 | 
            -
                end
         | 
| 423 | 
            -
             | 
| 424 | 
            -
              end
         | 
| 425 | 
            -
             | 
| 426 | 
            -
            end   # module TMail
         |