adium2gmail 0.1.1

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.
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .DS_Store
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ .idea
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in Adium2Gmail.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 John Jiang
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # adium2gmail
2
+
3
+ Converts Adium chatlogs to gmail style emails.
4
+
5
+ ## Installation
6
+
7
+ Run:
8
+
9
+ $ gem install adium2gmail
10
+
11
+ ## Usage
12
+
13
+ Run:
14
+
15
+ $ adium2gmail -i --input <path> -o --output <path>
16
+
17
+ Open the file in Thunderbird to view all the chatlogs
18
+
19
+ ## TODO
20
+
21
+ 1. Multiprocessing of chatlogs to improve performance
22
+ 2. Handle group chats
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ require 'adium2gmail'
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs << 'test'
9
+ end
10
+
11
+ desc "Run tests"
12
+ task :default => :test
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/Adium2Gmail/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["John Jiang"]
6
+ gem.email = ["johnjiang101@gmail.com"]
7
+ gem.description = %q{Converts Adium chatlogs to emails}
8
+ gem.summary = %q{Creates gmail like emails from Adium chatlogs. This gem allows you to easily store all your chatlogs on gmail.}
9
+ gem.homepage = ""
10
+
11
+ gem.add_dependency('mail')
12
+ gem.add_dependency('nokogiri')
13
+ gem.add_dependency('trollop')
14
+
15
+ gem.add_development_dependency('rspec')
16
+
17
+ gem.files = `git ls-files`.split($\)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.name = "adium2gmail"
21
+ gem.require_paths = ["lib"]
22
+ gem.version = Adium2Gmail::VERSION
23
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'adium2gmail'
4
+ require 'Find'
5
+ require 'trollop'
6
+
7
+ opts = Trollop::options do
8
+ version "adium2gmail #{Adium2Gmail::VERSION}"
9
+ opt :output, "Output path", :short => 'o', :default => 'chatlogs'
10
+ opt :input, "Input path", :short => 'i', :default => File.expand_path('~/Library/Application Support/Adium 2.0/Users/Default/Logs')
11
+ end
12
+
13
+ Adium2Gmail::process_adium_chatlogs opts[:input], opts[:output]
@@ -0,0 +1,82 @@
1
+ require "adium2gmail/version"
2
+ require 'date'
3
+ require 'find'
4
+ require 'logger'
5
+ require 'mail'
6
+ require 'nokogiri'
7
+
8
+
9
+ module Adium2Gmail
10
+ LOGGER = Logger.new(STDOUT)
11
+
12
+ def self.create_email(from_email, to_email, f, chat_date)
13
+ LOGGER.info "Generating email from #{to_email} on #{chat_date}"
14
+ email_body = get_email_body f
15
+
16
+ mail = Mail.new do
17
+ from from_email
18
+ to to_email
19
+ subject "Chat with #{to_email}"
20
+
21
+ content_type 'text/html; charset=UTF-8'
22
+ body email_body
23
+ end
24
+ header = "From - " + chat_date.strftime("%a %b %d %H:%M:%S %Y")
25
+ header += "Date: " + chat_date.strftime("%a, %d %b %Y %H:%M:%S %z")
26
+ header + "\n" + mail.to_s.split("\n")[1..-1].join("\n") + "\n\n\n"
27
+ end
28
+
29
+ def self.get_email_body(f)
30
+ messages = ''
31
+
32
+ doc = Nokogiri::XML(File.open(f, "r"))
33
+
34
+ doc.remove_namespaces! #stupid namespaces
35
+
36
+ doc.xpath("//message").each do | message |
37
+ datetime = DateTime.parse(message.xpath("@time").text)
38
+ nickname = message.xpath("@alias").text
39
+ nickname = message.xpath("@sender").text if nickname.blank?
40
+
41
+ messages << create_message(datetime, nickname, message)
42
+ end
43
+
44
+ return messages
45
+ end
46
+
47
+ def self.create_message(date, nickname, message_tag)
48
+ time = date.strftime("%I:%M %p")
49
+
50
+ message_tag = message_tag.xpath("div/span")
51
+
52
+ #Not sure why I do the gsub here. I did it in python but didn't comment :(
53
+ #But I'm sure I did it for a good reason
54
+ message = message_tag.text.gsub("&apos;", "&#39;")
55
+
56
+ message_style = message_tag.xpath("@style").text
57
+
58
+ div = %Q{
59
+ <div><span style="display:block;float:left;color:#888">#{time}</span>
60
+ <span style="display:block;padding-left:6em">
61
+ <span style="#{message_style}">
62
+ <span style="font-weight:bold">#{nickname}:</span>
63
+ #{message}
64
+ </span>
65
+ </span>
66
+ </div>}
67
+ end
68
+
69
+ def self.process_adium_chatlogs(input, output_path)
70
+ File.open output_path, "w" do |output_file|
71
+ Find.find(input) do |f|
72
+ if f.match(/\.chatlog.*?\.xml\Z/) && ! f.include?("msn chat") #skipping multiple conversations for now
73
+ from_email = File.basename(File.dirname(File.dirname(File.dirname(f)))).sub(/.*?\./, "") #this is somewhat hacky...
74
+ to_email, chat_date = File.basename(f, ".xml").split()
75
+ chat_date = DateTime.parse(chat_date.gsub!(".", ":"))
76
+
77
+ output_file.puts create_email(from_email, to_email, f, chat_date)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ module Adium2Gmail
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,34 @@
1
+ require 'date'
2
+ require 'test/unit'
3
+
4
+ require 'nokogiri'
5
+
6
+ require 'adium2gmail'
7
+
8
+ class TestAdium2Gmail < Test::Unit::TestCase
9
+
10
+ def test_create_message
11
+ current_time = DateTime.parse("2012/04/12 09:30")
12
+ nickname = "Test"
13
+ message_tag = Nokogiri::XML("<div><span style='bold'>test message</span></div>")
14
+
15
+ message = Adium2Gmail.create_message current_time, nickname, message_tag
16
+
17
+ target_result = %q{
18
+ <div><span style="display:block;float:left;color:#888">09:30 AM</span>
19
+ <span style="display:block;padding-left:6em">
20
+ <span style="bold">
21
+ <span style="font-weight:bold">Test:</span>
22
+ test message
23
+ </span>
24
+ </span>
25
+ </div>}
26
+
27
+ assert_equal message.gsub(/\s+/, ""), target_result.gsub(/\s+/, "")
28
+ end
29
+
30
+ def test_create_email
31
+
32
+ end
33
+
34
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adium2gmail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Jiang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mail
16
+ requirement: &70149383353760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70149383353760
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ requirement: &70149383353100 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70149383353100
36
+ - !ruby/object:Gem::Dependency
37
+ name: trollop
38
+ requirement: &70149383352140 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70149383352140
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70149383351600 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70149383351600
58
+ description: Converts Adium chatlogs to emails
59
+ email:
60
+ - johnjiang101@gmail.com
61
+ executables:
62
+ - adium2gmail
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - .travis.yml
68
+ - Gemfile
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - adium2gmail.gemspec
73
+ - bin/adium2gmail
74
+ - lib/adium2gmail.rb
75
+ - lib/adium2gmail/version.rb
76
+ - test/test_adium2gmail.rb
77
+ homepage: ''
78
+ licenses: []
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.15
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Creates gmail like emails from Adium chatlogs. This gem allows you to easily
101
+ store all your chatlogs on gmail.
102
+ test_files:
103
+ - test/test_adium2gmail.rb