entp-astrotrain 0.2.0
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/.gitignore +26 -0
 - data/LICENSE +20 -0
 - data/README +47 -0
 - data/Rakefile +145 -0
 - data/VERSION +1 -0
 - data/astrotrain.gemspec +96 -0
 - data/config/sample.rb +12 -0
 - data/lib/astrotrain/api.rb +53 -0
 - data/lib/astrotrain/logged_mail.rb +41 -0
 - data/lib/astrotrain/mapping/http_post.rb +18 -0
 - data/lib/astrotrain/mapping/jabber.rb +23 -0
 - data/lib/astrotrain/mapping/transport.rb +55 -0
 - data/lib/astrotrain/mapping.rb +157 -0
 - data/lib/astrotrain/message.rb +313 -0
 - data/lib/astrotrain/tmail.rb +48 -0
 - data/lib/astrotrain.rb +55 -0
 - data/lib/vendor/rest-client/README.rdoc +104 -0
 - data/lib/vendor/rest-client/Rakefile +84 -0
 - data/lib/vendor/rest-client/bin/restclient +65 -0
 - data/lib/vendor/rest-client/foo.diff +66 -0
 - data/lib/vendor/rest-client/lib/rest_client/net_http_ext.rb +21 -0
 - data/lib/vendor/rest-client/lib/rest_client/payload.rb +185 -0
 - data/lib/vendor/rest-client/lib/rest_client/request_errors.rb +75 -0
 - data/lib/vendor/rest-client/lib/rest_client/resource.rb +103 -0
 - data/lib/vendor/rest-client/lib/rest_client.rb +189 -0
 - data/lib/vendor/rest-client/rest-client.gemspec +18 -0
 - data/lib/vendor/rest-client/spec/base.rb +5 -0
 - data/lib/vendor/rest-client/spec/master_shake.jpg +0 -0
 - data/lib/vendor/rest-client/spec/payload_spec.rb +71 -0
 - data/lib/vendor/rest-client/spec/request_errors_spec.rb +44 -0
 - data/lib/vendor/rest-client/spec/resource_spec.rb +52 -0
 - data/lib/vendor/rest-client/spec/rest_client_spec.rb +219 -0
 - data/tasks/doc.thor +149 -0
 - data/tasks/merb.thor +2020 -0
 - data/test/api_test.rb +28 -0
 - data/test/fixtures/apple_multipart.txt +100 -0
 - data/test/fixtures/basic.txt +14 -0
 - data/test/fixtures/custom.txt +15 -0
 - data/test/fixtures/fwd.txt +0 -0
 - data/test/fixtures/gb2312_encoding.txt +16 -0
 - data/test/fixtures/gb2312_encoding_invalid.txt +15 -0
 - data/test/fixtures/html.txt +16 -0
 - data/test/fixtures/iso-8859-1.txt +13 -0
 - data/test/fixtures/mapped.txt +13 -0
 - data/test/fixtures/multipart.txt +213 -0
 - data/test/fixtures/multipart2.txt +213 -0
 - data/test/fixtures/multiple.txt +13 -0
 - data/test/fixtures/multiple_delivered_to.txt +14 -0
 - data/test/fixtures/multiple_with_body_recipients.txt +15 -0
 - data/test/fixtures/reply.txt +16 -0
 - data/test/fixtures/utf-8.txt +13 -0
 - data/test/logged_mail_test.rb +63 -0
 - data/test/mapping_test.rb +129 -0
 - data/test/message_test.rb +424 -0
 - data/test/test_helper.rb +54 -0
 - data/test/transport_test.rb +111 -0
 - metadata +115 -0
 
| 
         @@ -0,0 +1,424 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.join(File.dirname(__FILE__), "test_helper")
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class Astrotrain::MessageTest < Astrotrain::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              describe "mapping" do
         
     | 
| 
      
 5 
     | 
    
         
            +
                describe "against default domain" do
         
     | 
| 
      
 6 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 7 
     | 
    
         
            +
                    Astrotrain::Mapping.transaction do
         
     | 
| 
      
 8 
     | 
    
         
            +
                      Astrotrain::LoggedMail.all.destroy!
         
     | 
| 
      
 9 
     | 
    
         
            +
                      Astrotrain::Mapping.all.destroy!
         
     | 
| 
      
 10 
     | 
    
         
            +
                      @mapping  = Astrotrain::Mapping.create!(:email_user => 'xyz')
         
     | 
| 
      
 11 
     | 
    
         
            +
                      @mapping2 = Astrotrain::Mapping.create!(:email_user => 'xyz',  :email_domain => 'sample.com')
         
     | 
| 
      
 12 
     | 
    
         
            +
                    end
         
     | 
| 
      
 13 
     | 
    
         
            +
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  describe "without mapping" do
         
     | 
| 
      
 16 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 17 
     | 
    
         
            +
                      Astrotrain::LoggedMail.all.destroy!
         
     | 
| 
      
 18 
     | 
    
         
            +
                    end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                    it "doesn't log message" do
         
     | 
| 
      
 21 
     | 
    
         
            +
                      @msg = Astrotrain::Message.receive(mail(:basic))
         
     | 
| 
      
 22 
     | 
    
         
            +
                      @log = Astrotrain::LoggedMail.first
         
     | 
| 
      
 23 
     | 
    
         
            +
                      assert_nil @log
         
     | 
| 
      
 24 
     | 
    
         
            +
                    end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                    it "logs message if Astrotrain::LoggedMail.log_processed" do
         
     | 
| 
      
 27 
     | 
    
         
            +
                      Astrotrain::LoggedMail.log_processed = true
         
     | 
| 
      
 28 
     | 
    
         
            +
                      @msg = Astrotrain::Message.receive(mail(:basic))
         
     | 
| 
      
 29 
     | 
    
         
            +
                      @log = Astrotrain::LoggedMail.first
         
     | 
| 
      
 30 
     | 
    
         
            +
                      assert @log
         
     | 
| 
      
 31 
     | 
    
         
            +
                      assert @log.error_message.blank?
         
     | 
| 
      
 32 
     | 
    
         
            +
                    end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                    it "calls pre_mapping callback" do
         
     | 
| 
      
 35 
     | 
    
         
            +
                      Astrotrain::LoggedMail.log_processed = true
         
     | 
| 
      
 36 
     | 
    
         
            +
                      callback_msg = nil
         
     | 
| 
      
 37 
     | 
    
         
            +
                      Astrotrain.callback(:pre_mapping) do |message|
         
     | 
| 
      
 38 
     | 
    
         
            +
                        callback_msg = message
         
     | 
| 
      
 39 
     | 
    
         
            +
                      end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                      @msg = Astrotrain::Message.receive(mail(:mapped))
         
     | 
| 
      
 42 
     | 
    
         
            +
                      assert_equal callback_msg, @msg
         
     | 
| 
      
 43 
     | 
    
         
            +
                    end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                    it "calls pre_processing callback" do
         
     | 
| 
      
 46 
     | 
    
         
            +
                      Astrotrain::LoggedMail.log_processed = true
         
     | 
| 
      
 47 
     | 
    
         
            +
                      callback_msg, callback_map = nil
         
     | 
| 
      
 48 
     | 
    
         
            +
                      Astrotrain.callback(:pre_processing) do |message, mapping|
         
     | 
