Source for file functions.php

Documentation is available at functions.php

  1. <?php
  2.  
  3. /**
  4.  * functions.php
  5.  *
  6.  * Implementation of RFC 2369 for SquirrelMail.
  7.  * When viewing a message from a mailinglist complying with this RFC,
  8.  * this plugin displays a menu which gives the user a choice of mailinglist
  9.  * commands such as (un)subscribe, help and list archives.
  10.  *
  11.  * @copyright 1999-2020 The SquirrelMail Project Team
  12.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  13.  * @version $Id: functions.php 14845 2020-01-07 08:09:34Z pdontthink $
  14.  * @package plugins
  15.  * @subpackage listcommands
  16.  */
  17.  
  18. /**
  19.   * Get current list of subscribed non-RFC-compliant mailing lists for logged-in user
  20.   *
  21.   * @return array The list of mailing list addresses, keyed by integer index
  22.   */
  23. function get_non_rfc_lists({
  24.     global $username$data_dir;
  25.     $lists getPref($data_dir$username'non_rfc_lists'array());
  26.     $new_lists array();
  27.     if (!empty($lists)) {
  28.         $lists explode(':'$lists);
  29.         foreach ($lists as $list{
  30.             list($index$list_addrexplode('_'$list);
  31.             if ((!empty($index|| $index === '0'&& !empty($list_addr))
  32.                 $new_lists[$index$list_addr;
  33.         }
  34.     }
  35.     $lists $new_lists;
  36.     sort($lists);
  37.     return $lists;
  38. }
  39.  
  40. /**
  41.   * Show mailing list management option section on options page
  42.   */
  43. {
  44.     global $optpage_blocks$listcommands_allow_non_rfc_list_management;
  45.  
  46.     // only allow management of non-RFC lists if admin deems necessary
  47.     //
  48.     @include_once(SM_PATH 'plugins/listcommands/config.php');
  49.     if (!$listcommands_allow_non_rfc_list_management)
  50.         return;
  51.  
  52.     $optpage_blocks[array(
  53.         'name' => _("Mailing Lists"),
  54.         'url'  => '../plugins/listcommands/options.php',
  55.         '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."),
  56.         'js'   => false
  57.     );
  58.  
  59. }
  60.  
  61. /**
  62.  * internal function that builds mailing list links
  63.  */
  64.     global $passed_id$passed_ent_id$mailbox$message
  65.            $startMessage$oTemplate$listcommands_allow_non_rfc_list_management;
  66.  
  67.     @include_once(SM_PATH 'plugins/listcommands/config.php');
  68.  
  69.     /**
  70.      * Array of commands we can deal with from the header. The Reply option
  71.      * is added later because we generate it using the Post information.
  72.      */
  73.     $fieldsdescr listcommands_fieldsdescr();
  74.     $links array();
  75.  
  76.     foreach ($message->rfc822_header->mlist as $cmd => $actions{
  77.  
  78.         /* I don't know this action... skip it */
  79.         if !array_key_exists($cmd$fieldsdescr) ) {
  80.             continue;
  81.         }
  82.  
  83.         /* proto = {mailto,href} */
  84.         $aActions array_keys($actions);
  85.         // note that we only use the first cmd/action, ignore the rest
  86.         $proto array_shift($aActions);
  87.         $act   array_shift($actions);
  88.  
  89.         if ($proto == 'mailto'{
  90.  
  91.             $identity '';
  92.  
  93.             if (($cmd == 'post'|| ($cmd == 'owner')) {
  94.                 $url 'src/compose.php?'.
  95.                     (isset($startMessage)?'startMessage='.$startMessage.'&amp;':'');
  96.             else {
  97.                 $url "plugins/listcommands/mailout.php?action=$cmd&amp;";
  98.  
  99.                 // try to find which identity the mail should come from
  100.                 include_once(SM_PATH 'functions/identity.php');
  101.                 $idents get_identities();
  102.                 // ripped from src/compose.php
  103.                 $identities array();
  104.                 if (count($idents1{
  105.                     foreach($idents as $nr=>$data{
  106.                         $enc_from_name '"'.$data['full_name'].'" <'$data['email_address'].'>';
  107.                         $identities[$enc_from_name;
  108.                     }
  109.  
  110.                     $identity_match $message->rfc822_header->findAddress($identities);
  111.                     if ($identity_match !== FALSE{
  112.                         $identity $identity_match;
  113.                     }
  114.                 }
  115.             }
  116.  
  117.             // if things like subject are given, peel them off and give
  118.             // them to src/compose.php as is (not encoded)
  119.             if (strpos($act'?'0{
  120.                list($act$parametersexplode('?'$act2);
  121.                $parameters '&amp;identity=' $identity '&amp;' $parameters;
  122.             else {
  123.                $parameters '&amp;identity=' $identity;
  124.             }
  125.  
  126.             $url .= 'send_to=' urlencode($act$parameters;
  127.  
  128.             $links[$cmdmakeComposeLink($url$fieldsdescr[$cmd]);
  129.  
  130.             if ($cmd == 'post'{
  131.                 if (!isset($mailbox))
  132.                     $mailbox 'INBOX';
  133.                 $url .= '&amp;passed_id='.$passed_id.
  134.                     '&amp;mailbox='.urlencode($mailbox).
  135.                     (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
  136.                 $url .= '&amp;smaction=reply';
  137.  
  138.                 $links['reply'makeComposeLink($url$fieldsdescr['reply']);
  139.             }
  140.         else if ($proto == 'href'{
  141.             $links[$cmdcreate_hyperlink($act$fieldsdescr[$cmd]'_blank');
  142.         }
  143.     }
  144.  
  145.  
  146.     // allow non-rfc reply link if admin allows and message is from 
  147.     // non-rfc list the user has configured
  148.     //
  149.     if ($listcommands_allow_non_rfc_list_management{
  150.  
  151.         $non_rfc_lists get_non_rfc_lists();
  152.  
  153.         $recipients formatRecipientString($message->rfc822_header->to"to"' '
  154.                     . formatRecipientString($message->rfc822_header->cc"cc"' '
  155.                     . formatRecipientString($message->rfc822_header->bcc"bcc");
  156.  
  157.         if (!in_array('post'array_keys($links))) {
  158.  
  159.             foreach ($non_rfc_lists as $non_rfc_list{
  160.                 if (preg_match('/(^|,|<|\s)' preg_quote($non_rfc_list'($|,|>|\s)/'$recipients)) {
  161.                     $url 'src/compose.php?'
  162.                          . (isset($startMessage)?'startMessage='.$startMessage.'&amp;':'')
  163.                          . 'send_to=' str_replace('?','&amp;'$non_rfc_list);
  164.  
  165.                     $links['post'makeComposeLink($url$fieldsdescr['post']);
  166.  
  167.                     break;
  168.                 }
  169.             }
  170.  
  171.         }
  172.  
  173.         if (!in_array('reply'array_keys($links))) {
  174.  
  175.             foreach ($non_rfc_lists as $non_rfc_list{
  176.                 if (preg_match('/(^|,|\s)' preg_quote($non_rfc_list'($|,|\s)/'$recipients)) {
  177.                     if (!isset($mailbox))
  178.                         $mailbox 'INBOX';
  179.                     $url 'src/compose.php?'
  180.                          . (isset($startMessage)?'startMessage='.$startMessage.'&amp;':'')
  181.                          . 'send_to=' str_replace('?','&amp;'$non_rfc_list)
  182.                          . '&amp;passed_id='.$passed_id
  183.                          . '&amp;mailbox='.urlencode($mailbox)
  184.                          . (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'')
  185.                          . '&amp;smaction=reply';
  186.  
  187.                     $links['reply'makeComposeLink($url$fieldsdescr['reply']);
  188.  
  189.                     break;
  190.                 }
  191.             }
  192.  
  193.         }
  194.  
  195.     }
  196.  
  197.  
  198.     if (count($links0{
  199.         $oTemplate->assign('links'$links);
  200.         $output $oTemplate->fetch('plugins/listcommands/read_body_header.tpl');
  201.         return array('read_body_header' => $output);
  202.     }
  203.  
  204. }
  205.  
  206. /**
  207.  * Returns an array with the actions as translated strings.
  208.  * @return array action as key, translated string as value
  209.  */
  210.     return array('post'   => _("Post to List"),
  211.             'reply'       => _("Reply to List"),
  212.             'subscribe'   => _("Subscribe"),
  213.             'unsubscribe' => _("Unsubscribe"),
  214.             'archive'     => _("List Archives"),
  215.             'owner'       => _("Contact Listowner"),
  216.             'help'        => _("Help"));
  217. }

Documentation generated on Mon, 13 Jan 2020 04:22:32 +0100 by phpDocumentor 1.4.3