Class: PasteHub::SendMail
- Inherits:
-
PluginBase
- Object
- PluginBase
- PasteHub::SendMail
- Defined in:
- lib/pastehub/plugin/sendmail.rb
Instance Attribute Summary collapse
-
#mail_command ⇒ Object
Returns the value of attribute mail_command.
-
#mail_settings ⇒ Object
readonly
Returns the value of attribute mail_settings.
Instance Method Summary collapse
- #display_config ⇒ Object
- #encode_subject(subject) ⇒ Object
-
#initialize ⇒ SendMail
constructor
A new instance of SendMail.
- #newly_arrived(message) ⇒ Object
- #sendmail?(message) ⇒ Boolean
Constructor Details
#initialize ⇒ SendMail
Returns a new instance of SendMail.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pastehub/plugin/sendmail.rb', line 50 def initialize() @mail_command = "mail" # load env variables @mail_settings = 10.times.collect {|n| mail_setting = MailSetting.new val = ENV[ sprintf("PASTEHUB_MAIL%d", n) ] if val if val.match(/^[a-zA-Z]+[,][a-zA-Z0-9_.-]+[@].+$/) arr = val.split(/,/) mail_setting.tag = arr[0] mail_setting.mail = arr[1] mail_setting else nil end else nil end }.select( ) {|x| x} end |
Instance Attribute Details
#mail_command ⇒ Object
Returns the value of attribute mail_command.
48 49 50 |
# File 'lib/pastehub/plugin/sendmail.rb', line 48 def mail_command @mail_command end |
#mail_settings ⇒ Object (readonly)
Returns the value of attribute mail_settings.
47 48 49 |
# File 'lib/pastehub/plugin/sendmail.rb', line 47 def mail_settings @mail_settings end |
Instance Method Details
#display_config ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/pastehub/plugin/sendmail.rb', line 71 def display_config # display settings @mail_settings.each { |setting| STDERR.printf( "Info: SendMail-plugin tag:[%s] mail[%s]\n", setting.tag, setting.mail ) } end |
#encode_subject(subject) ⇒ Object
97 98 99 100 |
# File 'lib/pastehub/plugin/sendmail.rb', line 97 def encode_subject(subject) enc_str = Base64.strict_encode64(subject) "=?utf-8?B?" + enc_str + "?=" end |
#newly_arrived(message) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/pastehub/plugin/sendmail.rb', line 102 def newly_arrived() mailaddress = sendmail?() lines = .split( /\n/ ) if mailaddress command = sprintf( "|%s %s -i -s '%s'", @mail_command, mailaddress, encode_subject(lines[0])) if @mail_command p @mail_command open( command, "w" ) {|f| f.print } STDERR.printf( "Info: send mail [%s]\n", command ) nil else command end else nil end end |
#sendmail?(message) ⇒ Boolean
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pastehub/plugin/sendmail.rb', line 80 def sendmail?() arr = mail_settings.collect { |setting| tag_exp = sprintf("(^|[ ])[#]%s([ ]|$)", setting.tag) regexp = Regexp.new(tag_exp) if regexp.match() setting.mail else nil end }.select( ) {|x| x} if 0 < arr.size arr[0] else nil end end |