| 
      
 49 
     | 
    
         
            +
                        callback_msg = message
         
     | 
| 
      
 50 
     | 
    
         
            +
                        callback_map = mapping
         
     | 
| 
      
 51 
     | 
    
         
            +
                      end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                      @msg = Astrotrain::Message.receive(mail(:mapped))
         
     | 
| 
      
 54 
     | 
    
         
            +
                      @log = Astrotrain::LoggedMail.first
         
     | 
| 
      
 55 
     | 
    
         
            +
                      assert_equal callback_msg, @msg
         
     | 
| 
      
 56 
     | 
    
         
            +
                      assert_equal callback_map, @log.mapping
         
     | 
| 
      
 57 
     | 
    
         
            +
                    end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                    it "calls post_processing callback" do
         
     | 
| 
      
 60 
     | 
    
         
            +
                      Astrotrain::LoggedMail.log_processed = true
         
     | 
| 
      
 61 
     | 
    
         
            +
                      callback_msg, callback_map, callback_log = nil
         
     | 
| 
      
 62 
     | 
    
         
            +
                      Astrotrain.callback(:post_processing) do |message, mapping, log|
         
     | 
| 
      
 63 
     | 
    
         
            +
                        callback_msg = message
         
     | 
| 
      
 64 
     | 
    
         
            +
                        callback_map = mapping
         
     | 
| 
      
 65 
     | 
    
         
            +
                        callback_log = log
         
     | 
| 
      
 66 
     | 
    
         
            +
                      end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                      @msg = Astrotrain::Message.receive(mail(:mapped))
         
     | 
| 
      
 69 
     | 
    
         
            +
                      @log = Astrotrain::LoggedMail.first
         
     | 
| 
      
 70 
     | 
    
         
            +
                      assert_equal callback_msg, @msg
         
     | 
| 
      
 71 
     | 
    
         
            +
                      assert_equal callback_map, @log.mapping
         
     | 
| 
      
 72 
     | 
    
         
            +
                      assert_equal callback_log, @log
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                    after do
         
     | 
| 
      
 76 
     | 
    
         
            +
                      Astrotrain::LoggedMail.log_processed = false
         
     | 
| 
      
 77 
     | 
    
         
            +
                      Astrotrain.clear_callbacks
         
     | 
| 
      
 78 
     | 
    
         
            +
                    end
         
     | 
| 
      
 79 
     | 
    
         
            +
                  end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                  describe "erroring" do
         
     | 
| 
      
 82 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 83 
     | 
    
         
            +
                      Astrotrain::LoggedMail.all.destroy!
         
     | 
| 
      
 84 
     | 
    
         
            +
                    end
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                    it "logs message without mappping" do
         
     | 
| 
      
 87 
     | 
    
         
            +
                      stub(Astrotrain::Mapping).match { raise RuntimeError }
         
     | 
| 
      
 88 
     | 
    
         
            +
                      @msg = Astrotrain::Message.receive(mail(:basic))
         
     | 
| 
      
 89 
     | 
    
         
            +
                      @log = Astrotrain::LoggedMail.first
         
     | 
| 
      
 90 
     | 
    
         
            +
                      assert @log
         
     | 
| 
      
 91 
     | 
    
         
            +
                      assert_nil @log.delivered_at
         
     | 
| 
      
 92 
     | 
    
         
            +
                      assert_match /RuntimeError/, @log.error_message
         
     | 
| 
      
 93 
     | 
    
         
            +
                      assert_nil @log.mapping
         
     | 
| 
      
 94 
     | 
    
         
            +
                    end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                    it "logs message with mappping" do
         
     | 
| 
      
 97 
     | 
    
         
            +
                      stub(Astrotrain::Mapping).match {@mapping}
         
     | 
| 
      
 98 
     | 
    
         
            +
                      stub(@mapping).process { raise RuntimeError }
         
     | 
| 
      
 99 
     | 
    
         
            +
                      @msg = Astrotrain::Message.receive(mail(:basic))
         
     | 
| 
      
 100 
     | 
    
         
            +
                      @log = Astrotrain::LoggedMail.first
         
     | 
| 
      
 101 
     | 
    
         
            +
                      assert @log
         
     | 
| 
      
 102 
     | 
    
         
            +
                      assert_nil @log.delivered_at
         
     | 
| 
      
 103 
     | 
    
         
            +
                      assert_match /RuntimeError/, @log.error_message
         
     | 
| 
      
 104 
     | 
    
         
            +
                      assert_equal @mapping, @log.mapping
         
     | 
| 
      
 105 
     | 
    
         
            +
                    end
         
     | 
| 
      
 106 
     | 
    
         
            +
                  end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                  describe "with mapping" do
         
     | 
| 
      
 109 
     | 
    
         
            +
                    before :all do
         
     | 
| 
      
 110 
     | 
    
         
            +
                      @msg = Astrotrain::Message.receive(mail(:mapped))
         
     | 
| 
      
 111 
     | 
    
         
            +
                      @log = Astrotrain::LoggedMail.first
         
     | 
| 
      
 112 
     | 
    
         
            +
                    end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                    it "does not log message" do
         
     | 
| 
      
 115 
     | 
    
         
            +
                      assert_nil @log
         
     | 
| 
      
 116 
     | 
    
         
            +
                    end
         
     | 
| 
      
 117 
     | 
    
         
            +
                  end
         
     | 
| 
      
 118 
     | 
    
         
            +
                end
         
     | 
| 
      
 119 
     | 
    
         
            +
              end
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
              describe "parsing" do
         
     | 
| 
      
 122 
     | 
    
         
            +
                before :all do
         
     | 
| 
      
 123 
     | 
    
         
            +
                  @body = "---------- Forwarded message ----------\nblah blah"
         
     | 
| 
      
 124 
     | 
    
         
            +
                end
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                describe "basic, single sender/recipient" do
         
     | 
| 
      
 127 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 128 
     | 
    
         
            +
                    @raw     = mail(:basic)
         
     | 
| 
      
 129 
     | 
    
         
            +
                    @message = Astrotrain::Message.parse(@raw)
         
     | 
| 
      
 130 
     | 
    
         
            +
                  end
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
                  it "parses TMail::Mail headers" do
         
     | 
| 
      
 133 
     | 
    
         
            +
                    expected = {'mime-version' => '1.0', 'content-type' => 'text/plain; charset=ISO-8859-1', 'to' => 'Processor <processor@astrotrain.com>',
         
     | 
| 
      
 134 
     | 
    
         
            +
                      'x-custom' => 'reply', 'content-transfer-encoding' => '7bit', 'content-disposition' => 'inline', 'message-id' => '<a16be7390810161014n52b603e9k1aa6bb803c6735aa@mail.gmail.com>'}
         
     | 
| 
      
 135 
     | 
    
         
            +
                    assert_equal expected, @message.headers
         
     | 
| 
      
 136 
     | 
    
         
            +
                  end
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
                  it "#parse parses TMail::Mail object from raw text" do
         
     | 
| 
      
 139 
     | 
    
         
            +
                    assert_kind_of TMail::Mail, @message.mail
         
     | 
| 
      
 140 
     | 
    
         
            +
                  end
         
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
                  it "recognizes Delivered-To and To: headers as recipients" do
         
     | 
| 
      
 143 
     | 
    
         
            +
                    assert_equal %w(processor@astrotrain.com), @message.recipients
         
     | 
