mahnve-vcard2alias 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +8 -0
- data/README.txt +48 -0
- data/Rakefile +16 -0
- data/bin/vcard2alias +9 -0
- data/lib/vcard2alias.rb +5 -0
- data/lib/vcard2alias_converter.rb +52 -0
- data/test/spec_vcard2alias_converter.rb +61 -0
- metadata +70 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= vcard2alias
|
2
|
+
|
3
|
+
http://github.com/mahnve/vcard2alias/tree/master
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Reads a list of vCards and extracts emailaddresses into a mutt alias file
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
*
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
vcard2alias <infile> > <outputfile>
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
Vpim
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
sudo gem install vcard2alias
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2008 Marcus Ahnve
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/vcard2alias.rb'
|
6
|
+
|
7
|
+
Hoe.new('vcard2alias', Vcard2alias::VERSION) do |p|
|
8
|
+
# p.rubyforge_name = 'vcard2aliasx' # if different than lowercase project name
|
9
|
+
p.developer('Marcus Ahnve', 'marcus@ahnve.com')
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Run all the fast tests"
|
13
|
+
task :test do
|
14
|
+
`bacon -Ilib --automatic --quiet test/*.rb`
|
15
|
+
end
|
16
|
+
|
data/bin/vcard2alias
ADDED
data/lib/vcard2alias.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'vpim/vcard'
|
2
|
+
|
3
|
+
class Vcard2aliasConverter
|
4
|
+
def convert(input)
|
5
|
+
result = []
|
6
|
+
cards = Vpim::Vcard.decode(input)
|
7
|
+
cards.each do |card|
|
8
|
+
nick = create_nick(card)
|
9
|
+
full_name = full_name(card)
|
10
|
+
card.emails.each do |email|
|
11
|
+
location = get_location(email)
|
12
|
+
result << create_alias_line(nick, location, full_name, email)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
result
|
16
|
+
end
|
17
|
+
|
18
|
+
def convert_and_print(input)
|
19
|
+
aliases = convert(input).inject do |result, line|
|
20
|
+
result << "\n" + line
|
21
|
+
end
|
22
|
+
puts aliases
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def create_alias_line(nick, location, full_name, email)
|
28
|
+
alias_line = "alias "
|
29
|
+
alias_line << nick
|
30
|
+
alias_line << location
|
31
|
+
alias_line << full_name
|
32
|
+
alias_line << ' '
|
33
|
+
alias_line << '<' + email + '>'
|
34
|
+
end
|
35
|
+
|
36
|
+
def full_name(card)
|
37
|
+
card.name.fullname ? " " + card.name.fullname : ""
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_location(email)
|
41
|
+
'-' << (email.location.first ? email.location.first : 'other')
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_nick(card)
|
45
|
+
nick = card.nickname ? card.nickname.downcase : fullname_appended(card)
|
46
|
+
end
|
47
|
+
|
48
|
+
def fullname_appended(card)
|
49
|
+
card.name.fullname.gsub(/\s/,'_').downcase
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'bacon'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/vcard2alias_converter'
|
3
|
+
|
4
|
+
describe 'vcard to alias converter' do
|
5
|
+
before do
|
6
|
+
addresses = <<-END
|
7
|
+
BEGIN:VCARD
|
8
|
+
VERSION:3.0
|
9
|
+
N:Usersson;User;;;
|
10
|
+
FN:User Usersson
|
11
|
+
EMAIL;type=INTERNET;type=WORK;type=pref:musersson@thoughtworks.com
|
12
|
+
EMAIL;type=INTERNET;type=HOME:user@usersson.com
|
13
|
+
item1.EMAIL;type=INTERNET:musersson@gmail.com
|
14
|
+
item1.X-ABLabel:_$!<Other>!$_
|
15
|
+
END:VCARD
|
16
|
+
BEGIN:VCARD
|
17
|
+
VERSION:3.0
|
18
|
+
N:Nickman;Nick;;;
|
19
|
+
FN:Nick Nickman
|
20
|
+
NICKNAME:Nickname
|
21
|
+
EMAIL;type=INTERNET;type=HOME;type=pref:nick@nick.com
|
22
|
+
END:VCARD
|
23
|
+
BEGIN:VCARD
|
24
|
+
VERSION:3.0
|
25
|
+
N:;;;;
|
26
|
+
FN:Agile Sweden
|
27
|
+
ORG:Agile Sweden;
|
28
|
+
EMAIL;type=INTERNET;type=WORK;type=pref:agile@agilesweden.org
|
29
|
+
EMAIL;type=INTERNET;type=WORK:agile@list.agilesweden.org
|
30
|
+
END:VCARD
|
31
|
+
END
|
32
|
+
|
33
|
+
converter = Vcard2aliasConverter.new
|
34
|
+
@result = converter.convert(addresses)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should start with alias' do
|
38
|
+
@result.first[0..4].should.equal 'alias'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should create nick from first name, last name and type of email address' do
|
42
|
+
@result.first[6..23].should.equal 'user_usersson-work'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should choose nickname if available' do
|
46
|
+
@result[3][6..18].should.equal 'nickname-home'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should set up full name if available' do
|
50
|
+
@result.first[25..37].should.equal 'User Usersson'
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should add email address' do
|
54
|
+
@result.first[39..66].should.equal '<musersson@thoughtworks.com>'
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should handle organizations' do
|
58
|
+
@result[4].should.equal 'alias agile_sweden-work Agile Sweden <agile@agilesweden.org>'
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mahnve-vcard2alias
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.2"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcus Ahnve
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-07 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: vpim
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.0.0
|
23
|
+
version:
|
24
|
+
description: With a file of vcards, convert all cards to mutt alias format
|
25
|
+
email: marcus@ahnve.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
34
|
+
files:
|
35
|
+
- History.txt
|
36
|
+
- Manifest.txt
|
37
|
+
- README.txt
|
38
|
+
- Rakefile
|
39
|
+
- bin/vcard2alias
|
40
|
+
- lib/vcard2alias.rb
|
41
|
+
- lib/vcard2alias_converter.rb
|
42
|
+
has_rdoc: false
|
43
|
+
homepage: http://github.com/mahnve/vcard2alias
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --main
|
47
|
+
- README.txt
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.2.0
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: Converts vcard file to mutt alias format
|
69
|
+
test_files:
|
70
|
+
- test/spec_vcard2alias_converter.rb
|