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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Modify email just before use?
Pages: [1]

Author Topic: Modify email just before use?  (Read 1458 times)

bokabu

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
    • California Creativity
Modify email just before use?
October 06, 2009, 08:20:41 pm
I have a Drupal/CiviCRM installation serving volunteers in families who insist on only having one e-mail.  Bah! -- I can't fire them!

Plan A
I originally had a Drupal module temporarily modify a duplicate email address so it would get through the account creation checks.  I used hook_civicrm_pre to remove the modification as it got sent to civicrm_email.  I took off the UNIQUE constraint from civicrm_ut_match.

Either my "helpers" must have not understood when I asked them to never ask CiviCRM to Synchronize Users to Contacts, or I was making foolishly simple assumptions how civicrm_ut_match would be modified.  My hand-crafted table is now full of junk.  The upgrade to CiviCRM 3.0 re-establishes the UNIQUE constraints, and so my upgrade fails.

Plan B
I've now got the Drupal side set up to hack/append a bogus duplicate email counter on to the back of second and subsequent addresses so Drupal is happy.  I now keep the bogus email in the database.  A hook_mail_alter() drops that counter before using it in a Drupal-generated email.  I plan to clean up the addresses so there are no actual duplicates, just these bogus duplicate counters (e.g. bob@example.com.002).

From http://forum.civicrm.org/index.php/topic,9365.0.html I had hoped to use hook_civicrm_tokenValues to drop the counter before using it in CiviCRM generated email, but
a) the modified $details[$key]['email'] is not used for "Send an Email" from a contact page, and
b) ...tokenValues is only invoked for the *sender*, not the *to* contacts when using CiviMail

Is there a way to use hooks to modify the email address?

Do I misunderstand how hook_civicrm_token needs to be used?  [I don't use it]

Are there any changes in this area I should look forward to (3.0 vs. my current 2.2.7)?

Thanks,

- Bob

bokabu

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
    • California Creativity
Re: Modify email just before use?
October 06, 2009, 09:05:39 pm
Ah, I now understand what hook_civicrm_tokens & ...tokenValues are used for -- to provide more tokens to place in to the email.  Doh!

I can't envision how hook_civicrm_pre/post against UFMatch might help me.

Time to figure out exim rewrite rules...

- Bob

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Modify email just before use?
October 07, 2009, 08:37:33 am

I dont think you can do this right now. I think it might be time for CiviCRM to introduce a hook_civicrm_mail_alter

If you want to work on it that would be great. You can check the code at CRM/Utils/Mail::send and see what makes sense with regard to adding a hook there

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Modify email just before use?

This forum was archived on 2017-11-26.