| 
      
 144 
     | 
    
         
            +
                  end
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                  it "recognizes From: header as sender" do
         
     | 
| 
      
 147 
     | 
    
         
            +
                    assert_equal %(Bob <user@example.com>), @message.sender
         
     | 
| 
      
 148 
     | 
    
         
            +
                  end
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
                  it "recognizes Subject: header" do
         
     | 
| 
      
 151 
     | 
    
         
            +
                    assert_equal 'Fwd: blah blah', @message.subject
         
     | 
| 
      
 152 
     | 
    
         
            +
                  end
         
     | 
| 
      
 153 
     | 
    
         
            +
             
     | 
| 
      
 154 
     | 
    
         
            +
                  it "recognizes message body" do
         
     | 
| 
      
 155 
     | 
    
         
            +
                    assert_equal @body, @message.body
         
     | 
| 
      
 156 
     | 
    
         
            +
                  end
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
                  it "retains raw message" do
         
     | 
| 
      
 159 
     | 
    
         
            +
                    assert_equal @raw, @message.raw
         
     | 
| 
      
 160 
     | 
    
         
            +
                  end
         
     | 
| 
      
 161 
     | 
    
         
            +
                end
         
     | 
| 
      
 162 
     | 
    
         
            +
                
         
     | 
| 
      
 163 
     | 
    
         
            +
                describe "iso 8859 1 encoded headers" do
         
     | 
| 
      
 164 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 165 
     | 
    
         
            +
                    @raw     = mail("iso-8859-1")
         
     | 
| 
      
 166 
     | 
    
         
            +
                    @message = Astrotrain::Message.parse(@raw)
         
     | 
| 
      
 167 
     | 
    
         
            +
                  end
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
      
 169 
     | 
    
         
            +
                  it "recognizes From: header with strange encoding" do
         
     | 
| 
      
 170 
     | 
    
         
            +
                    assert_equal %(Matthéw <user@example.com>), @message.sender
         
     | 
| 
      
 171 
     | 
    
         
            +
                  end
         
     | 
| 
      
 172 
     | 
    
         
            +
                end
         
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
                describe "gb2312 encoded body" do
         
     | 
| 
      
 175 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 176 
     | 
    
         
            +
                    @raw     = mail("gb2312_encoding")
         
     | 
| 
      
 177 
     | 
    
         
            +
                    @message = Astrotrain::Message.parse(@raw)
         
     | 
| 
      
 178 
     | 
    
         
            +
                  end
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
                  it "converts to UTF-8" do
         
     | 
| 
      
 181 
     | 
    
         
            +
                    assert_equal "Dear Sirs, \r\nWe are given to understand that you are  Manufacturer of  plstic  Bottles\r\nAdd: blah China", 
         
     | 
| 
      
 182 
     | 
    
         
            +
                      @message.body
         
     | 
| 
      
 183 
     | 
    
         
            +
                  end
         
     | 
| 
      
 184 
     | 
    
         
            +
                end
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
                describe "gb2312 encoded body with invalid charset in mime version header" do
         
     | 
| 
      
 187 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 188 
     | 
    
         
            +
                    @raw     = mail("gb2312_encoding_invalid")
         
     | 
| 
      
 189 
     | 
    
         
            +
                    @message = Astrotrain::Message.parse(@raw)
         
     | 
| 
      
 190 
     | 
    
         
            +
                  end
         
     | 
| 
      
 191 
     | 
    
         
            +
             
     | 
| 
      
 192 
     | 
    
         
            +
                  it "converts to UTF-8" do
         
     | 
| 
      
 193 
     | 
    
         
            +
                    assert_equal "Dear Sirs, \r\nWe are given to understand that you are  Manufacturer of  plstic  Bottles\r\nAdd: blah China",
         
     | 
| 
      
 194 
     | 
    
         
            +
                      @message.body
         
     | 
| 
      
 195 
     | 
    
         
            +
                  end
         
     | 
| 
      
 196 
     | 
    
         
            +
                end
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
      
 198 
     | 
    
         
            +
                describe "utf 8 encoded headers" do
         
     | 
| 
      
 199 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 200 
     | 
    
         
            +
                    @raw     = mail("utf-8")
         
     | 
| 
      
 201 
     | 
    
         
            +
                    @message = Astrotrain::Message.parse(@raw)
         
     | 
| 
      
 202 
     | 
    
         
            +
                  end
         
     | 
| 
      
 203 
     | 
    
         
            +
                  
         
     | 
| 
      
 204 
     | 
    
         
            +
                  it "recognizes From: header with strange encoding" do
         
     | 
| 
      
 205 
     | 
    
         
            +
                    assert_equal %(isnard naiké <user@example.com>), @message.sender
         
     | 
| 
      
 206 
     | 
    
         
            +
                  end
         
     | 
| 
      
 207 
     | 
    
         
            +
                end
         
     | 
| 
      
 208 
     | 
    
         
            +
             
     | 
| 
      
 209 
     | 
    
         
            +
                describe "multipart message with name property on Content Type" do
         
     | 
| 
      
 210 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 211 
     | 
    
         
            +
                    @raw     = mail(:multipart)
         
     | 
| 
      
 212 
     | 
    
         
            +
                    @message = Astrotrain::Message.parse(@raw)
         
     | 
| 
      
 213 
     | 
    
         
            +
                  end
         
     | 
| 
      
 214 
     | 
    
         
            +
             
     | 
| 
      
 215 
     | 
    
         
            +
                  it "#parse parses TMail::Mail object from raw text" do
         
     | 
| 
      
 216 
     | 
    
         
            +
                    assert_kind_of TMail::Mail, @message.mail
         
     | 
| 
      
 217 
     | 
    
         
            +
                  end
         
     | 
| 
      
 218 
     | 
    
         
            +
             
     | 
| 
      
 219 
     | 
    
         
            +
                  it "recognizes Delivered-To/To: headers as recipient" do
         
     | 
| 
      
 220 
     | 
    
         
            +
                    assert_equal %w(foo@example.com), @message.recipients
         
     | 
| 
      
 221 
     | 
    
         
            +
                  end
         
     | 
| 
      
 222 
     | 
    
         
            +
             
     | 
| 
      
 223 
     | 
    
         
            +
                  it "recognizes message body" do
         
     | 
| 
      
 224 
     | 
    
         
            +
                    assert_equal "Testing out rich emails with attachments!\nThis one has a name property on Content-Type.\n[state:hold responsible:rick]\n\n",
         
     | 
| 
      
 225 
     | 
    
         
            +
                      @message.body
         
     | 
| 
      
 226 
     | 
    
         
            +
                  end
         
     | 
| 
      
 227 
     | 
    
         
            +
             
     | 
| 
      
 228 
     | 
    
         
            +
                  it "retrieves attachments" do
         
     | 
| 
      
 229 
     | 
    
         
            +
                    assert_equal 1, @message.attachments.size
         
     | 
| 
      
 230 
     | 
    
         
            +
                  end
         
     | 
| 
      
 231 
     | 
    
         
            +
             
     | 
| 
      
 232 
     | 
    
         
            +
                  it "retrieves attachment filename" do
         
     | 
| 
      
 233 
     | 
    
         
            +
                    assert_equal 'bandit.jpg', @message.attachments.first.filename
         
     | 
