Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

identity_select.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Identity selection based on additional message headers.
  4. *
  5. * On reply to a message user identity selection is based on
  6. * content of standard headers i.e. From, To, Cc and Return-Path.
  7. * Here you can add header(s) set by your SMTP server (e.g.
  8. * Delivered-To, Envelope-To, X-Envelope-To, X-RCPT-TO) to make
  9. * identity selection more accurate.
  10. *
  11. * Enable the plugin in config.inc.php and add your desired headers:
  12. * $config['identity_select_headers'] = array('Delivered-To');
  13. *
  14. * @version @package_version@
  15. * @author Aleksander Machniak <alec@alec.pl>
  16. * @license GNU GPLv3+
  17. */
  18. class identity_select extends rcube_plugin
  19. {
  20. public $task = 'mail';
  21. function init()
  22. {
  23. $this->add_hook('identity_select', array($this, 'select'));
  24. $this->add_hook('storage_init', array($this, 'storage_init'));
  25. }
  26. /**
  27. * Adds additional headers to supported headers list
  28. */
  29. function storage_init($p)
  30. {
  31. $rcmail = rcmail::get_instance();
  32. if ($add_headers = (array)$rcmail->config->get('identity_select_headers', array())) {
  33. $p['fetch_headers'] = trim($p['fetch_headers'] . ' ' . strtoupper(join(' ', $add_headers)));
  34. }
  35. return $p;
  36. }
  37. /**
  38. * Identity selection
  39. */
  40. function select($p)
  41. {
  42. if ($p['selected'] !== null || !is_object($p['message']->headers)) {
  43. return $p;
  44. }
  45. $rcmail = rcmail::get_instance();
  46. foreach ((array)$rcmail->config->get('identity_select_headers', array()) as $header) {
  47. if ($header = $p['message']->headers->get($header, false)) {
  48. foreach ($p['identities'] as $idx => $ident) {
  49. if (in_array($ident['email_ascii'], (array)$header)) {
  50. $p['selected'] = $idx;
  51. break 2;
  52. }
  53. }
  54. }
  55. }
  56. return $p;
  57. }
  58. }