|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Griddler::Email do |
| 4 | + it "should handle 'On [date] [soandso] wrote:' format" do |
| 5 | + body = <<-EOF |
| 6 | + Hello. |
| 7 | +
|
| 8 | + On 2010-01-01 12:00:00 Tristan wrote: |
| 9 | + > Check out this report. |
| 10 | + > |
| 11 | + > It's pretty cool. |
| 12 | + > |
| 13 | + > Thanks, Tristan |
| 14 | + EOF |
| 15 | + |
| 16 | + email = Griddler::Email.new(text: body) |
| 17 | + email.body.should == 'Hello.' |
| 18 | + end |
| 19 | + |
| 20 | + it "should handle 'On [date] [soandso] <email@example.com> wrote:' format" do |
| 21 | + body = <<-EOF |
| 22 | + Hello. |
| 23 | +
|
| 24 | + On 2010-01-01 12:00:00 Tristan <email@example.com> wrote: |
| 25 | + > Check out this report. |
| 26 | + > |
| 27 | + > It's pretty cool. |
| 28 | + > |
| 29 | + > Thanks, Tristan |
| 30 | + EOF |
| 31 | + |
| 32 | + email = Griddler::Email.new(text: body) |
| 33 | + email.body.should == 'Hello.' |
| 34 | + end |
| 35 | + |
| 36 | + it "should handle 'On [date] [soandso]\n<email@example.com> wrote:' format" do |
| 37 | + body = <<-EOF |
| 38 | + Hello. |
| 39 | +
|
| 40 | + On 2010-01-01 12:00:00 Tristan\n <email@example.com> wrote: |
| 41 | + > Check out this report. |
| 42 | + > |
| 43 | + > It's pretty cool. |
| 44 | + > |
| 45 | + > Thanks, Tristan |
| 46 | + EOF |
| 47 | + |
| 48 | + email = Griddler::Email.new(text: body) |
| 49 | + email.body.should == 'Hello.' |
| 50 | + end |
| 51 | + |
| 52 | + it "should handle '-----Original Message-----' format" do |
| 53 | + body = <<-EOF |
| 54 | + Hello. |
| 55 | +
|
| 56 | + -----Original Message----- |
| 57 | + From: bob@example.com |
| 58 | + Sent: Today |
| 59 | + Subject: Awesome report. |
| 60 | +
|
| 61 | + Check out this report! |
| 62 | + EOF |
| 63 | + |
| 64 | + email = Griddler::Email.new(text: body) |
| 65 | + email.body.should == 'Hello.' |
| 66 | + end |
| 67 | + |
| 68 | + it "should handle 'Reply ABOVE THIS LINE' format" do |
| 69 | + body = <<-EOF |
| 70 | + Hello. |
| 71 | +
|
| 72 | + Reply ABOVE THIS LINE |
| 73 | +
|
| 74 | + Hey! |
| 75 | + EOF |
| 76 | + |
| 77 | + email = Griddler::Email.new(text: body) |
| 78 | + email.body.should == 'Hello.' |
| 79 | + end |
| 80 | + |
| 81 | + it "should remove any noncontent things above Reply ABOVE THIS LINE" do |
| 82 | + body = <<-EOF |
| 83 | + Hello. |
| 84 | +
|
| 85 | + On 2010-01-01 12:00:00 Tristan wrote: |
| 86 | +
|
| 87 | + > Reply ABOVE THIS LINE |
| 88 | +
|
| 89 | + Hey! |
| 90 | + EOF |
| 91 | + |
| 92 | + email = Griddler::Email.new(text: body) |
| 93 | + email.body.should == 'Hello.' |
| 94 | + end |
| 95 | + |
| 96 | + it "should remove any iphone things above Reply ABOVE THIS LINE" do |
| 97 | + body = <<-EOF |
| 98 | + Hello. |
| 99 | +
|
| 100 | + Sent from my iPhone |
| 101 | +
|
| 102 | + > Reply ABOVE THIS LINE |
| 103 | +
|
| 104 | + Hey! |
| 105 | + EOF |
| 106 | + |
| 107 | + email = Griddler::Email.new(text: body) |
| 108 | + email.body.should == 'Hello.' |
| 109 | + end |
| 110 | + |
| 111 | + it "should remove any signature above Reply ABOVE THIS LINE" do |
| 112 | + body = <<-EOF |
| 113 | + Hello. |
| 114 | +
|
| 115 | + -- |
| 116 | + Mr. Smith |
| 117 | + CEO, company |
| 118 | + t: 6174821300 |
| 119 | +
|
| 120 | + > Reply ABOVE THIS LINE |
| 121 | +
|
| 122 | + > Hey! |
| 123 | + EOF |
| 124 | + |
| 125 | + email = Griddler::Email.new(text: body) |
| 126 | + email.body.should == 'Hello.' |
| 127 | + end |
| 128 | + |
| 129 | + it "should remove any signature without space above Reply ABOVE THIS LINE" do |
| 130 | + body = <<-EOF |
| 131 | + Hello. |
| 132 | +
|
| 133 | + -- |
| 134 | + Mr. Smith |
| 135 | + CEO, company |
| 136 | + t: 6174821300 |
| 137 | +
|
| 138 | + > Reply ABOVE THIS LINE |
| 139 | +
|
| 140 | + > Hey! |
| 141 | + EOF |
| 142 | + |
| 143 | + email = Griddler::Email.new(text: body) |
| 144 | + email.body.should == 'Hello.' |
| 145 | + end |
| 146 | + |
| 147 | + it "properly handles a json charsets" do |
| 148 | + body = <<-EOF |
| 149 | + Hello. |
| 150 | +
|
| 151 | + -- |
| 152 | + Mr. Smith |
| 153 | + CEO, company |
| 154 | + t: 6174821300 |
| 155 | +
|
| 156 | + > Reply ABOVE THIS LINE |
| 157 | +
|
| 158 | + > Hey! |
| 159 | + EOF |
| 160 | + charsets = { |
| 161 | + to: 'UTF-8', |
| 162 | + html: 'utf-8', |
| 163 | + subject: 'UTF-8', |
| 164 | + from: 'UTF-8', |
| 165 | + text: 'utf-8' |
| 166 | + }.to_json |
| 167 | + email = Griddler::Email.new(text: body, charsets: charsets) |
| 168 | + |
| 169 | + email.body.should == 'Hello.' |
| 170 | + end |
| 171 | + |
| 172 | + it "should preserve empty lines" do |
| 173 | + body = "Hello.\r\n\r\nWhat's up?" |
| 174 | + |
| 175 | + email = Griddler::Email.new(text: body) |
| 176 | + email.body.should == body |
| 177 | + end |
| 178 | + |
| 179 | + describe "extracting email address" do |
| 180 | + before do |
| 181 | + @address = "bob@example.com" |
| 182 | + end |
| 183 | + |
| 184 | + it "should handle normal e-mail address" do |
| 185 | + email = Griddler::Email.new(to: @address, from: @address) |
| 186 | + email.to.should == @address |
| 187 | + email.from.should == @address |
| 188 | + end |
| 189 | + |
| 190 | + it "should handle new lines" do |
| 191 | + email = Griddler::Email.new(to: "#{@address}\n", from: "#{@address}\n") |
| 192 | + email.to.should == @address |
| 193 | + email.from.should == @address |
| 194 | + end |
| 195 | + |
| 196 | + it "should handle angle brackets around address" do |
| 197 | + email = Griddler::Email.new(to: "<#{@address}>", from: "<#{@address}>") |
| 198 | + email.to.should == @address |
| 199 | + email.from.should == @address |
| 200 | + end |
| 201 | + |
| 202 | + it "should handle name and angle brackets around address" do |
| 203 | + email = Griddler::Email.new(to: "Bob <#{@address}>", from: "Bob <#{@address}>") |
| 204 | + email.to.should == @address |
| 205 | + email.from.should == @address |
| 206 | + end |
| 207 | + |
| 208 | + it "should handle multiple e-mails, with priority to the bracketed" do |
| 209 | + email = Griddler::Email.new(to: "fake@example.com <#{@address}>", from: "fake@example.com <#{@address}>") |
| 210 | + email.to.should == @address |
| 211 | + email.to.should == @address |
| 212 | + end |
| 213 | + end |
| 214 | +end |
0 commit comments