functions.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /**
  3. * functions.php
  4. *
  5. * Implementation of RFC 2369 for SquirrelMail.
  6. * When viewing a message from a mailinglist complying with this RFC,
  7. * this plugin displays a menu which gives the user a choice of mailinglist
  8. * commands such as (un)subscribe, help and list archives.
  9. *
  10. * @copyright 1999-2015 The SquirrelMail Project Team
  11. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  12. * @version $Id$
  13. * @package plugins
  14. * @subpackage listcommands
  15. */
  16. /**
  17. * Get current list of subscribed non-RFC-compliant mailing lists for logged-in user
  18. *
  19. * @return array The list of mailing list addresses, keyed by integer index
  20. */
  21. function get_non_rfc_lists() {
  22. global $username, $data_dir;
  23. $lists = getPref($data_dir, $username, 'non_rfc_lists', array());
  24. $new_lists = array();
  25. if (!empty($lists)) {
  26. $lists = explode(':', $lists);
  27. foreach ($lists as $list) {
  28. list($index, $list_addr) = explode('_', $list);
  29. if ((!empty($index) || $index === '0') && !empty($list_addr))
  30. $new_lists[$index] = $list_addr;
  31. }
  32. }
  33. $lists = $new_lists;
  34. sort($lists);
  35. return $lists;
  36. }
  37. /**
  38. * Show mailing list management option section on options page
  39. */
  40. function plugin_listcommands_optpage_register_block_do()
  41. {
  42. global $optpage_blocks, $listcommands_allow_non_rfc_list_management;
  43. // only allow management of non-RFC lists if admin deems necessary
  44. //
  45. @include_once(SM_PATH . 'plugins/listcommands/config.php');
  46. if (!$listcommands_allow_non_rfc_list_management)
  47. return;
  48. $optpage_blocks[] = array(
  49. 'name' => _("Mailing Lists"),
  50. 'url' => '../plugins/listcommands/options.php',
  51. 'desc' => _("Manage the (non-RFC-compliant) mailing lists that you are subscribed to for the purpose of providing one-click list replies when responding to list messages."),
  52. 'js' => false
  53. );
  54. }
  55. /**
  56. * internal function that builds mailing list links
  57. */
  58. function plugin_listcommands_menu_do() {
  59. global $passed_id, $passed_ent_id, $mailbox, $message,
  60. $startMessage, $oTemplate, $listcommands_allow_non_rfc_list_management;
  61. @include_once(SM_PATH . 'plugins/listcommands/config.php');
  62. /**
  63. * Array of commands we can deal with from the header. The Reply option
  64. * is added later because we generate it using the Post information.
  65. */
  66. $fieldsdescr = listcommands_fieldsdescr();
  67. $links = array();
  68. foreach ($message->rfc822_header->mlist as $cmd => $actions) {
  69. /* I don't know this action... skip it */
  70. if ( !array_key_exists($cmd, $fieldsdescr) ) {
  71. continue;
  72. }
  73. /* proto = {mailto,href} */
  74. $aActions = array_keys($actions);
  75. $proto = array_shift($aActions);
  76. $act = array_shift($actions);
  77. if ($proto == 'mailto') {
  78. if (($cmd == 'post') || ($cmd == 'owner')) {
  79. $url = 'src/compose.php?'.
  80. (isset($startMessage)?'startMessage='.$startMessage.'&amp;':'');
  81. } else {
  82. $url = "plugins/listcommands/mailout.php?action=$cmd&amp;";
  83. }
  84. $url .= 'send_to=' . urlencode($act);
  85. $links[$cmd] = makeComposeLink($url, $fieldsdescr[$cmd]);
  86. if ($cmd == 'post') {
  87. if (!isset($mailbox))
  88. $mailbox = 'INBOX';
  89. $url .= '&amp;passed_id='.$passed_id.
  90. '&amp;mailbox='.urlencode($mailbox).
  91. (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
  92. $url .= '&amp;smaction=reply';
  93. $links['reply'] = makeComposeLink($url, $fieldsdescr['reply']);
  94. }
  95. } else if ($proto == 'href') {
  96. $links[$cmd] = create_hyperlink($act, $fieldsdescr[$cmd], '_blank');
  97. }
  98. }
  99. // allow non-rfc reply link if admin allows and message is from
  100. // non-rfc list the user has configured
  101. //
  102. if ($listcommands_allow_non_rfc_list_management) {
  103. $non_rfc_lists = get_non_rfc_lists();
  104. $recipients = formatRecipientString($message->rfc822_header->to, "to") . ' '
  105. . formatRecipientString($message->rfc822_header->cc, "cc") . ' '
  106. . formatRecipientString($message->rfc822_header->bcc, "bcc");
  107. if (!in_array('post', array_keys($links))) {
  108. foreach ($non_rfc_lists as $non_rfc_list) {
  109. if (preg_match('/(^|,|<|\s)' . preg_quote($non_rfc_list) . '($|,|>|\s)/', $recipients)) {
  110. $url = 'src/compose.php?'
  111. . (isset($startMessage)?'startMessage='.$startMessage.'&amp;':'')
  112. . 'send_to=' . str_replace('?','&amp;', $non_rfc_list);
  113. $links['post'] = makeComposeLink($url, $fieldsdescr['post']);
  114. break;
  115. }
  116. }
  117. }
  118. if (!in_array('reply', array_keys($links))) {
  119. foreach ($non_rfc_lists as $non_rfc_list) {
  120. if (preg_match('/(^|,|\s)' . preg_quote($non_rfc_list) . '($|,|\s)/', $recipients)) {
  121. if (!isset($mailbox))
  122. $mailbox = 'INBOX';
  123. $url = 'src/compose.php?'
  124. . (isset($startMessage)?'startMessage='.$startMessage.'&amp;':'')
  125. . 'send_to=' . str_replace('?','&amp;', $non_rfc_list)
  126. . '&amp;passed_id='.$passed_id
  127. . '&amp;mailbox='.urlencode($mailbox)
  128. . (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'')
  129. . '&amp;smaction=reply';
  130. $links['reply'] = makeComposeLink($url, $fieldsdescr['reply']);
  131. break;
  132. }
  133. }
  134. }
  135. }
  136. if (count($links) > 0) {
  137. $oTemplate->assign('links', $links);
  138. $output = $oTemplate->fetch('plugins/listcommands/read_body_header.tpl');
  139. return array('read_body_header' => $output);
  140. }
  141. }
  142. /**
  143. * Returns an array with the actions as translated strings.
  144. * @return array action as key, translated string as value
  145. */
  146. function listcommands_fieldsdescr() {
  147. return array('post' => _("Post to List"),
  148. 'reply' => _("Reply to List"),
  149. 'subscribe' => _("Subscribe"),
  150. 'unsubscribe' => _("Unsubscribe"),
  151. 'archive' => _("List Archives"),
  152. 'owner' => _("Contact Listowner"),
  153. 'help' => _("Help"));
  154. }