Class: CARPS::EmailConfig
- Inherits:
-
SystemConfig
- Object
- YamlConfig
- SystemConfig
- CARPS::EmailConfig
- Defined in:
- lib/carps/email/config.rb
Overview
Class to read email config.
Class Method Summary collapse
Instance Method Summary collapse
-
#connect! ⇒ Object
Relentlessly continue until we can connect to IMAP and SMTP.
-
#emit ⇒ Object
Emit options as hash.
-
#imap ⇒ Object
Expose the IMAP client.
-
#initialize(address, same_pass, imap_options, smtp_options) ⇒ EmailConfig
constructor
A new instance of EmailConfig.
-
#load_resources(address, same_pass, imap_settings, smtp_settings) ⇒ Object
Connect to the imap and smtp servers.
-
#mailer(message_parser, session_manager) ⇒ Object
Return the high level mail client.
-
#parse_yaml(conf) ⇒ Object
Parse the email config file.
-
#smtp ⇒ Object
Expose the SMTP client.
-
#untaint_all(hsh) ⇒ Object
Untaint every value in a hash.
Methods inherited from SystemConfig
Methods inherited from YamlConfig
Constructor Details
#initialize(address, same_pass, imap_options, smtp_options) ⇒ EmailConfig
Returns a new instance of EmailConfig.
48 49 50 |
# File 'lib/carps/email/config.rb', line 48 def initialize address, same_pass, , load_resources address, same_pass, , end |
Class Method Details
.filepath ⇒ Object
44 45 46 |
# File 'lib/carps/email/config.rb', line 44 def EmailConfig.filepath "email.yaml" end |
Instance Method Details
#connect! ⇒ Object
Relentlessly continue until we can connect to IMAP and SMTP
87 88 89 90 |
# File 'lib/carps/email/config.rb', line 87 def connect! @smtp.with_connection {|smtp|} @imap.with_connection {|imap|} end |
#emit ⇒ Object
Emit options as hash
93 94 95 |
# File 'lib/carps/email/config.rb', line 93 def emit @file_struct end |
#imap ⇒ Object
Expose the IMAP client
98 99 100 |
# File 'lib/carps/email/config.rb', line 98 def imap @imap end |
#load_resources(address, same_pass, imap_settings, smtp_settings) ⇒ Object
Connect to the imap and smtp servers
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/carps/email/config.rb', line 71 def load_resources address, same_pass, imap_settings, smtp_settings @file_struct = {"address" => address, "same_pass" => same_pass, "imap" => imap_settings, "smtp" => smtp_settings} @address = address smtp_password = "" imap_password = "" if same_pass imap_password = smtp_password = UI::secret("Enter password for #{address}:") else imap_password = UI::secret "Enter password for IMAP account at #{address}:" smtp_password = UI::secret "Enter password for SMTP account at #{address}:" end @imap = IMAP.new imap_settings, imap_password @smtp = SMTP.new smtp_settings, smtp_password end |
#mailer(message_parser, session_manager) ⇒ Object
Return the high level mail client
108 109 110 111 |
# File 'lib/carps/email/config.rb', line 108 def mailer , session_manager mailbox = Mailbox.new @smtp, @imap, , session_manager Mailer.new @address, mailbox end |
#parse_yaml(conf) ⇒ Object
Parse the email config file
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/carps/email/config.rb', line 53 def parse_yaml conf address = read_conf conf, "address" same_pass = read_conf conf, "same_pass" imap = read_conf conf, "imap" unless imap.members?(["user", "server", "port", "tls", "certificate", "verify", "login", "cram_md5"]) raise Expected, "Expected IMAP section to be valid." end smtp = read_conf conf, "smtp" unless smtp.members?(["user", "server", "port", "tls", "starttls", "login", "cram_md5"]) raise Expected, "Expected SMTP section to be valid." end # Untaint the imap and smtp data untaint_all imap untaint_all smtp [address, same_pass, imap, smtp] end |
#smtp ⇒ Object
Expose the SMTP client
103 104 105 |
# File 'lib/carps/email/config.rb', line 103 def smtp @smtp end |
#untaint_all(hsh) ⇒ Object
Untaint every value in a hash
114 115 116 117 118 |
# File 'lib/carps/email/config.rb', line 114 def untaint_all hsh hsh.each_value do |val| val.untaint end end |