Permalink
Browse files

Monkey patch Net::SMTP to prevent double brackets.

Some SMTP servers don't allow multiple angle brackets in the MAIL FROM
line. This monkey patches Net::SMTP to only add angle braces around
addresses if they don't contain them already.
  • Loading branch information...
1 parent e13cb57 commit ea8b118bd2065893d4b9ad29597c2296cea82c56 @benburkert benburkert committed Jan 6, 2012
Showing with 20 additions and 0 deletions.
  1. +20 −0 services/email.rb
View
@@ -1,3 +1,23 @@
+class Net::SMTP
+ def mailfrom(from_addr)
+ if $SAFE > 0
+ raise SecurityError, 'tainted from_addr' if from_addr.tainted?
+ end
+ getok("MAIL FROM:#{escape(from_addr)}")
+ end
+
+ def rcptto(to_addr)
+ if $SAFE > 0
+ raise SecurityError, 'tainted to_addr' if to_addr.tainted?
+ end
+ getok("RCPT TO:#{escape(to_addr)}")
+ end
+
+ def escape(address)
+ address.include?('<') ? address : "<#{address}>"
+ end
+end
+
class Service::Email < Service
string :address, :secret
boolean :send_from_author

0 comments on commit ea8b118

Please sign in to comment.