mailcvt 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,64 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  class LineConverter
4
- attr_reader :log
5
- @@keys = {
6
- 'D' => {full: 'Date:', begin: 5},
7
- 'M' => {full: 'Message-ID:', begin: 11},
8
- 'S' => {full: 'Subject:', begin: 8},
9
- 'F' => {full: 'From:', begin: 5},
10
- 'T' => {full: 'To:', begin: 3}
4
+ @@hkeys = {
5
+ 'D' => {key: 'Date:', begin: 5, id: 0},
6
+ 'M' => {key: 'Message-ID:', begin: 11, id: 1},
7
+ 'S' => {key: 'Subject:', begin: 8, id: 2},
8
+ 'F' => {key: 'From:', begin: 5, id: 3},
9
+ 'T' => {key: 'To:', begin: 3, id: 4}
11
10
  }
12
-
11
+ ATTACH = 'Content-Disposition: attachment; filename="'
12
+
13
13
  def initialize
14
- @log = ""
14
+ @hvals = Array.new(5, "")
15
+ @attach = ""
16
+ @stage = 0
17
+ end
18
+
19
+ def log
20
+ line = ""
21
+ @hvals.each {|v| line << "#{v}\t"}
22
+ line << @attach
23
+ end
24
+
25
+ def delimiter?(line)
26
+ if line == nil or line.empty? or line == "\n"
27
+ @stage += 1
28
+ return true
29
+ end
30
+ false
15
31
  end
16
32
 
17
33
  def convert(line)
18
- cap = line[0]
19
- return unless @@keys.has_key?(cap)
34
+ return if delimiter?(line)
35
+
36
+ cap = line[0]
37
+ if @stage == 0
38
+ convertheader(cap, line)
39
+ else
40
+ convertbody(cap, line)
41
+ end
42
+ end
43
+
44
+ def convertheader(cap, line)
45
+ if cap == "\t" or cap == ' '
46
+ @hvals[@hk[:id]] += "\a#{line.strip}" if @hk
47
+ else
48
+ if @@hkeys.has_key?(cap)
49
+ @hk = @@hkeys[cap]
50
+ @hvals[@hk[:id]] = line[@hk[:begin]..-1].strip if line.start_with?(@hk[:key])
51
+ else
52
+ @hk = nil
53
+ end
54
+ end
55
+ end
20
56
 
21
- key = @@keys[cap]
22
- @log << "#{line[key[:begin]..-1].strip}\t" if line.start_with?(key[:full])
57
+ def convertbody(cap, line)
58
+ if cap == 'C' and line.start_with?(ATTACH)
59
+ @attach << "\a" if not @attach.empty?
60
+ @attach << line[43..-3] # filename"\n
61
+ end
23
62
  end
24
63
  end
25
64
 
@@ -1,3 +1,3 @@
1
1
  module Mailcvt
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailcvt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-11 00:00:00.000000000 Z
12
+ date: 2013-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  segments:
114
114
  - 0
115
- hash: -2467422005071128305
115
+ hash: 2517497545800885469
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  segments:
123
123
  - 0
124
- hash: -2467422005071128305
124
+ hash: 2517497545800885469
125
125
  requirements: []
126
126
  rubyforge_project:
127
127
  rubygems_version: 1.8.25