Class: Gossip::SmtpCrony

Inherits:
Crony
  • Object
show all
Defined in:
lib/gossip/cronies/smtp.rb

Overview

This Crony sends email.

Instance Attribute Summary

Attributes inherited from Crony

#is_bff_by_default, #user_choices

Instance Method Summary collapse

Methods inherited from Crony

#add_bff_choice, #checked, #df, #initialize, #is_bff?, #is_bff_by_default?

Constructor Details

This class inherits a constructor from Gossip::Crony

Instance Method Details

#add_configuration_choices(builder) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/gossip/cronies/smtp.rb', line 22

def add_configuration_choices(builder)
  builder.add_choice(:mail_to,
                     :default => checked(:default_to),
                     :type => [:string]) { | command_line |
    command_line.uses_option("--mail-to RECIPIENTS",
                             "Recipients of mail.",
                             "This can be a comma-separated list.",
                             df(:default_to)
                             )
  }

  builder.add_choice(:mail_from,
                     :default => checked(:default_from)) { | command_line |
    command_line.uses_option("--mail-from SENDER", 
                             "The sender of the mail (appears in From line).",
                             df(:default_from)
                             )
  }

  builder.add_choice(:mail_server,
                     :default => checked(:default_smtp_server)) { | command_line |
    command_line.uses_option("--mail-server HOSTNAME", 
                             "SMTP server. #{df(:default_smtp_server)}"
                             )
  }

  builder.add_choice(:mail_port,
                     :type => :integer,
                     :default => checked(:default_smtp_port)) { | command_line |
    command_line.uses_option("--mail-port NUMBER", 
                             "Mail port on that server.",
                             df(:default_smtp_port)
                             )
  }

  builder.add_choice(:mail_account,
                     :default => checked(:default_smtp_account)) { | command_line |
    command_line.uses_option("--mail-account USERNAME", 
                             "Your account name on the SMTP server.",
                             df(:default_smtp_account)
                             )
  }

  builder.add_choice(:mail_from_domain,
                     :default => checked(:default_from_domain)) { | command_line |
    command_line.uses_option("--mail-from-domain HOSTNAME", 
                             "The server the mail supposedly comes from.",
                             "(Not necessarily the SMTP server.)",
                             df(:default_from_domain)
                             )
  }

  builder.add_choice(:mail_password,
                     :default => checked(:default_smtp_password)) { | command_line |
    command_line.uses_option("--mail-password HOSTNAME", 
                             "Your password on the SMTP server.",
                             df(:default_smtp_password)
                             )
  }

  auth_types = ['plain', 'login', 'cram_md5']
  builder.add_choice(:mail_authentication,
                     :type => auth_types,
                     :default => checked(:default_smtp_authentication)) { | command_line |
    command_line.uses_option("--mail-authentication TYPE",
                             "The kind of authentication your SMTP server uses.",
                             "One of #{friendly_list('or', auth_types)}.",
                             df(:default_smtp_authentication)
                             )
  }
end

#command_line_descriptionObject



16
17
18
19
20
# File 'lib/gossip/cronies/smtp.rb', line 16

def command_line_description
  ['-m', "--mail",
   "Control mail notification.",
   "Defaults to #{is_bff_by_default?}."]
end

#hear(scandal, details) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/gossip/cronies/smtp.rb', line 99

def hear(scandal, details)
  from = @user_choices[:mail_from]
  to = @user_choices[:mail_to]
  Net::SMTP.start(@user_choices[:mail_server], @user_choices[:mail_port],
                  @user_choices[:mail_from_domain],
                  @user_choices[:mail_account],
                  @user_choices[:mail_password],
                  @user_choices[:mail_authentication]) { | smtp |
    mail = "
            . From: #{from}
            . To: #{to.join(', ')}
            . Subject: #{scandal}
            .
            . #{details}
           ".without_pretty_indentation('.')
    smtp.send_message(mail, from, to)
  }
end

#nameObject



13
# File 'lib/gossip/cronies/smtp.rb', line 13

def name; 'mail'; end

#postprocess_user_choicesObject



94
95
96
97
# File 'lib/gossip/cronies/smtp.rb', line 94

def postprocess_user_choices
  @user_choices[:mail_authentication] =
    @user_choices[:mail_authentication].to_sym
end

#symbolObject



14
# File 'lib/gossip/cronies/smtp.rb', line 14

def symbol; :mail; end