| 
      
 234 
     | 
    
         
            +
                  end
         
     | 
| 
      
 235 
     | 
    
         
            +
             
     | 
| 
      
 236 
     | 
    
         
            +
                  it "retrieves attachment content_type" do
         
     | 
| 
      
 237 
     | 
    
         
            +
                    assert_equal 'image/jpeg', @message.attachments.first.content_type
         
     | 
| 
      
 238 
     | 
    
         
            +
                  end
         
     | 
| 
      
 239 
     | 
    
         
            +
                end
         
     | 
| 
      
 240 
     | 
    
         
            +
             
     | 
| 
      
 241 
     | 
    
         
            +
                describe "multipart message with filename property on Content Disposition" do
         
     | 
| 
      
 242 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 243 
     | 
    
         
            +
                    @raw     = mail(:multipart2)
         
     | 
| 
      
 244 
     | 
    
         
            +
                    @message = Astrotrain::Message.parse(@raw)
         
     | 
| 
      
 245 
     | 
    
         
            +
                  end
         
     | 
| 
      
 246 
     | 
    
         
            +
             
     | 
| 
      
 247 
     | 
    
         
            +
                  it "#parse parses TMail::Mail object from raw text" do
         
     | 
| 
      
 248 
     | 
    
         
            +
                    assert_kind_of TMail::Mail, @message.mail
         
     | 
| 
      
 249 
     | 
    
         
            +
                  end
         
     | 
| 
      
 250 
     | 
    
         
            +
             
     | 
| 
      
 251 
     | 
    
         
            +
                  it "recognizes Delivered-To/To: headers as recipient" do
         
     | 
| 
      
 252 
     | 
    
         
            +
                    assert_equal %w(foo@example.com), @message.recipients
         
     | 
| 
      
 253 
     | 
    
         
            +
                  end
         
     | 
| 
      
 254 
     | 
    
         
            +
             
     | 
| 
      
 255 
     | 
    
         
            +
                  it "recognizes message body" do
         
     | 
| 
      
 256 
     | 
    
         
            +
                    assert_equal "Testing out rich emails with attachments!\nThis one has NO name property on Content-Type.\n[state:hold responsible:rick]\n\n", 
         
     | 
| 
      
 257 
     | 
    
         
            +
                      @message.body
         
     | 
| 
      
 258 
     | 
    
         
            +
                  end
         
     | 
| 
      
 259 
     | 
    
         
            +
             
     | 
| 
      
 260 
     | 
    
         
            +
                  it "retrieves attachments" do
         
     | 
| 
      
 261 
     | 
    
         
            +
                    assert_equal 1, @message.attachments.size
         
     | 
| 
      
 262 
     | 
    
         
            +
                  end
         
     | 
| 
      
 263 
     | 
    
         
            +
             
     | 
| 
      
 264 
     | 
    
         
            +
                  it "retrieves attachment filename" do
         
     | 
| 
      
 265 
     | 
    
         
            +
                    assert_equal 'bandit.jpg', @message.attachments.first.filename
         
     | 
| 
      
 266 
     | 
    
         
            +
                  end
         
     | 
| 
      
 267 
     | 
    
         
            +
             
     | 
| 
      
 268 
     | 
    
         
            +
                  it "retrieves attachment content_type" do
         
     | 
| 
      
 269 
     | 
    
         
            +
                    assert_equal 'image/jpeg', @message.attachments.first.content_type
         
     | 
| 
      
 270 
     | 
    
         
            +
                  end
         
     | 
| 
      
 271 
     | 
    
         
            +
                end
         
     | 
| 
      
 272 
     | 
    
         
            +
             
     | 
| 
      
 273 
     | 
    
         
            +
                describe "apple multipart message" do
         
     | 
| 
      
 274 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 275 
     | 
    
         
            +
                    @raw     = mail(:apple_multipart)
         
     | 
| 
      
 276 
     | 
    
         
            +
                    @message = Astrotrain::Message.parse(@raw)
         
     | 
| 
      
 277 
     | 
    
         
            +
                  end
         
     | 
| 
      
 278 
     | 
    
         
            +
             
     | 
| 
      
 279 
     | 
    
         
            +
                  it "#parse parses TMail::Mail object from raw text" do
         
     | 
| 
      
 280 
     | 
    
         
            +
                    assert_kind_of TMail::Mail, @message.mail
         
     | 
| 
      
 281 
     | 
    
         
            +
                  end
         
     | 
| 
      
 282 
     | 
    
         
            +
             
     | 
| 
      
 283 
     | 
    
         
            +
                  it "recognizes To: header as recipient" do
         
     | 
| 
      
 284 
     | 
    
         
            +
                    assert_equal %w(foo@example.com), @message.recipients
         
     | 
| 
      
 285 
     | 
    
         
            +
                  end
         
     | 
| 
      
 286 
     | 
    
         
            +
             
     | 
| 
      
 287 
     | 
    
         
            +
                  it "recognizes message body" do
         
     | 
| 
      
 288 
     | 
    
         
            +
                    assert_equal "Let's have a test here:\r\n\r\n\r\n\nYum\r\n\r\n\r\nOn Feb 10, 2009, at 3:37 PM, Tender Support wrote:\r\n\r\n> // Add your reply above here\r\n> ==================================================\r\n> From: Tyler Durden\r\n> Subject: Email attachments and file upload\r\n>\r\n> not at the moment ... let me test\r\n>\r\n> View this Discussion online: http://foobar.com\r\n> .\r\n\r\n\r\n\r\n\r\n--Apple-Mail-7-451386929--", 
         
     | 
| 
      
 289 
     | 
    
         
            +
                      @message.body
         
     | 
| 
      
 290 
     | 
    
         
            +
                  end
         
     | 
| 
      
 291 
     | 
    
         
            +
             
     | 
| 
      
 292 
     | 
    
         
            +
                  it "retrieves attachments" do
         
     | 
| 
      
 293 
     | 
    
         
            +
                    assert_equal 1, @message.attachments.size
         
     | 
| 
      
 294 
     | 
    
         
            +
                  end
         
     | 
| 
      
 295 
     | 
    
         
            +
             
     | 
| 
      
 296 
     | 
    
         
            +
                  it "retrieves attachment filename" do
         
     | 
| 
      
 297 
     | 
    
         
            +
                    assert_equal 'logo.gif', @message.attachments.first.filename
         
     | 
| 
      
 298 
     | 
    
         
            +
                  end
         
     | 
| 
      
 299 
     | 
    
         
            +
             
     | 
| 
      
 300 
     | 
    
         
            +
                  it "retrieves attachment content_type" do
         
     | 
| 
      
 301 
     | 
    
         
            +
                    assert_equal 'image/gif', @message.attachments.first.content_type
         
     | 
| 
      
 302 
     | 
    
         
            +
                  end
         
     | 
| 
      
 303 
     | 
    
         
            +
                end
         
     | 
| 
      
 304 
     | 
    
         
            +
             
     | 
| 
      
 305 
     | 
    
         
            +
                describe "multiple sender/recipients" do
         
     | 
| 
      
 306 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 307 
     | 
    
         
            +
                    @raw     = mail(:multiple)
         
     | 
| 
      
 308 
     | 
    
         
            +
                    @message = Astrotrain::Message.parse(@raw)
         
     | 
