Answers.Body: <p>In my experience, reading the <code>Bcc</code> field is not a reliable source of information, because there is not always available data. Thanks to your question I checked the RFC in response to your question and learned why!</p>
  <p><strong>What's happening</strong></p>
  <p>See <a href="https://www.rfc-editor.org/rfc/rfc2822#page-22" rel="nofollow noreferrer">https://www.rfc-editor.org/rfc/rfc2822#page-22</a></p>
  <blockquote>
  <p>The &quot;Bcc:&quot; field (where the &quot;Bcc&quot; means &quot;Blind Carbon Copy&quot;) contains    addresses of recipients of the message whose addresses are not to be    revealed to other recipients of the message.  There are three ways in    which the &quot;Bcc:&quot; field is used.</p>
  <p>In the first case, when a message    containing a &quot;Bcc:&quot; field is prepared to be sent, <strong>the &quot;Bcc:&quot; line is    removed even though all of the recipients (including those specified    in the &quot;Bcc:&quot; field) are sent a copy of the message</strong>.</p>
  </blockquote>
  <p>When sender and recipient are on different servers, this is the behaviour you'll observe. (<a href="https://gist.github.com/jitendrapurohit/fa6a115c18b8bcfbb8346f58cd1265c0" rel="nofollow noreferrer">Outlook.com =&gt; Gmail.com result</a>)</p>
  <blockquote>
  <p>In the second    case, recipients specified in the &quot;To:&quot; and &quot;Cc:&quot; lines each are sent    a copy of the message with the &quot;Bcc:&quot; line removed as above, but <strong>the    recipients on the &quot;Bcc:&quot; line get a separate copy of the message    containing a &quot;Bcc:&quot; line</strong>.</p>
  <p>(When there are multiple recipient    addresses in the &quot;Bcc:&quot; field, some implementations actually send a    separate copy of the message to each recipient with a &quot;Bcc:&quot;    containing only the address of that particular recipient.)</p>
  </blockquote>
  <p>When sender and recipient are on Outlook.com, this is the behaviour you observe. (<a href="https://gist.github.com/jitendrapurohit/176eee759cfc9b3688682ea99b6c3460" rel="nofollow noreferrer">Outlook.com =&gt; Outlook.com result</a>)</p>
  <blockquote>
  <p>Finally,    since a &quot;Bcc:&quot; field may contain no addresses, a &quot;Bcc:&quot; field can be    sent without any addresses indicating to the recipients that blind    copies were sent to someone.</p>
  </blockquote>
  <p>So - it's not a difference in Outlook vs GMail behaviour, so much as a difference in how MTAs handle internal and external deliveries. I still would not expect to see <em>other</em> Bcc recipients appear though.</p>
  <p>See also <a href="https://stackoverflow.com/a/33579971/43034">this similar question/answer</a>.</p>
  <p><strong>How to handle this</strong></p>
  <p>My take is: if you're parsing an email and the receiving address is not in To or Cc, it’s a fair bet that it was either Bcc'd or the receiving address is the final recipient of an email alias.</p>
  <p>Beyond that, don’t expect to know who’s in the Bcc field - that’s what it’s for.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-06T03:53:02.190Z
Answers.LastActivityDate: 2018-02-06T04:00:13.803Z
Answers.LastEditDate: 2021-10-07T07:34:52.683Z
Answers.UserDisplayName: Chris Burgess
Body: <p>Trying to process inbound mails that are bcc'd to abc@domain.com (Office 365).</p>
  
  <p>Pasting the code we have at <a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Mailing/MailStore.php#L128-L138" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/CRM/Mailing/MailStore.php#L128-L138</a></p>
  
  <pre><code>$parser = new ezcMailParser();
  //set property text attachment as file CRM-5408
  $parser-&gt;options-&gt;parseTextAttachmentsAsFiles = TRUE;
  foreach ($set-&gt;getMessageNumbers() as $nr) {
    if ($this-&gt;_debug) {
      print "retrieving message $nr\n";
    }
    $single = $parser-&gt;parseMail($this-&gt;_transport-&gt;fetchByMessageNr($nr));
    $mails[$nr] = $single[0];
  }
  </code></pre>
  
  <p>When a mail is bcc'd from a Gmail account to <code>abc@domain.com</code> and <code>Process Inbound Email</code> job is executed, <code>$mails</code> correctly contain the email address in the bcc header.</p>
  
  <p>But, when it is sent from an outlook account or Apple Mail, there is no bcc or any header that contains an information that our mail was bcc'd to <code>abc@domain.com</code>.</p>
  
  <p>Does our email parser strips bcc information if the input is from a server other than Gmail?</p>
  
  <p>Update - </p>
  
  <p>If mail is sent from Gmail, headers look like - <a href="https://gist.github.com/jitendrapurohit/fa6a115c18b8bcfbb8346f58cd1265c0" rel="nofollow noreferrer">https://gist.github.com/jitendrapurohit/fa6a115c18b8bcfbb8346f58cd1265c0</a></p>
  
  <p>From Outlook - <a href="https://gist.github.com/jitendrapurohit/176eee759cfc9b3688682ea99b6c3460" rel="nofollow noreferrer">https://gist.github.com/jitendrapurohit/176eee759cfc9b3688682ea99b6c3460</a></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-05T16:29:24.673Z
