galakei 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/galakei/email.rb CHANGED
@@ -37,6 +37,10 @@ module Galakei::Email
37
37
  node.name = "div"
38
38
  node.after("<br />")
39
39
  end
40
+ #empty the <head>
41
+ doc.css("head").each do |node|
42
+ node.unlink
43
+ end
40
44
  encoding = doc.meta_encoding || "UTF-8"
41
45
  res = "<html><head>"
42
46
  res << "<meta http-equiv=\"Content-type\" content=\"text/html;charset=#{encoding}\" />"
@@ -1,3 +1,3 @@
1
1
  module Galakei
2
- VERSION = "0.11.0"
2
+ VERSION = "0.11.1"
3
3
  end
@@ -1,36 +1,80 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'spec_helper'
3
3
 
4
+ MSG=<<EOT
5
+ <html>
6
+ <head>
7
+ <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
8
+ <title> This is mytitle </title>
9
+ </head>
10
+ <body bgcolor="#FFFF00">
11
+ <h1>A first level heading
12
+ </h1
13
+ <h3>A third level heading
14
+ </h3>
15
+ <blink> A BLINKING TITLE
16
+ </blink>
17
+ A table
18
+ <table>
19
+ <tr><td>Cell top left</td><td>Cell top right</td></tr>
20
+ <tr><td>Cell bot left</td><td>Cell bot right</td></tr>
21
+ </table>
22
+ <marquee behaviour="scroll"> HELLO mailworld I'm a marquee
23
+ </marquee>
24
+ <div align="left">
25
+ 左側
26
+ </div>
27
+ <hr color="#0000FF">
28
+ <div align="center">
29
+ ど真ん中
30
+ </div>
31
+ <div style="text-align:center;">
32
+ </div>
33
+ <hr color="#FF0000">
34
+ <div align="right">
35
+ 右側
36
+ </div>
37
+ こんにちは世界!ばあばばばあ
38
+ </body>
39
+ <br/>
40
+ <font size=4 color="#009900">
41
+ GREEEEEEN
42
+ </font>
43
+ <a href="http://dragonmobile.nuancemobiledeveloper.com/"><img src="cid:image-attachment-id" alt=""/></a>this was an image
44
+ <br/>
45
+ And now, <a href="ftp://some.ftpsite.com/">Downloadz youz warez herez!</a>
46
+ </html>
47
+ EOT
48
+
4
49
  describe Galakei::Email do
50
+ let(:sanitized_mail){ Galakei::Email.to_galakei_email(MSG) }
5
51
 
6
- it "should not have h tags" do
7
- html_email = '<h1>Email big heading</h1><h2>Second heading</h2><h6>Sixth heading</h6>'
8
- Galakei::Email.to_galakei_email(html_email).should_not =~ /<h[0-9]>/
52
+ it "should have a html, head, meta and body" do
53
+ sanitized_mail.should =~ /html.*head.*meta.*body/m
9
54
  end
10
55
 
11
- it "should have images with cid" do
12
- html_email='<a href="http://dragonmobile.nuancemobiledeveloper.com/"><img src="cid:image-attachment-id" alt=""/></a>this was an image'
13
- Galakei::Email.to_galakei_email(html_email).should =~ /img.*cid/m
56
+ it "should have supported tags and styles" do
57
+ sanitized_mail.should =~ /<div align=/m
58
+ sanitized_mail.should =~ /<hr color=/m
59
+ sanitized_mail.should =~ /<font size=.*color=/m
60
+ sanitized_mail.should =~ /<br>/m
61
+ sanitized_mail.should =~ /<blink>/m
62
+ sanitized_mail.should =~ /<marquee behaviour=/m
63
+ sanitized_mail.should =~ /<img src=.*cid/m
64
+ sanitized_mail.should =~ /<a href=/m
14
65
  end
15
-
16
- it "should not have unsupported protocols" do
17
- html_email='<a href="ftp://some.ftpsite.com/">Downloadz youz warez herez</a> Monsieur'
18
- Galakei::Email.to_galakei_email(html_email).should_not =~ /ftpsite/
66
+
67
+ it "should not have h and table tags" do
68
+ sanitized_mail.should_not =~ /<h[0-9]>/
69
+ sanitized_mail.should_not =~ /<table>/
19
70
  end
20
71
 
21
- it "should have a html, head, meta and body" do
22
- html_email='<html><head><meta http-equiv="Content-type" content="text/html;charset=UTF-8"" ><title>Document X</title><head><body>I am a body!</body></html>'
23
- Galakei::Email.to_galakei_email(html_email).should =~ /html.*head.*meta.*body/m
24
- end
25
-
26
- it "should have div,href,br,hr elements" do
27
- html_email='<div align="center"><a href="http://dragonmobile.nuancemobiledeveloper.com/"><img src="http://www.mobilemonday.jp/wp-content/uploads/2011/01/NMDP.jpg" alt=""></a></div><hr color="blue"> <br><div class="register_button"><a href="http://gigs.checkin.local:3000/events/2/tickets/new?auth_token=demo">Register</a></div>'
28
- Galakei::Email.to_galakei_email(html_email).should =~ /div(.*)align(.*)href(.*)hr(.*)blue(.*)br/m
72
+ it "should not have unsupported protocols" do
73
+ sanitized_mail.should_not =~ /ftpsite/
29
74
  end
30
75
 
31
- it "should allow font, blink and marquee elements" do
32
- html_email='<div align="center"><font size="2" color="red">NEWS FLASH</font><blink>plink plink plink the nineties!</blink><marquee behaviour="scroll">This is corn!</marquee></div>'
33
- Galakei::Email.to_galakei_email(html_email).should =~ /font(.*)size(.*)color(.*)blink(.*)marquee(.*)behaviour/m
34
- end
76
+ it "should not have title" do
77
+ sanitized_mail.should_not =~ /mytitle/
78
+ end
35
79
 
36
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: galakei
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-09-14 00:00:00.000000000Z
14
+ date: 2011-09-15 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: actionpack
18
- requirement: &70278177590600 !ruby/object:Gem::Requirement
18
+ requirement: &70175966516740 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 3.0.3
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70278177590600
26
+ version_requirements: *70175966516740
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack
29
- requirement: &70278177589740 !ruby/object:Gem::Requirement
29
+ requirement: &70175966515520 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 1.2.1
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70278177589740
37
+ version_requirements: *70175966515520
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: css_parser
40
- requirement: &70278177589060 !ruby/object:Gem::Requirement
40
+ requirement: &70175966514940 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0'
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *70278177589060
48
+ version_requirements: *70175966514940
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: nokogiri
51
- requirement: &70278177588420 !ruby/object:Gem::Requirement
51
+ requirement: &70175966514340 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0'
57
57
  type: :runtime
58
58
  prerelease: false
59
- version_requirements: *70278177588420
59
+ version_requirements: *70175966514340
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: sanitize
62
- requirement: &70278177587560 !ruby/object:Gem::Requirement
62
+ requirement: &70175966513600 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,7 +67,7 @@ dependencies:
67
67
  version: '0'
68
68
  type: :runtime
69
69
  prerelease: false
70
- version_requirements: *70278177587560
70
+ version_requirements: *70175966513600
71
71
  description: Japanese feature phones (a.k.a., keitai, galakei) have a number of restrictions
72
72
  over normal web browsers. This library adds support for them
73
73
  email: info@mobalean.com