| 
      
 309 
     | 
    
         
            +
                  end
         
     | 
| 
      
 310 
     | 
    
         
            +
             
     | 
| 
      
 311 
     | 
    
         
            +
                  it "#parse parses TMail::Mail object from raw text" do
         
     | 
| 
      
 312 
     | 
    
         
            +
                    assert_kind_of TMail::Mail, @message.mail
         
     | 
| 
      
 313 
     | 
    
         
            +
                  end
         
     | 
| 
      
 314 
     | 
    
         
            +
             
     | 
| 
      
 315 
     | 
    
         
            +
                  it "recognizes To: headers as recipients" do
         
     | 
| 
      
 316 
     | 
    
         
            +
                    assert_equal %w(processor@astrotrain.com other@example.com), @message.recipients
         
     | 
| 
      
 317 
     | 
    
         
            +
                  end
         
     | 
| 
      
 318 
     | 
    
         
            +
             
     | 
| 
      
 319 
     | 
    
         
            +
                  it "recognizes To: headers as recipients with custom header order" do
         
     | 
| 
      
 320 
     | 
    
         
            +
                    assert_equal %w(other@example.com processor@astrotrain.com), @message.recipients(%w(to original_to delivered_to))
         
     | 
| 
      
 321 
     | 
    
         
            +
                  end
         
     | 
| 
      
 322 
     | 
    
         
            +
             
     | 
| 
      
 323 
     | 
    
         
            +
                  it "recognizes From: header as sender" do
         
     | 
| 
      
 324 
     | 
    
         
            +
                    assert_equal %(user@example.com, boss@example.com), @message.sender
         
     | 
| 
      
 325 
     | 
    
         
            +
                  end
         
     | 
| 
      
 326 
     | 
    
         
            +
             
     | 
| 
      
 327 
     | 
    
         
            +
                  it "recognizes Subject: header" do
         
     | 
| 
      
 328 
     | 
    
         
            +
                    assert_equal 'Fwd: blah blah', @message.subject
         
     | 
| 
      
 329 
     | 
    
         
            +
                  end
         
     | 
| 
      
 330 
     | 
    
         
            +
             
     | 
| 
      
 331 
     | 
    
         
            +
                  it "recognizes message body" do
         
     | 
| 
      
 332 
     | 
    
         
            +
                    assert_equal @body, @message.body
         
     | 
| 
      
 333 
     | 
    
         
            +
                  end
         
     | 
| 
      
 334 
     | 
    
         
            +
             
     | 
| 
      
 335 
     | 
    
         
            +
                  it "retains raw message" do
         
     | 
| 
      
 336 
     | 
    
         
            +
                    assert_equal @raw, @message.raw
         
     | 
| 
      
 337 
     | 
    
         
            +
                  end
         
     | 
| 
      
 338 
     | 
    
         
            +
                end
         
     | 
| 
      
 339 
     | 
    
         
            +
             
     | 
| 
      
 340 
     | 
    
         
            +
                describe "recipients in the body" do
         
     | 
| 
      
 341 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 342 
     | 
    
         
            +
                    @raw     = mail(:multiple_with_body_recipients)
         
     | 
| 
      
 343 
     | 
    
         
            +
                    @message = Astrotrain::Message.parse(@raw)
         
     | 
| 
      
 344 
     | 
    
         
            +
                  end
         
     | 
| 
      
 345 
     | 
    
         
            +
             
     | 
| 
      
 346 
     | 
    
         
            +
                  it "recognizes in-body emails and To: headers as recipients" do
         
     | 
| 
      
 347 
     | 
    
         
            +
                    assert_equal %w(processor+foobar@astrotrain.com processor+blah@astrotrain.com processor@astrotrain.com other@example.com), 
         
     | 
| 
      
 348 
     | 
    
         
            +
                      @message.recipients
         
     | 
| 
      
 349 
     | 
    
         
            +
                  end
         
     | 
| 
      
 350 
     | 
    
         
            +
                end
         
     | 
| 
      
 351 
     | 
    
         
            +
             
     | 
| 
      
 352 
     | 
    
         
            +
                describe "with only HTML body" do
         
     | 
| 
      
 353 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 354 
     | 
    
         
            +
                    @raw     = mail(:html)
         
     | 
| 
      
 355 
     | 
    
         
            +
                    @message = Astrotrain::Message.parse(@raw)
         
     | 
| 
      
 356 
     | 
    
         
            +
                  end
         
     | 
| 
      
 357 
     | 
    
         
            +
             
     | 
| 
      
 358 
     | 
    
         
            +
                  it "parses emtpy body" do
         
     | 
| 
      
 359 
     | 
    
         
            +
                    assert_equal '', @message.body
         
     | 
| 
      
 360 
     | 
    
         
            +
                  end
         
     | 
| 
      
 361 
     | 
    
         
            +
             
     | 
| 
      
 362 
     | 
    
         
            +
                  it "parses HTML body" do
         
     | 
| 
      
 363 
     | 
    
         
            +
                    assert_equal "<p>ABC</p>\n------", @message.html
         
     | 
| 
      
 364 
     | 
    
         
            +
                  end
         
     | 
| 
      
 365 
     | 
    
         
            +
                end
         
     | 
| 
      
 366 
     | 
    
         
            +
             
     | 
| 
      
 367 
     | 
    
         
            +
                describe "with X Original To header" do
         
     | 
| 
      
 368 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 369 
     | 
    
         
            +
                    @raw     = mail(:custom)
         
     | 
| 
      
 370 
     | 
    
         
            +
                    @message = Astrotrain::Message.parse(@raw)
         
     | 
| 
      
 371 
     | 
    
         
            +
                  end
         
     | 
| 
      
 372 
     | 
    
         
            +
             
     | 
| 
      
 373 
     | 
    
         
            +
                  it "#parse parses TMail::Mail object from raw text" do
         
     | 
| 
      
 374 
     | 
    
         
            +
                    assert_kind_of TMail::Mail, @message.mail
         
     | 
| 
      
 375 
     | 
    
         
            +
                  end
         
     | 
| 
      
 376 
     | 
    
         
            +
             
     | 
| 
      
 377 
     | 
    
         
            +
                  it "recognizes X-Original-to: header as recipient" do
         
     | 
| 
      
 378 
     | 
    
         
            +
                    assert_equal %w(processor-reply-57@custom.com processor-delivered@astrotrain.com processor@astrotrain.com), @message.recipients
         
     | 
| 
      
 379 
     | 
    
         
            +
                  end
         
     | 
| 
      
 380 
     | 
    
         
            +
             
     | 
| 
      
 381 
     | 
    
         
            +
                  it "recognizes Delivered-To: header as recipient with custom header order" do
         
     | 
| 
      
 382 
     | 
    
         
            +
                    assert_equal %w(processor-delivered@astrotrain.com processor-reply-57@custom.com processor@astrotrain.com), @message.recipients(%w(delivered_to original_to to))
         
     | 
| 
      
 383 
     | 
    
         
            +
                  end
         
     | 
| 
      
 384 
     | 
    
         
            +
             
     | 
| 
      
 385 
     | 
    
         
            +
                  it "recognizes To: header as recipient with custom header order" do
         
     | 
