mailcvt 0.0.5 → 0.0.6
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/lib/line_converter.rb +52 -13
 - data/lib/mailcvt/version.rb +1 -1
 - metadata +4 -4
 
    
        data/lib/line_converter.rb
    CHANGED
    
    | 
         @@ -1,25 +1,64 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #!/usr/bin/env ruby
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class LineConverter
         
     | 
| 
       4 
     | 
    
         
            -
                 
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
                    ' 
     | 
| 
       7 
     | 
    
         
            -
                    ' 
     | 
| 
       8 
     | 
    
         
            -
                    ' 
     | 
| 
       9 
     | 
    
         
            -
                    ' 
     | 
| 
       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 
     | 
    
         
            -
                    @ 
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         | 
    
        data/lib/mailcvt/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 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:  
     | 
| 
      
 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:  
     | 
| 
      
 124 
     | 
    
         
            +
                  hash: 2517497545800885469
         
     | 
| 
       125 
125 
     | 
    
         
             
            requirements: []
         
     | 
| 
       126 
126 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       127 
127 
     | 
    
         
             
            rubygems_version: 1.8.25
         
     |