skaar-daemon-kit 0.1.7.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/Configuration.txt +110 -0
  2. data/Deployment.txt +113 -0
  3. data/History.txt +97 -0
  4. data/Logging.txt +92 -0
  5. data/Manifest.txt +174 -0
  6. data/PostInstall.txt +6 -0
  7. data/README.rdoc +130 -0
  8. data/Rakefile +37 -0
  9. data/RuoteParticipants.txt +113 -0
  10. data/TODO.txt +37 -0
  11. data/app_generators/daemon_kit/USAGE +7 -0
  12. data/app_generators/daemon_kit/daemon_kit_generator.rb +178 -0
  13. data/app_generators/daemon_kit/templates/README +48 -0
  14. data/app_generators/daemon_kit/templates/Rakefile +6 -0
  15. data/app_generators/daemon_kit/templates/bin/daemon.erb +7 -0
  16. data/app_generators/daemon_kit/templates/config/arguments.rb +12 -0
  17. data/app_generators/daemon_kit/templates/config/boot.rb +68 -0
  18. data/app_generators/daemon_kit/templates/config/environment.rb +23 -0
  19. data/app_generators/daemon_kit/templates/config/environments/development.rb +2 -0
  20. data/app_generators/daemon_kit/templates/config/environments/production.rb +2 -0
  21. data/app_generators/daemon_kit/templates/config/environments/test.rb +2 -0
  22. data/app_generators/daemon_kit/templates/config/post-daemonize/readme +5 -0
  23. data/app_generators/daemon_kit/templates/config/pre-daemonize/readme +12 -0
  24. data/app_generators/daemon_kit/templates/lib/daemon.rb +2 -0
  25. data/app_generators/daemon_kit/templates/libexec/daemon.erb +18 -0
  26. data/app_generators/daemon_kit/templates/script/console +3 -0
  27. data/app_generators/daemon_kit/templates/script/destroy +14 -0
  28. data/app_generators/daemon_kit/templates/script/generate +14 -0
  29. data/bin/daemon_kit +18 -0
  30. data/daemon_generators/amqp/USAGE +5 -0
  31. data/daemon_generators/amqp/amqp_generator.rb +65 -0
  32. data/daemon_generators/amqp/templates/config/amqp.yml +28 -0
  33. data/daemon_generators/amqp/templates/config/initializers/amqp.rb +7 -0
  34. data/daemon_generators/amqp/templates/libexec/daemon.rb +37 -0
  35. data/daemon_generators/cron/USAGE +5 -0
  36. data/daemon_generators/cron/cron_generator.rb +64 -0
  37. data/daemon_generators/cron/templates/config/initializers/cron.rb +11 -0
  38. data/daemon_generators/cron/templates/libexec/daemon.rb +43 -0
  39. data/daemon_generators/cucumber/USAGE +11 -0
  40. data/daemon_generators/cucumber/cucumber_generator.rb +38 -0
  41. data/daemon_generators/cucumber/templates/cucumber +8 -0
  42. data/daemon_generators/cucumber/templates/cucumber.rake +13 -0
  43. data/daemon_generators/cucumber/templates/cucumber_environment.rb +2 -0
  44. data/daemon_generators/cucumber/templates/env.rb +7 -0
  45. data/daemon_generators/deploy_capistrano/deploy_capistrano_generator.rb +35 -0
  46. data/daemon_generators/deploy_capistrano/templates/Capfile +10 -0
  47. data/daemon_generators/deploy_capistrano/templates/USAGE +10 -0
  48. data/daemon_generators/deploy_capistrano/templates/config/deploy.rb +53 -0
  49. data/daemon_generators/deploy_capistrano/templates/config/deploy/production.rb +6 -0
  50. data/daemon_generators/deploy_capistrano/templates/config/deploy/staging.rb +6 -0
  51. data/daemon_generators/deploy_capistrano/templates/config/environments/staging.rb +0 -0
  52. data/daemon_generators/jabber/USAGE +5 -0
  53. data/daemon_generators/jabber/jabber_generator.rb +65 -0
  54. data/daemon_generators/jabber/templates/config/initializers/jabber.rb +7 -0
  55. data/daemon_generators/jabber/templates/config/jabber.yml +26 -0
  56. data/daemon_generators/jabber/templates/libexec/daemon.rb +27 -0
  57. data/daemon_generators/nanite_agent/USAGE +5 -0
  58. data/daemon_generators/nanite_agent/nanite_agent_generator.rb +68 -0
  59. data/daemon_generators/nanite_agent/templates/config/initializers/nanite_agent.rb +6 -0
  60. data/daemon_generators/nanite_agent/templates/config/nanite.yml +35 -0
  61. data/daemon_generators/nanite_agent/templates/lib/actors/sample.rb +11 -0
  62. data/daemon_generators/nanite_agent/templates/libexec/daemon.rb +31 -0
  63. data/daemon_generators/rspec/USAGE +5 -0
  64. data/daemon_generators/rspec/rspec_generator.rb +55 -0
  65. data/daemon_generators/rspec/templates/spec.rb +11 -0
  66. data/daemon_generators/rspec/templates/spec/spec.opts +1 -0
  67. data/daemon_generators/rspec/templates/spec/spec_helper.rb +21 -0
  68. data/daemon_generators/rspec/templates/tasks/rspec.rake +21 -0
  69. data/daemon_generators/ruote/USAGE +5 -0
  70. data/daemon_generators/ruote/ruote_generator.rb +67 -0
  71. data/daemon_generators/ruote/templates/config/amqp.yml +30 -0
  72. data/daemon_generators/ruote/templates/config/initializers/ruote.rb +13 -0
  73. data/daemon_generators/ruote/templates/config/ruote.yml +23 -0
  74. data/daemon_generators/ruote/templates/lib/daemon.rb +4 -0
  75. data/daemon_generators/ruote/templates/lib/sample.rb +26 -0
  76. data/daemon_generators/ruote/templates/libexec/daemon.rb +33 -0
  77. data/lib/daemon_kit.rb +62 -0
  78. data/lib/daemon_kit/abstract_logger.rb +235 -0
  79. data/lib/daemon_kit/amqp.rb +38 -0
  80. data/lib/daemon_kit/application.rb +187 -0
  81. data/lib/daemon_kit/arguments.rb +165 -0
  82. data/lib/daemon_kit/commands/console.rb +38 -0
  83. data/lib/daemon_kit/config.rb +108 -0
  84. data/lib/daemon_kit/console_daemon.rb +2 -0
  85. data/lib/daemon_kit/core_ext.rb +1 -0
  86. data/lib/daemon_kit/core_ext/configurable.rb +96 -0
  87. data/lib/daemon_kit/core_ext/string.rb +22 -0
  88. data/lib/daemon_kit/cron.rb +48 -0
  89. data/lib/daemon_kit/cucumber/world.rb +38 -0
  90. data/lib/daemon_kit/deployment/capistrano.rb +482 -0
  91. data/lib/daemon_kit/em.rb +43 -0
  92. data/lib/daemon_kit/error_handlers/base.rb +32 -0
  93. data/lib/daemon_kit/error_handlers/hoptoad.rb +61 -0
  94. data/lib/daemon_kit/error_handlers/mail.rb +85 -0
  95. data/lib/daemon_kit/exceptions.rb +15 -0
  96. data/lib/daemon_kit/initializer.rb +438 -0
  97. data/lib/daemon_kit/jabber.rb +170 -0
  98. data/lib/daemon_kit/nanite.rb +7 -0
  99. data/lib/daemon_kit/nanite/agent.rb +56 -0
  100. data/lib/daemon_kit/pid_file.rb +61 -0
  101. data/lib/daemon_kit/ruote_participants.rb +119 -0
  102. data/lib/daemon_kit/ruote_pseudo_participant.rb +68 -0
  103. data/lib/daemon_kit/ruote_workitem.rb +169 -0
  104. data/lib/daemon_kit/safety.rb +85 -0
  105. data/lib/daemon_kit/tasks.rb +2 -0
  106. data/lib/daemon_kit/tasks/environment.rake +10 -0
  107. data/lib/daemon_kit/tasks/framework.rake +120 -0
  108. data/lib/daemon_kit/tasks/god.rake +62 -0
  109. data/lib/daemon_kit/tasks/log.rake +8 -0
  110. data/lib/daemon_kit/tasks/monit.rake +29 -0
  111. data/script/console +10 -0
  112. data/script/destroy +14 -0
  113. data/script/generate +14 -0
  114. data/script/txt2html +71 -0
  115. data/spec/abstract_logger_spec.rb +126 -0
  116. data/spec/argument_spec.rb +70 -0
  117. data/spec/config_spec.rb +79 -0
  118. data/spec/configurable_spec.rb +56 -0
  119. data/spec/daemon_kit_spec.rb +7 -0
  120. data/spec/error_handlers_spec.rb +23 -0
  121. data/spec/fixtures/env.yml +15 -0
  122. data/spec/fixtures/noenv.yml +4 -0
  123. data/spec/initializer_spec.rb +26 -0
  124. data/spec/spec.opts +1 -0
  125. data/spec/spec_helper.rb +27 -0
  126. data/tasks/rspec.rake +21 -0
  127. data/templates/god/god.erb +69 -0
  128. data/templates/monit/monit.erb +14 -0
  129. data/test/test_amqp_generator.rb +48 -0
  130. data/test/test_cron_generator.rb +45 -0
  131. data/test/test_daemon-kit_generator.rb +84 -0
  132. data/test/test_daemon_kit_config.rb +28 -0
  133. data/test/test_deploy_capistrano_generator.rb +48 -0
  134. data/test/test_generator_helper.rb +29 -0
  135. data/test/test_helper.rb +7 -0
  136. data/test/test_jabber_generator.rb +49 -0
  137. data/test/test_nanite_agent_generator.rb +49 -0
  138. data/test/test_ruote_generator.rb +45 -0
  139. data/vendor/tmail-1.2.3/tmail.rb +5 -0
  140. data/vendor/tmail-1.2.3/tmail/address.rb +426 -0
  141. data/vendor/tmail-1.2.3/tmail/attachments.rb +46 -0
  142. data/vendor/tmail-1.2.3/tmail/base64.rb +46 -0
  143. data/vendor/tmail-1.2.3/tmail/compat.rb +41 -0
  144. data/vendor/tmail-1.2.3/tmail/config.rb +67 -0
  145. data/vendor/tmail-1.2.3/tmail/core_extensions.rb +63 -0
  146. data/vendor/tmail-1.2.3/tmail/encode.rb +581 -0
  147. data/vendor/tmail-1.2.3/tmail/header.rb +960 -0
  148. data/vendor/tmail-1.2.3/tmail/index.rb +9 -0
  149. data/vendor/tmail-1.2.3/tmail/interface.rb +1130 -0
  150. data/vendor/tmail-1.2.3/tmail/loader.rb +3 -0
  151. data/vendor/tmail-1.2.3/tmail/mail.rb +578 -0
  152. data/vendor/tmail-1.2.3/tmail/mailbox.rb +495 -0
  153. data/vendor/tmail-1.2.3/tmail/main.rb +6 -0
  154. data/vendor/tmail-1.2.3/tmail/mbox.rb +3 -0
  155. data/vendor/tmail-1.2.3/tmail/net.rb +248 -0
  156. data/vendor/tmail-1.2.3/tmail/obsolete.rb +132 -0
  157. data/vendor/tmail-1.2.3/tmail/parser.rb +1476 -0
  158. data/vendor/tmail-1.2.3/tmail/port.rb +379 -0
  159. data/vendor/tmail-1.2.3/tmail/quoting.rb +118 -0
  160. data/vendor/tmail-1.2.3/tmail/require_arch.rb +58 -0
  161. data/vendor/tmail-1.2.3/tmail/scanner.rb +49 -0
  162. data/vendor/tmail-1.2.3/tmail/scanner_r.rb +261 -0
  163. data/vendor/tmail-1.2.3/tmail/stringio.rb +280 -0
  164. data/vendor/tmail-1.2.3/tmail/utils.rb +337 -0
  165. data/vendor/tmail-1.2.3/tmail/version.rb +39 -0
  166. data/vendor/tmail.rb +13 -0
  167. metadata +282 -0