| 
      
 386 
     | 
    
         
            +
                    assert_equal %w(processor@astrotrain.com processor-reply-57@custom.com processor-delivered@astrotrain.com), @message.recipients(%w(to original_to delivered_to))
         
     | 
| 
      
 387 
     | 
    
         
            +
                  end
         
     | 
| 
      
 388 
     | 
    
         
            +
             
     | 
| 
      
 389 
     | 
    
         
            +
                  it "recognizes From: header as sender" do
         
     | 
| 
      
 390 
     | 
    
         
            +
                    assert_equal %(user@example.com, boss@example.com), @message.sender
         
     | 
| 
      
 391 
     | 
    
         
            +
                  end
         
     | 
| 
      
 392 
     | 
    
         
            +
             
     | 
| 
      
 393 
     | 
    
         
            +
                  it "recognizes Subject: header" do
         
     | 
| 
      
 394 
     | 
    
         
            +
                    assert_equal 'Fwd: blah blah', @message.subject
         
     | 
| 
      
 395 
     | 
    
         
            +
                  end
         
     | 
| 
      
 396 
     | 
    
         
            +
             
     | 
| 
      
 397 
     | 
    
         
            +
                  it "recognizes message body" do
         
     | 
| 
      
 398 
     | 
    
         
            +
                    assert_equal @body, @message.body
         
     | 
| 
      
 399 
     | 
    
         
            +
                  end
         
     | 
| 
      
 400 
     | 
    
         
            +
             
     | 
| 
      
 401 
     | 
    
         
            +
                  it "retains raw message" do
         
     | 
| 
      
 402 
     | 
    
         
            +
                    assert_equal @raw, @message.raw
         
     | 
| 
      
 403 
     | 
    
         
            +
                  end
         
     | 
| 
      
 404 
     | 
    
         
            +
                end
         
     | 
| 
      
 405 
     | 
    
         
            +
             
     | 
| 
      
 406 
     | 
    
         
            +
                describe "with multiple Delivered To headers" do
         
     | 
| 
      
 407 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 408 
     | 
    
         
            +
                    @raw     = mail(:multiple_delivered_to)
         
     | 
| 
      
 409 
     | 
    
         
            +
                    @message = Astrotrain::Message.parse(@raw)
         
     | 
| 
      
 410 
     | 
    
         
            +
                  end
         
     | 
| 
      
 411 
     | 
    
         
            +
             
     | 
| 
      
 412 
     | 
    
         
            +
                  it "recognizes Delivered-to: header as recipient" do
         
     | 
| 
      
 413 
     | 
    
         
            +
                    assert_equal %w(processor-reply-57@custom.com processor-delivered@astrotrain.com processor@astrotrain.com), @message.recipients
         
     | 
| 
      
 414 
     | 
    
         
            +
                  end
         
     | 
| 
      
 415 
     | 
    
         
            +
                end
         
     | 
| 
      
 416 
     | 
    
         
            +
              end
         
     | 
| 
      
 417 
     | 
    
         
            +
             
     | 
| 
      
 418 
     | 
    
         
            +
              describe "queueing" do
         
     | 
| 
      
 419 
     | 
    
         
            +
                it "writes contents queue path" do
         
     | 
| 
      
 420 
     | 
    
         
            +
                  filename = Astrotrain::Message.queue("boo!")
         
     | 
| 
      
 421 
     | 
    
         
            +
                  assert_equal 'boo!', IO.read(filename)
         
     | 
| 
      
 422 
     | 
    
         
            +
                end
         
     | 
| 
      
 423 
     | 
    
         
            +
              end
         
     | 
| 
      
 424 
     | 
    
         
            +
            end
         
     | 
    
        data/test/test_helper.rb
    ADDED
    
    | 
         @@ -0,0 +1,54 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            $testing = true
         
     | 
| 
      
 2 
     | 
    
         
            +
            $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            require "rubygems"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require "context"
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'rr'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'astrotrain'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'astrotrain/api'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'sinatra/test'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            module Astrotrain
         
     | 
| 
      
 12 
     | 
    
         
            +
              load File.dirname(__FILE__) do
         
     | 
| 
      
 13 
     | 
    
         
            +
                DataMapper.setup(:default, {
         
     | 
| 
      
 14 
     | 
    
         
            +
                  :adapter  => "mysql",
         
     | 
| 
      
 15 
     | 
    
         
            +
                  :database => "astrotrain_test",
         
     | 
| 
      
 16 
     | 
    
         
            +
                  :username => "root",
         
     | 
| 
      
 17 
     | 
    
         
            +
                  :host     => "localhost"
         
     | 
| 
      
 18 
     | 
    
         
            +
                })
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              LoggedMail.log_path = Astrotrain.root / 'messages'
         
     | 
| 
      
 22 
     | 
    
         
            +
              FileUtils.rm_rf   LoggedMail.log_path
         
     | 
| 
      
 23 
     | 
    
         
            +
              FileUtils.mkdir_p LoggedMail.log_path
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              Message.queue_path = root / 'fixtures' / 'queue'
         
     | 
| 
      
 26 
     | 
    
         
            +
              FileUtils.rm_rf   Message.queue_path
         
     | 
| 
      
 27 
     | 
    
         
            +
              FileUtils.mkdir_p Message.queue_path
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              class TestCase < Test::Unit::TestCase
         
     | 
| 
      
 30 
     | 
    
         
            +
                include RR::Adapters::RRMethods
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                before do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  RR.reset
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                after do
         
     | 
| 
      
 37 
     | 
    
         
            +
                  RR.verify
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                def mail(filename)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  IO.read(File.join(File.dirname(__FILE__), 'fixtures', "#{filename}.txt"))
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              class ApiTestCase < TestCase
         
     | 
| 
      
 46 
     | 
    
         
            +
                include Sinatra::Test
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
      
 48 
     | 
    
         
            +
            end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
            begin
         
     | 
| 
      
 51 
     | 
    
         
            +
              require 'ruby-debug'
         
     | 
| 
      
 52 
     | 
    
         
            +
              Debugger.start
         
     | 
| 
      
 53 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 54 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,111 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.join(File.dirname(__FILE__), "test_helper")
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class Astrotrain::TransportTest < Astrotrain::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              describe "HttpPost" do
         
     | 
| 
      
 5 
     | 
    
         
            +
                before :all do
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @post    = 'http://example.com'
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @message = Astrotrain::Message.parse(mail(:custom))
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @mapping = Astrotrain::Mapping.new(:destination => @post, :transport => 'http_post')
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                before do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @trans           = Astrotrain::Mapping::HttpPost.new(@message, @mapping, @message.recipients(%w(delivered_to)).first)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @expected_fields = @trans.fields.merge(:emails => @message.recipients(%w(original_to to)) * ",")
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                it "sets #fields" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                  expected = {:subject => @message.subject, :from => @message.sender, :to => @message.recipients(%w(delivered_to)).first, :body => @message.body, :html => @message.html, :emails => @message.recipients(%w(original_to to)),
         
     | 
| 
      
 18 
     | 
    
         
            +
                    "headers[reply-to]" => "reply-to-me@example.com", 'headers[message-id]' => '<a16be7390810161014n52b603e9k1aa6bb803c6735aa@mail.gmail.com>', 'headers[to]' => "processor@astrotrain.com",
         
     | 
| 
      
 19 
     | 
    
         
            +
                    "headers[mime-version]"=>"1.0", "headers[content-type]"=>"text/plain; charset=ISO-8859-1", "headers[content-disposition]"=>"inline", "headers[content-transfer-encoding]"=>"7bit"}
         
     | 
