New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core#644 - extract function to return correct mailbox header #13407
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -577,4 +577,26 @@ public static function format($fields) { | |
return $formattedEmail; | ||
} | ||
|
||
/** | ||
* When passed a value, returns the value if it's non-numeric. | ||
* If it's numeric, look up the display name and email of the corresponding | ||
* contact ID in RFC822 format. | ||
* | ||
* @param string $from | ||
* contact ID or formatted "From address", eg. 12 or "Fred Bloggs" <fred@example.org> | ||
* @return string | ||
* The RFC822-formatted email header (display name + address) | ||
*/ | ||
public static function formatFromAddress($from) { | ||
if (is_numeric($from)) { | ||
$result = civicrm_api3('Email', 'get', [ | ||
'id' => $from, | ||
'return' => ['contact_id.display_name', 'email'], | ||
'sequential' => 1, | ||
])['values'][0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will give a PHP notice if the id is not found There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's probably a good thing though, right? The only legitimate use case in which this code path executes would require the id to be found. Or are you suggesting I should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old and this new code pretends that $result = CRM_Utils_Array::value(0, civicrm_api3('Email', 'get', [
'id' => $from,
'return' => ['contact_id.display_name', 'email'],
'sequential' => 1,
])['values']);
if (empty($result)) {
Civi::log()->warning(ts('Invalid From email ID - ' . $from);
}
... I think we can ignore this. |
||
$from = '"' . $result['contact_id.display_name'] . '" <' . $result['email'] . '>'; | ||
} | ||
return $from; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this commit has already been merged, but I feel like this block where the FROM address is "fixed" should be before the alterMailParams hook is called. otherwise we're sending bad data to that hook and then fixing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lcdservices That makes sense. If you submit a PR I'll review it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MegaphoneJon here you go: #13776