Comments.Text: I would recommend forwarding the email to a separate (non-Civi) address from both GMail and Apple Mail and examining the headers.  Post the relevant headers on this question if necessary.  I suspect you'll find a difference in the headers that causes different behavior.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-06T02:37:12.137Z
Comments.Text: yes, there is a difference and it doesn't include bcc info - I'll update the same on the question
Comments.UserDisplayName: jitendra - fuzion
Tags: <email><mailserver>
Title: ezcMailParser not able to retrieve bcc from a mail
ThreadText: # ezcMailParser not able to retrieve bcc from a mail
  
  (Asked by: username_0 on 2018-02-05)
  
  Trying to process inbound mails that are bcc'd to abc@domain.com (Office 365).
  Pasting the code we have at https://github.com/civicrm/civicrm-core/blob/master/CRM/Mailing/MailStore.php#L128-L138
  $parser = new ezcMailParser();
  //set property text attachment as file CRM-5408
  $parser->options->parseTextAttachmentsAsFiles = TRUE;
  foreach ($set->getMessageNumbers() as $nr) {
    if ($this->_debug) {
      print "retrieving message $nr\n";
    }
    $single = $parser->parseMail($this->_transport->fetchByMessageNr($nr));
    $mails[$nr] = $single[0];
  }
  
  When a mail is bcc'd from a Gmail account to abc@domain.com and Process Inbound Email job is executed, $mails correctly contain the email address in the bcc header.
  But, when it is sent from an outlook account or Apple Mail, there is no bcc or any header that contains an information that our mail was bcc'd to abc@domain.com.
  Does our email parser strips bcc information if the input is from a server other than Gmail?
  Update - 
  If mail is sent from Gmail, headers look like - https://gist.github.com/jitendrapurohit/fa6a115c18b8bcfbb8346f58cd1265c0
  From Outlook - https://gist.github.com/jitendrapurohit/176eee759cfc9b3688682ea99b6c3460
  
  **Tags:** email, mailserver
  
  > **Comments:**
  > **username_1**: I would recommend forwarding the email to a separate (non-Civi) address from both GMail and Apple Mail and examining the headers.  Post the relevant headers on this question if necessary.  I suspect you'll find a difference in the headers that causes different behavior.  
  > **username_0**: yes, there is a difference and it doesn't include bcc info - I'll update the same on the question  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-02-06. Score: 1 | Accepted answer
  
  In my experience, reading the `Bcc` field is not a reliable source of information, because there is not always available data. Thanks to your question I checked the RFC in response to your question and learned why!
  
  **What's happening**
  
  See <https://www.rfc-editor.org/rfc/rfc2822#page-22>
  
  > The "Bcc:" field (where the "Bcc" means "Blind Carbon Copy") contains addresses of recipients of the message whose addresses are not to be revealed to other recipients of the message. There are three ways in which the "Bcc:" field is used.
  >
  > In the first case, when a message containing a "Bcc:" field is prepared to be sent, **the "Bcc:" line is removed even though all of the recipients (including those specified in the "Bcc:" field) are sent a copy of the message**.
  
  When sender and recipient are on different servers, this is the behaviour you'll observe. ([Outlook.com => Gmail.com result](https://gist.github.com/jitendrapurohit/fa6a115c18b8bcfbb8346f58cd1265c0))
  
  > In the second case, recipients specified in the "To:" and "Cc:" lines each are sent a copy of the message with the "Bcc:" line removed as above, but **the recipients on the "Bcc:" line get a separate copy of the message containing a "Bcc:" line**.
  >
  > (When there are multiple recipient addresses in the "Bcc:" field, some implementations actually send a separate copy of the message to each recipient with a "Bcc:" containing only the address of that particular recipient.)
  
  When sender and recipient are on Outlook.com, this is the behaviour you observe. ([Outlook.com => Outlook.com result](https://gist.github.com/jitendrapurohit/176eee759cfc9b3688682ea99b6c3460))
  
  > Finally, since a "Bcc:" field may contain no addresses, a "Bcc:" field can be sent without any addresses indicating to the recipients that blind copies were sent to someone.
  
  So - it's not a difference in Outlook vs GMail behaviour, so much as a difference in how MTAs handle internal and external deliveries. I still would not expect to see *other* Bcc recipients appear though.
  
  See also [this similar question/answer](https://stackoverflow.com/a/33579971/43034).
  
  **How to handle this**
  
  My take is: if you're parsing an email and the receiving address is not in To or Cc, it’s a fair bet that it was either Bcc'd or the receiving address is the final recipient of an email alias.
  
  Beyond that, don’t expect to know who’s in the Bcc field - that’s what it’s for.
  
  
  ---
  
  