Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Troubles with emails started with "-"(dash)

We have Ruby On Rails application with some emails subscription. It has mailer class inherited from ActionMailer:

class UserMailer < ActionMailer::Base
...
end

Everything ok, except one thing - some users have email addresses with "-" at begin. It occur errors when I'm trying send email to "[email protected]":

sendmail: invalid option -- u
sendmail: invalid option -- s
sendmail: invalid option -- u
sendmail: fatal: usage: sendmail [options]

How could I escape this character(and maybe some similar) for ActionMailer?

Thanks

like image 574
vld Avatar asked Nov 22 '12 15:11

vld


People also ask

Can an email address start with a dash?

The short answer is yes, email addresses can include these characters, but with some exceptions. The two biggest factors to consider are hyphen placement and email service provider.

What is a dash symbol in an email?

A dash is longer than a hyphen and is commonly used to indicate a range or a pause. The most common types of dashes are the en dash (–) and the em dash (—).


1 Answers

The URI.escape method although deprecated does take a second parameter that lets you mark what's unsafe like so

URI.escape("[email protected]", '-')
=> "%[email protected]"

CGI escape which replaces URI.escape doesn't seem to have the same functionality but for a single case like this it might work.

like image 67
mkrinblk Avatar answered Oct 05 '22 13:10

mkrinblk