CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviCase (Moderator: Dave Greenberg) »
  • CiviCase 3.3.2: email's recipient name is odd
Pages: [1]

Author Topic: CiviCase 3.3.2: email's recipient name is odd  (Read 1908 times)

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
CiviCase 3.3.2: email's recipient name is odd
January 22, 2011, 09:42:35 pm
When I edit a case activity, and use "send a copy" to send an email, the recipient name in the email is odd. (update: see my reply, below, for an analysis and a suggested fix)

If I, as the case manager have an email address of "Bill Smith <bill.smith@example.com>" and I send an email to myself, the email header looks like ...

Quote
From: Bill Smith <bill.smith@example.com>
To:   Smith@example.com, Bill <bill.smith@example.com>

The "from" address is what I expect, matching every other address CiviCRM generates, but the "to" address is odd.

Indeed, the first 'example.com' is my domain, not the domain of the recipient. If I sent the email to the client, the header might look like ...

Quote
From: Bill Smith <bill.smith@example.com>
To:   Jones@example.com, Jack <jack.jones@client.com>

Ken
« Last Edit: January 24, 2011, 03:16:18 am by ken »

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
Re: CiviCase 3.3.2: email's recipient name is odd
January 24, 2011, 03:14:49 am
I did a bit of digging and found the cause of the problem, plus a suggested fix.

At lines 1300-1304 of CRM/Case/BAO/Case.php the contact's 'sort name' is copied into a 'display name' variable.

Code: [Select]
            if ( !CRM_Utils_Array::value('sort_name', $info) ) {
                $info['sort_name'] = $info['display_name'];   
            }
           
            $displayName = $info['sort_name'];

At line 1314 this variable is stored as the name part of the "To:" email.

Code: [Select]
                    'toName'      => $displayName,
At line 93 of CRM/Utils/Mail.php this is combined with the email address to form the "To:" header.

Code: [Select]
        $headers['To']                        = "{$params['toName']} <{$params['toEmail']}>";
There are 4 problems with the use of 'sort_name' ...
  • The comma in the name confuses some MTA's. For example, Postfix replaces "Recipient, John <john.recipient@recievingdomain.com>" with "Recipient@sendingdomain.com, John <john.recipient@recievingdomain.com>" because it interprets the comma as separating two recipients, and interprets "Recipient" as a local address.
  • In all other emails sent by CiviCRM, the name has the form "Firstname Lastname" rather than "Lastname, Firstname"
  • It feels a bit odd to receive an email using the sort name (no one calls me "West, Ken", not even my bank!)
  • The sort name is an internal construct, generated within CiviCRM
The appropriate fix is to replace lines 1300-1304 of CRM/Case/BAO/Case.php with ...

Code: [Select]
            $displayName = $info['display_name'];

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: CiviCase 3.3.2: email's recipient name is odd
January 24, 2011, 04:50:22 am
Hi,

Agree with your suggestion of using display name for the displayed name.

@civicore: I'm assuming there is a reason it wasn't done that way ?

Quote from: ken on January 24, 2011, 03:14:49 am
For example, Postfix replaces "Recipient, John <john.recipient@recievingdomain.com>" with "Recipient@sendingdomain.com, John <john.recipient@recievingdomain.com>" because it interprets the comma as separating two recipients, and interprets "Recipient" as a local address.

Ken, been struggling for a while with a strange bug on the from, I think you found it. (the mail is sent by Doe, John john.doe@example.com, the user replies to instead of reply to all and he gets a bounced email as doe@example.com is invalid).

Do you know if there is an option in postfix so it doesn't try to outsmart us doing clever split on the comma? (even if using display name, we can still have a comma, eg in the name of the household or organisation).

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
Re: CiviCase 3.3.2: email's recipient name is odd
January 24, 2011, 07:41:18 am
Xavier,

I don't think the solution should be sought with Postfix. The problem is to do with compliance with the email address format specified in RFC 5322 (Internet Message Format). I suggest a location for the fix at the bottom of this post.

In Section 3.4.1 of that RFC the address can be of the form ...

Code: [Select]
   name-addr       =   [display-name] angle-addr

... with an optional display name (the address itself must be between angle brackets). The display name is a 'phrase' and Section 3.2.5 allows a phrase to be one or more words, and a word is an atom or a quoted string ...

Code: [Select]
   word            =   atom / quoted-string

   phrase          =   1*word / obs-phrase

Section 3.2.3 says an 'atom' is a string of text surrounded by white space which doesn't contain the following special characters ...

Code: [Select]
   specials        =   "(" / ")" /        ; Special characters that do
                       "<" / ">" /        ;  not appear in atext
                       "[" / "]" /
                       ":" / ";" /
                       "@" / "\" /
                       "," / "." /
                       DQUOTE

So, boiling that all down, the display name should be quoted if it contains any of these special characters (DQUOTE is a double quote  " ).

Lines 107 and 112 of CRM/Utils/Mail.php for 3.3.2 indicate that some issues have been detected with 'From' addresses, with CRM-6977 and CRM-7053 recently being applied. I note that the fix for CRM-7053 doesn't deal with all the 'special characters'.

The 'To' address should be simpler to fix than the 'From' address as CRM_Utils_Mail::send() is 'constructing' it rather than 'repairing' it. The 'Cc' and 'Bcc' addresses should have the same fix applied as the 'From' address.

Ken

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: CiviCase 3.3.2: email's recipient name is odd
January 29, 2011, 02:38:53 am
http://issues.civicrm.org/jira/browse/CRM-7451

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
Re: CiviCase 3.3.2: email's recipient name is odd
January 29, 2011, 04:46:36 am
Magic!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviCase (Moderator: Dave Greenberg) »
  • CiviCase 3.3.2: email's recipient name is odd

This forum was archived on 2017-11-26.