| 
      
 20 
     | 
    
         
            +
                  assert_equal expected, @trans.fields
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                it "adds attachments to #fields" do
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @multipart = Astrotrain::Message.parse(mail(:multipart))
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @trans     = Astrotrain::Mapping::HttpPost.new(@multipart, @mapping, @multipart.recipients.first)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  assert_equal @multipart.attachments.first, @trans.fields[:attachments_0]
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                it "sets fields with mapping separator set" do
         
     | 
| 
      
 30 
     | 
    
         
            +
                  @message = Astrotrain::Message.parse(mail(:reply))
         
     | 
| 
      
 31 
     | 
    
         
            +
                  @mapping.separator = "=" * 5
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @trans   = Astrotrain::Mapping::HttpPost.new(@message, @mapping, @message.recipients.first)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  assert_equal "blah blah", @trans.fields[:body]
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                describe "when processing" do
         
     | 
| 
      
 37 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 38 
     | 
    
         
            +
                    stub(Astrotrain::Mapping::HttpPost).new {@trans}
         
     | 
| 
      
 39 
     | 
    
         
            +
                  end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                  it "makes http post request" do
         
     | 
| 
      
 42 
     | 
    
         
            +
                    mock(RestClient).post(@mapping.destination, @expected_fields)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    @trans.process
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  it "makes http post request from Transport" do
         
     | 
| 
      
 47 
     | 
    
         
            +
                    mock(RestClient).post(@mapping.destination, @expected_fields)
         
     | 
| 
      
 48 
     | 
    
         
            +
                    Astrotrain::Mapping::Transport.process(@message, @mapping, @message.recipients.first)
         
     | 
| 
      
 49 
     | 
    
         
            +
                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 52 
     | 
    
         
            +
                    Astrotrain::Mapping::Transport.processing = true
         
     | 
| 
      
 53 
     | 
    
         
            +
                  end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                  after :all do
         
     | 
| 
      
 56 
     | 
    
         
            +
                    Astrotrain::Mapping::Transport.processing = false
         
     | 
| 
      
 57 
     | 
    
         
            +
                  end
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
              describe "jabber" do
         
     | 
| 
      
 62 
     | 
    
         
            +
                before :all do
         
     | 
| 
      
 63 
     | 
    
         
            +
                  @dest    = 'foo@bar.com'
         
     | 
| 
      
 64 
     | 
    
         
            +
                  @message = Astrotrain::Message.parse(mail(:custom))
         
     | 
| 
      
 65 
     | 
    
         
            +
                  @mapping = Astrotrain::Mapping.new(:destination => @dest, :transport => 'jabber')
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                before do
         
     | 
| 
      
 69 
     | 
    
         
            +
                  @trans   = Astrotrain::Mapping::Jabber.new(@message, @mapping, @message.recipients(%w(delivered_to)).first)
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                it "sets #content" do
         
     | 
| 
      
 73 
     | 
    
         
            +
                  expected = "From: %s\nTo: %s\nSubject: %s\nEmails: %s\n%s" % [@message.sender, @message.recipients(%w(delivered_to)).first, @message.subject, @message.recipients(%w(original_to to)) * ", ", @message.body]
         
     | 
| 
      
 74 
     | 
    
         
            +
                  assert_equal expected, @trans.content
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                it "sets content with mapping separator set" do
         
     | 
| 
      
 78 
     | 
    
         
            +
                  @message = Astrotrain::Message.parse(mail(:reply))
         
     | 
| 
      
 79 
     | 
    
         
            +
                  @mapping.separator = "=" * 5
         
     | 
| 
      
 80 
     | 
    
         
            +
                  @trans   = Astrotrain::Mapping::Jabber.new(@message, @mapping, @message.recipients(%w(delivered_to)).first)
         
     | 
| 
      
 81 
     | 
    
         
            +
                  expected = "From: %s\nTo: %s\nSubject: %s\nEmails: %s\n%s" % [@message.sender, @message.recipients(%w(delivered_to)).first, @message.subject, '', "blah blah"]
         
     | 
| 
      
 82 
     | 
    
         
            +
                  assert_equal expected, @trans.content
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                describe "when processing" do
         
     | 
| 
      
 86 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 87 
     | 
    
         
            +
                    @conn = Object.new
         
     | 
| 
      
 88 
     | 
    
         
            +
                    stub(@trans).connection { @conn }
         
     | 
| 
      
 89 
     | 
    
         
            +
                    stub(Astrotrain::Mapping::Jabber).new { @trans }
         
     | 
| 
      
 90 
     | 
    
         
            +
                  end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                  it "makes jabber delivery" do
         
     | 
| 
      
 93 
     | 
    
         
            +
                    mock(@conn).deliver(@mapping.destination, @trans.content)
         
     | 
| 
      
 94 
     | 
    
         
            +
                    @trans.process
         
     | 
| 
      
 95 
     | 
    
         
            +
                  end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                  it "makes jabber delivery from Transport" do
         
     | 
| 
      
 98 
     | 
    
         
            +
                    mock(@conn).deliver(@mapping.destination, @trans.content)
         
     | 
| 
      
 99 
     | 
    
         
            +
                    Astrotrain::Mapping::Transport.process(@message, @mapping, @message.recipients(%w(delivered_to)).first)
         
     | 
| 
      
 100 
     | 
    
         
            +
                  end
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 103 
     | 
    
         
            +
                    Astrotrain::Mapping::Transport.processing = true
         
     | 
| 
      
 104 
     | 
    
         
            +
                  end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                  after :all do
         
     | 
| 
      
 107 
     | 
    
         
            +
                    Astrotrain::Mapping::Transport.processing = false
         
     | 
| 
      
 108 
     | 
    
         
            +
                  end
         
     | 
| 
      
 109 
     | 
    
         
            +
                end
         
     | 
| 
      
 110 
     | 
    
         
            +
              end
         
     | 
| 
      
 111 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,115 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification 
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: entp-astrotrain
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version 
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors: 
         
     | 
| 
      
 7 
     | 
    
         
            +
            - technoweenie
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2009-09-21 00:00:00 -07:00
         
     | 
| 
      
 13 
     | 
    
         
            +
            default_executable: 
         
     | 
| 
      
 14 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            description: 
         
     | 
| 
      
 17 
     | 
    
         
            +
            email: technoweenie@gmail.com
         
     | 
| 
      
 18 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            extra_rdoc_files: 
         
     | 
| 
      
 23 
     | 
    
         
            +
            - LICENSE
         
     | 
| 
      
 24 
     | 
    
         
            +
            - README
         
     | 
| 
      
 25 
     | 
    
         
            +
            files: 
         
     | 
| 
      
 26 
     | 
    
         
            +
            - .gitignore
         
     | 
| 
      
 27 
     | 
    
         
            +
            - LICENSE
         
     | 
| 
      
 28 
     | 
    
         
            +
            - README
         
     | 
| 
      
 29 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 30 
     | 
    
         
            +
            - VERSION
         
     | 
| 
      
 31 
     | 
    
         
            +
            - astrotrain.gemspec
         
     | 