@@ -0,0 +1,29 @@
1
+ begin
2
+ require File.dirname(__FILE__) + '/test_helper'
3
+ rescue LoadError
4
+ require 'test/unit'
5
+ end
6
+ require 'fileutils'
7
+
8
+ # Must set before requiring generator libs.
9
+ TMP_ROOT = File.dirname(__FILE__) + "/tmp" unless defined?(TMP_ROOT)
10
+ PROJECT_NAME = "myproject" unless defined?(PROJECT_NAME)
11
+ app_root = File.join(TMP_ROOT, PROJECT_NAME)
12
+ if defined?(APP_ROOT)
13
+ APP_ROOT.replace(app_root)
14
+ else
15
+ APP_ROOT = app_root
16
+ end
17
+ if defined?(RAILS_ROOT)
18
+ RAILS_ROOT.replace(app_root)
19
+ else
20
+ RAILS_ROOT = app_root
21
+ end
22
+
23
+ begin
24
+ require 'rubigen'
25
+ rescue LoadError
26
+ require 'rubygems'
27
+ require 'rubigen'
28
+ end
29
+ require 'rubigen/helpers/generator_test_helper'
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+
3
+ DAEMON_ENV = "test"
4
+
5
+ require File.dirname(__FILE__) + '/../lib/daemon_kit'
6
+
7
+
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
2
+
3
+
4
+ class TestJabberGenerator < Test::Unit::TestCase
5
+ include RubiGen::GeneratorTestHelper
6
+
7
+ def setup
8
+ bare_setup
9
+ end
10
+
11
+ def teardown
12
+ bare_teardown
13
+ end
14
+
15
+ # Some generator-related assertions:
16
+ # assert_generated_file(name, &block) # block passed the file contents
17
+ # assert_directory_exists(name)
18
+ # assert_generated_class(name, &block)
19
+ # assert_generated_module(name, &block)
20
+ # assert_generated_test_for(name, &block)
21
+ # The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
22
+ # assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
23
+ #
24
+ # Other helper methods are:
25
+ # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
26
+ # bare_setup - place this in setup method to create the APP_ROOT folder for each test
27
+ # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
28
+
29
+ def test_generator_without_options
30
+ name = "myapp"
31
+ run_generator('jabber', [name], sources)
32
+ assert_directory_exists "config"
33
+ assert_generated_file "config/jabber.yml"
34
+ assert_directory_exists "config/initializers"
35
+ assert_generated_file "config/initializers/myapp.rb"
36
+ assert_directory_exists "libexec"
37
+ assert_generated_file "libexec/myapp-daemon.rb"
38
+ end
39
+
40
+ private
41
+ def sources
42
+ [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
43
+ ]
44
+ end
45
+
46
+ def generator_path
47
+ "daemon_generators"
48
+ end
49
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
2
+
3
+
4
+ class TestNaniteAgentGenerator < Test::Unit::TestCase
5
+ include RubiGen::GeneratorTestHelper
6
+
7
+ def setup
8
+ bare_setup
9
+ end
10
+
11
+ def teardown
12
+ bare_teardown
13
+ end
14
+
15
+ # Some generator-related assertions:
16
+ # assert_generated_file(name, &block) # block passed the file contents
17
+ # assert_directory_exists(name)
18
+ # assert_generated_class(name, &block)
19
+ # assert_generated_module(name, &block)
20
+ # assert_generated_test_for(name, &block)
21
+ # The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
22
+ # assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
23
+ #
24
+ # Other helper methods are:
25
+ # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
26
+ # bare_setup - place this in setup method to create the APP_ROOT folder for each test
27
+ # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
28
+
29
+ def test_generator_without_options
30
+ name = "myapp"
31
+ run_generator('nanite_agent', [name], sources)
32
+ assert_directory_exists "lib/actors"
33
+ assert_generated_file "lib/actors/sample.rb"
34
+ assert_directory_exists "config"
35
+ assert_generated_file "config/nanite.yml"
36
+ assert_directory_exists "config/initializers"
37
+ assert_generated_file "config/initializers/myapp.rb"
38
+ end
39
+
40
+ private
41
+ def sources
42
+ [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
43
+ ]
44
+ end
45
+
46
+ def generator_path
47
+ "daemon_generators"
48
+ end
49
+ end
@@ -0,0 +1,45 @@
1
+ require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
2
+
3
+
4
+ class TestRuoteGenerator < Test::Unit::TestCase
5
+ include RubiGen::GeneratorTestHelper
6
+
7
+ def setup
8
+ bare_setup
9
+ end
10
+
11
+ def teardown
12
+ bare_teardown
13
+ end
14
+
15
+ # Some generator-related assertions:
16
+ # assert_generated_file(name, &block) # block passed the file contents
17
+ # assert_directory_exists(name)
18
+ # assert_generated_class(name, &block)
19
+ # assert_generated_module(name, &block)
20
+ # assert_generated_test_for(name, &block)
21
+ # The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
22
+ # assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
23
+ #
24
+ # Other helper methods are:
25
+ # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
26
+ # bare_setup - place this in setup method to create the APP_ROOT folder for each test
27
+ # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
28
+
29
+ def test_generator_without_options
30
+ name = "myapp"
31
+ run_generator('ruote', [name], sources)
32
+ assert_directory_exists "some/directory"
33
+ assert_generated_file "some_file"
34
+ end
35
+
36
+ private
37
+ def sources
38
+ [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
39
+ ]
40
+ end
41
+
42
+ def generator_path
43
+ "daemon_generators"
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ require 'tmail/version'
2
+ require 'tmail/mail'
3
+ require 'tmail/mailbox'
4
+ require 'tmail/core_extensions'
5
+ require 'tmail/net'
@@ -0,0 +1,426 @@
1
+ =begin rdoc
2
+
3
+ = Address handling class
4
+
5
+ =end
6
+ #--
7
+ # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
8
+ #
9
+ # Permission is hereby granted, free of charge, to any person obtaining
10
+ # a copy of this software and associated documentation files (the
11
+ # "Software"), to deal in the Software without restriction, including
12
+ # without limitation the rights to use, copy, modify, merge, publish,
13
+ # distribute, sublicense, and/or sell copies of the Software, and to
14
+ # permit persons to whom the Software is furnished to do so, subject to
15
+ # the following conditions:
16
+ #
17
+ # The above copyright notice and this permission notice shall be
18
+ # included in all copies or substantial portions of the Software.
19
+ #
20
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ #
28
+ # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
29
+ # with permission of Minero Aoki.
30
+ #++
31
+
32
+ require 'tmail/encode'
33
+ require 'tmail/parser'
34
+
35
+
36
+ module TMail
37
+
38
+ # = Class Address
39
+ #
40
+ # Provides a complete handling library for email addresses. Can parse a string of an
41
+ # address directly or take in preformatted addresses themselves. Allows you to add
42
+ # and remove phrases from the front of the address and provides a compare function for
43
+ # email addresses.
44
+ #
45
+ # == Parsing and Handling a Valid Address:
46
+ #
47
+ # Just pass the email address in as a string to Address.parse:
48
+ #
49
+ # email = TMail::Address.parse('Mikel Lindsaar <mikel@lindsaar.net>)
50
+ # #=> #<TMail::Address mikel@lindsaar.net>
51
+ # email.address
52
+ # #=> "mikel@lindsaar.net"
53
+ # email.local
54
+ # #=> "mikel"
55
+ # email.domain
56
+ # #=> "lindsaar.net"
57
+ # email.name # Aliased as phrase as well
58
+ # #=> "Mikel Lindsaar"
59
+ #
60
+ # == Detecting an Invalid Address
61
+ #
62
+ # If you want to check the syntactical validity of an email address, just pass it to
63
+ # Address.parse and catch any SyntaxError:
64
+ #
65
+ # begin
66
+ # TMail::Mail.parse("mikel 2@@@@@ me .com")
67
+ # rescue TMail::SyntaxError
68
+ # puts("Invalid Email Address Detected")
69
+ # else
70
+ # puts("Address is valid")
71
+ # end
72
+ # #=> "Invalid Email Address Detected"
73
+ class Address
74
+
75
+ include TextUtils #:nodoc:
76
+
77
+ # Sometimes you need to parse an address, TMail can do it for you and provide you with
78
+ # a fairly robust method of detecting a valid address.
79
+ #
80
+ # Takes in a string, returns a TMail::Address object.
81
+ #
82
+ # Raises a TMail::SyntaxError on invalid email format
83
+ def Address.parse( str )
84
+ Parser.parse :ADDRESS, special_quote_address(str)
85
+ end
86
+
87
+ def Address.special_quote_address(str) #:nodoc:
88
+ # Takes a string which is an address and adds quotation marks to special
89
+ # edge case methods that the RACC parser can not handle.
90
+ #
91
+ # Right now just handles two edge cases:
92
+ #
93
+ # Full stop as the last character of the display name:
94
+ # Mikel L. <mikel@me.com>
95
+ # Returns:
96
+ # "Mikel L." <mikel@me.com>
97
+ #
98
+ # Unquoted @ symbol in the display name:
99
+ # mikel@me.com <mikel@me.com>
100
+ # Returns:
101
+ # "mikel@me.com" <mikel@me.com>
102
+ #
103
+ # Any other address not matching these patterns just gets returned as is.
104
+ case
105
+ # This handles the missing "" in an older version of Apple Mail.app
106
+ # around the display name when the display name contains a '@'
107
+ # like 'mikel@me.com <mikel@me.com>'
108
+ # Just quotes it to: '"mikel@me.com" <mikel@me.com>'
109
+ when str =~ /\A([^"].+@.+[^"])\s(<.*?>)\Z/
110
+ return "\"#{$1}\" #{$2}"
111
+ # This handles cases where 'Mikel A. <mikel@me.com>' which is a trailing
112
+ # full stop before the address section. Just quotes it to
113
+ # '"Mikel A. <mikel@me.com>"
114
+ when str =~ /\A(.*?\.)\s(<.*?>)\Z/
115
+ return "\"#{$1}\" #{$2}"
116
+ else
117
+ str
118
+ end
119
+ end
120
+
121
+ def address_group? #:nodoc:
122
+ false
123
+ end
124
+
125
+ # Address.new(local, domain)
126
+ #
127
+ # Accepts:
128
+ #
129
+ # * local - Left of the at symbol
130
+ #
131
+ # * domain - Array of the domain split at the periods.
132
+ #
133
+ # For example:
134
+ #
135
+ # Address.new("mikel", ["lindsaar", "net"])
136
+ # #=> "#<TMail::Address mikel@lindsaar.net>"
137
+ def initialize( local, domain )
138
+ if domain
139
+ domain.each do |s|
140
+ raise SyntaxError, 'empty word in domain' if s.empty?
141
+ end
142
+ end
143
+
144
+ # This is to catch an unquoted "@" symbol in the local part of the
145
+ # address. Handles addresses like <"@"@me.com> and makes sure they
146
+ # stay like <"@"@me.com> (previously were becoming <@@me.com>)
147
+ if local && (local.join == '@' || local.join =~ /\A[^"].*?@.*?[^"]\Z/)
148
+ @local = "\"#{local.join}\""
149
+ else
150
+ @local = local
151
+ end
152
+
153
+ @domain = domain
154
+ @name = nil
155
+ @routes = []
156
+ end
157
+
158
+ # Provides the name or 'phrase' of the email address.
159
+ #
160
+ # For Example:
161
+ #
162
+ # email = TMail::Address.parse("Mikel Lindsaar <mikel@lindsaar.net>")
163
+ # email.name
164
+ # #=> "Mikel Lindsaar"
165
+ def name
166
+ @name
167
+ end
168
+
169
+ # Setter method for the name or phrase of the email
170
+ #
171
+ # For Example:
172
+ #
173
+ # email = TMail::Address.parse("mikel@lindsaar.net")
174
+ # email.name
175
+ # #=> nil
176
+ # email.name = "Mikel Lindsaar"
177
+ # email.to_s
178
+ # #=> "Mikel Lindsaar <mikel@me.com>"
179
+ def name=( str )
180
+ @name = str
181
+ @name = nil if str and str.empty?
182
+ end
183
+
184
+ #:stopdoc:
185
+ alias phrase name
186
+ alias phrase= name=
187
+ #:startdoc:
188
+
189
+ # This is still here from RFC 822, and is now obsolete per RFC2822 Section 4.
190
+ #
191
+ # "When interpreting addresses, the route portion SHOULD be ignored."
192
+ #
193
+ # It is still here, so you can access it.
194
+ #
195
+ # Routes return the route portion at the front of the email address, if any.
196
+ #
197
+ # For Example:
198
+ # email = TMail::Address.parse( "<@sa,@another:Mikel@me.com>")
199
+ # => #<TMail::Address Mikel@me.com>
200
+ # email.to_s
201
+ # => "<@sa,@another:Mikel@me.com>"
202
+ # email.routes
203
+ # => ["sa", "another"]
204
+ def routes
205
+ @routes
206
+ end
207
+
208
+ def inspect #:nodoc:
209
+ "#<#{self.class} #{address()}>"
210
+ end
211
+
212
+ # Returns the local part of the email address
213
+ #
214
+ # For Example:
215
+ #
216
+ # email = TMail::Address.parse("mikel@lindsaar.net")
217
+ # email.local
218
+ # #=> "mikel"
219
+ def local
220
+ return nil unless @local
221
+ return '""' if @local.size == 1 and @local[0].empty?
222
+ # Check to see if it is an array before trying to map it
223
+ if @local.respond_to?(:map)
224
+ @local.map {|i| quote_atom(i) }.join('.')
225
+ else
226
+ quote_atom(@local)
227
+ end
228
+ end
229
+
230
+ # Returns the domain part of the email address
231
+ #
232
+ # For Example:
233
+ #
234
+ # email = TMail::Address.parse("mikel@lindsaar.net")
235
+ # email.local
236
+ # #=> "lindsaar.net"
237
+ def domain
238
+ return nil unless @domain
239
+ join_domain(@domain)
240
+ end
241
+
242
+ # Returns the full specific address itself
243
+ #
244
+ # For Example:
245
+ #
246
+ # email = TMail::Address.parse("mikel@lindsaar.net")
247
+ # email.address
248
+ # #=> "mikel@lindsaar.net"
249
+ def spec
250
+ s = self.local
251
+ d = self.domain
252
+ if s and d
253
+ s + '@' + d
254
+ else
255
+ s
256
+ end
257
+ end
258
+
259
+ alias address spec
260
+
261
+ # Provides == function to the email. Only checks the actual address
262
+ # and ignores the name/phrase component
263
+ #
264
+ # For Example
265
+ #
266
+ # addr1 = TMail::Address.parse("My Address <mikel@lindsaar.net>")
267
+ # #=> "#<TMail::Address mikel@lindsaar.net>"
268
+ # addr2 = TMail::Address.parse("Another <mikel@lindsaar.net>")
269
+ # #=> "#<TMail::Address mikel@lindsaar.net>"
270
+ # addr1 == addr2
271
+ # #=> true
272
+ def ==( other )
273
+ other.respond_to? :spec and self.spec == other.spec
274
+ end
275
+
276
+ alias eql? ==
277
+
278
+ # Provides a unique hash value for this record against the local and domain
279
+ # parts, ignores the name/phrase value
280
+ #
281
+ # email = TMail::Address.parse("mikel@lindsaar.net")
282
+ # email.hash
283
+ # #=> 18767598
284
+ def hash
285
+ @local.hash ^ @domain.hash
286
+ end
287
+
288
+ # Duplicates a TMail::Address object returning the duplicate
289
+ #
290
+ # addr1 = TMail::Address.parse("mikel@lindsaar.net")
291
+ # addr2 = addr1.dup
292
+ # addr1.id == addr2.id
293
+ # #=> false
294
+ def dup
295
+ obj = self.class.new(@local.dup, @domain.dup)
296
+ obj.name = @name.dup if @name
297
+ obj.routes.replace @routes
298
+ obj
299
+ end
300
+
301
+ include StrategyInterface #:nodoc:
302
+
303
+ def accept( strategy, dummy1 = nil, dummy2 = nil ) #:nodoc:
304
+ unless @local
305
+ strategy.meta '<>' # empty return-path
306
+ return
307
+ end
308
+
309
+ spec_p = (not @name and @routes.empty?)
310
+ if @name
311
+ strategy.phrase @name
312
+ strategy.space
313
+ end
314
+ tmp = spec_p ? '' : '<'
315
+ unless @routes.empty?
316
+ tmp << @routes.map {|i| '@' + i }.join(',') << ':'
317
+ end
318
+ tmp << self.spec
319
+ tmp << '>' unless spec_p
320
+ strategy.meta tmp
321
+ strategy.lwsp ''
322
+ end
323
+
324
+ end
325
+
326
+
327
+ class AddressGroup
328
+
329
+ include Enumerable
330
+
331
+ def address_group?
332
+ true
333
+ end
334
+
335
+ def initialize( name, addrs )
336
+ @name = name
337
+ @addresses = addrs
338
+ end
339
+
340
+ attr_reader :name
341
+
342
+ def ==( other )
343
+ other.respond_to? :to_a and @addresses == other.to_a
344
+ end
345
+
346
+ alias eql? ==
347
+
348
+ def hash
349
+ map {|i| i.hash }.hash
350
+ end
351
+
352
+ def []( idx )
353
+ @addresses[idx]
354
+ end
355
+
356
+ def size
357
+ @addresses.size
358
+ end
359
+
360
+ def empty?
361
+ @addresses.empty?
362
+ end
363
+
364
+ def each( &block )
365
+ @addresses.each(&block)
366
+ end
367
+
368
+ def to_a
369
+ @addresses.dup
370
+ end
371
+
372
+ alias to_ary to_a
373
+
374
+ def include?( a )
375
+ @addresses.include? a
376
+ end
377
+
378
+ def flatten
379
+ set = []
380
+ @addresses.each do |a|
381
+ if a.respond_to? :flatten
382
+ set.concat a.flatten
383
+ else
384
+ set.push a
385
+ end
386
+ end
387
+ set
388
+ end
389
+
390
+ def each_address( &block )
391
+ flatten.each(&block)
392
+ end
393
+
394
+ def add( a )
395
+ @addresses.push a
396
+ end
397
+
398
+ alias push add
399
+
400
+ def delete( a )
401
+ @addresses.delete a
402
+ end
403
+
404
+ include StrategyInterface
405
+
406
+ def accept( strategy, dummy1 = nil, dummy2 = nil )
407
+ strategy.phrase @name
408
+ strategy.meta ':'
409
+ strategy.space
410
+ first = true
411
+ each do |mbox|
412
+ if first
413
+ first = false
414
+ else
415
+ strategy.meta ','
416
+ end
417
+ strategy.space
418
+ mbox.accept strategy
419
+ end
420
+ strategy.meta ';'
421
+ strategy.lwsp ''
422
+ end
423
+
424
+ end
425
+
426
+ end # module TMail