Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

BCC is ignored #426

Closed
oprogfrogo opened this Issue · 3 comments

3 participants

@oprogfrogo

Rails 3.1.4
Ruby 1.9.3
mail (2.3.3)
actionmailer (3.1.4)

1.9.3p194 :008 > mail = Mail.new do
1.9.3p194 :009 > from 'oprogfrogo@gmail.com'
1.9.3p194 :010?> to 'oprogfrogo@gmail.com'
1.9.3p194 :011?> bcc 'oprogfrogo@gmail.com'
1.9.3p194 :012?> end
=> #, , >
1.9.3p194 :013 > mail.to_s
=> "Date: Mon, 13 Aug 2012 14:55:34 -0700\r\nFrom: oprogfrogo@gmail.com\r\nTo: oprogfrogo@gmail.com\r\nMessage-ID: 502977d6ab02d_17c6c3ff4cd434cdc4346a@Simon-Lees-iMac.local.mail\r\nMime-Version: 1.0\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: 7bit\r\n\r\n"
1.9.3p194 :014 >

@oprogfrogo

I compared bcc_field.rb to cc_field.rb and noticed some differences in the initialize constuctor and encoded method. Here's what I updated to and it works now:

module Mail
class BccField < StructuredField

include Mail::CommonAddress

FIELD_NAME = 'bcc'
CAPITALIZED_FIELD = 'Bcc'

def initialize(value = nil, charset = 'utf-8')
  @charset = charset
  super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
  self.parse
  self
end

# Bcc field should never be :encoded
def encoded
  do_encode(CAPITALIZED_FIELD)
end

def decoded
  do_decode
end

end
end

@briantobin

Hi oprogfrogo. I think that is intended behavior, as the comment suggests. The BCC field shouldn't be included in the to_s output because that's what all recipients see. If BCC were a header like any other then it wouldn't be "blind" any more.

The way BCC works in practice is that all recipients are passed to the SMTP server (To, CC, and BCC). All recipients receive the same RFC822, which only lists the To and CC recipients.

One twist is that some RFC822 emails you download will have the field. For example, GMail's IMAP server includes the BCC header for messages you've sent, but not messages you've received. I suspect this gem will swallow that field, which is kind of a bummer. Perhaps a good compromise would be an argument to to_s that lets you override the default behavior and include the BCC field.

@jeremy
Collaborator

@briantobin is spot-on. BCC on outgoing messages adds SMTP recipients without adding message headers.

@jeremy jeremy closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.