| 
      
 32 
     | 
    
         
            +
            - config/sample.rb
         
     | 
| 
      
 33 
     | 
    
         
            +
            - lib/astrotrain.rb
         
     | 
| 
      
 34 
     | 
    
         
            +
            - lib/astrotrain/api.rb
         
     | 
| 
      
 35 
     | 
    
         
            +
            - lib/astrotrain/logged_mail.rb
         
     | 
| 
      
 36 
     | 
    
         
            +
            - lib/astrotrain/mapping.rb
         
     | 
| 
      
 37 
     | 
    
         
            +
            - lib/astrotrain/mapping/http_post.rb
         
     | 
| 
      
 38 
     | 
    
         
            +
            - lib/astrotrain/mapping/jabber.rb
         
     | 
| 
      
 39 
     | 
    
         
            +
            - lib/astrotrain/mapping/transport.rb
         
     | 
| 
      
 40 
     | 
    
         
            +
            - lib/astrotrain/message.rb
         
     | 
| 
      
 41 
     | 
    
         
            +
            - lib/astrotrain/tmail.rb
         
     | 
| 
      
 42 
     | 
    
         
            +
            - lib/vendor/rest-client/README.rdoc
         
     | 
| 
      
 43 
     | 
    
         
            +
            - lib/vendor/rest-client/Rakefile
         
     | 
| 
      
 44 
     | 
    
         
            +
            - lib/vendor/rest-client/bin/restclient
         
     | 
| 
      
 45 
     | 
    
         
            +
            - lib/vendor/rest-client/foo.diff
         
     | 
| 
      
 46 
     | 
    
         
            +
            - lib/vendor/rest-client/lib/rest_client.rb
         
     | 
| 
      
 47 
     | 
    
         
            +
            - lib/vendor/rest-client/lib/rest_client/net_http_ext.rb
         
     | 
| 
      
 48 
     | 
    
         
            +
            - lib/vendor/rest-client/lib/rest_client/payload.rb
         
     | 
| 
      
 49 
     | 
    
         
            +
            - lib/vendor/rest-client/lib/rest_client/request_errors.rb
         
     | 
| 
      
 50 
     | 
    
         
            +
            - lib/vendor/rest-client/lib/rest_client/resource.rb
         
     | 
| 
      
 51 
     | 
    
         
            +
            - lib/vendor/rest-client/rest-client.gemspec
         
     | 
| 
      
 52 
     | 
    
         
            +
            - lib/vendor/rest-client/spec/base.rb
         
     | 
| 
      
 53 
     | 
    
         
            +
            - lib/vendor/rest-client/spec/master_shake.jpg
         
     | 
| 
      
 54 
     | 
    
         
            +
            - lib/vendor/rest-client/spec/payload_spec.rb
         
     | 
| 
      
 55 
     | 
    
         
            +
            - lib/vendor/rest-client/spec/request_errors_spec.rb
         
     | 
| 
      
 56 
     | 
    
         
            +
            - lib/vendor/rest-client/spec/resource_spec.rb
         
     | 
| 
      
 57 
     | 
    
         
            +
            - lib/vendor/rest-client/spec/rest_client_spec.rb
         
     | 
| 
      
 58 
     | 
    
         
            +
            - tasks/doc.thor
         
     | 
| 
      
 59 
     | 
    
         
            +
            - tasks/merb.thor
         
     | 
| 
      
 60 
     | 
    
         
            +
            - test/api_test.rb
         
     | 
| 
      
 61 
     | 
    
         
            +
            - test/fixtures/apple_multipart.txt
         
     | 
| 
      
 62 
     | 
    
         
            +
            - test/fixtures/basic.txt
         
     | 
| 
      
 63 
     | 
    
         
            +
            - test/fixtures/custom.txt
         
     | 
| 
      
 64 
     | 
    
         
            +
            - test/fixtures/fwd.txt
         
     | 
| 
      
 65 
     | 
    
         
            +
            - test/fixtures/gb2312_encoding.txt
         
     | 
| 
      
 66 
     | 
    
         
            +
            - test/fixtures/gb2312_encoding_invalid.txt
         
     | 
| 
      
 67 
     | 
    
         
            +
            - test/fixtures/html.txt
         
     | 
| 
      
 68 
     | 
    
         
            +
            - test/fixtures/iso-8859-1.txt
         
     | 
| 
      
 69 
     | 
    
         
            +
            - test/fixtures/mapped.txt
         
     | 
| 
      
 70 
     | 
    
         
            +
            - test/fixtures/multipart.txt
         
     | 
| 
      
 71 
     | 
    
         
            +
            - test/fixtures/multipart2.txt
         
     | 
| 
      
 72 
     | 
    
         
            +
            - test/fixtures/multiple.txt
         
     | 
| 
      
 73 
     | 
    
         
            +
            - test/fixtures/multiple_delivered_to.txt
         
     | 
| 
      
 74 
     | 
    
         
            +
            - test/fixtures/multiple_with_body_recipients.txt
         
     | 
| 
      
 75 
     | 
    
         
            +
            - test/fixtures/reply.txt
         
     | 
| 
      
 76 
     | 
    
         
            +
            - test/fixtures/utf-8.txt
         
     | 
| 
      
 77 
     | 
    
         
            +
            - test/logged_mail_test.rb
         
     | 
| 
      
 78 
     | 
    
         
            +
            - test/mapping_test.rb
         
     | 
| 
      
 79 
     | 
    
         
            +
            - test/message_test.rb
         
     | 
| 
      
 80 
     | 
    
         
            +
            - test/test_helper.rb
         
     | 
| 
      
 81 
     | 
    
         
            +
            - test/transport_test.rb
         
     | 
| 
      
 82 
     | 
    
         
            +
            has_rdoc: false
         
     | 
| 
      
 83 
     | 
    
         
            +
            homepage: http://github.com/entp/astrotrain
         
     | 
| 
      
 84 
     | 
    
         
            +
            licenses: 
         
     | 
| 
      
 85 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 86 
     | 
    
         
            +
            rdoc_options: 
         
     | 
| 
      
 87 
     | 
    
         
            +
            - --charset=UTF-8
         
     | 
| 
      
 88 
     | 
    
         
            +
            require_paths: 
         
     | 
| 
      
 89 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 90 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 91 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 92 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 93 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 94 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 95 
     | 
    
         
            +
              version: 
         
     | 
| 
      
 96 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 97 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 98 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 99 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 100 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 101 
     | 
    
         
            +
              version: 
         
     | 
| 
      
 102 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 105 
     | 
    
         
            +
            rubygems_version: 1.3.5
         
     | 
| 
      
 106 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 107 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 108 
     | 
    
         
            +
            summary: email => http post
         
     | 
| 
      
 109 
     | 
    
         
            +
            test_files: 
         
     | 
| 
      
 110 
     | 
    
         
            +
            - test/api_test.rb
         
     | 
| 
      
 111 
     | 
    
         
            +
            - test/logged_mail_test.rb
         
     | 
| 
      
 112 
     | 
    
         
            +
            - test/mapping_test.rb
         
     | 
| 
      
 113 
     | 
    
         
            +
            - test/message_test.rb
         
     | 
| 
      
 114 
     | 
    
         
            +
            - test/test_helper.rb
         
     | 
| 
      
 115 
     | 
    
         
            +
            - test/transport_test.rb
         
     |