[ Index ]
 

Code source de IMP H3 (4.1.5)

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/lib/Maintenance/Task/ -> rename_sentmail_monthly.php (source)

   1  <?php
   2  /**
   3   * Maintenance module that renames the sent-mail folder.
   4   *
   5   * $Horde: imp/lib/Maintenance/Task/rename_sentmail_monthly.php,v 1.28.10.8 2007/01/02 13:55:01 jan Exp $
   6   *
   7   * Copyright 2001-2007 Michael Slusarz <slusarz@bigworm.colorado.edu>
   8   *
   9   * See the enclosed file COPYING for license information (GPL). If you
  10   * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  11   *
  12   * @author  Michael Slusarz <slusarz@bigworm.colorado.edu>
  13   * @since   IMP 2.3.7
  14   * @package Horde_Maintenance
  15   */
  16  class Maintenance_Task_rename_sentmail_monthly extends Maintenance_Task {
  17  
  18      /**
  19       * Renames the old sent-mail folders.
  20       *
  21       * @return boolean  Whether all sent-mail folders were renamed.
  22       */
  23      function doMaintenance()
  24      {
  25          $success = true;
  26  
  27          include_once 'Horde/Identity.php';
  28          include_once  IMP_BASE . '/lib/Folder.php';
  29  
  30          $identity = &Identity::singleton(array('imp', 'imp'));
  31          $imp_folder = &IMP_Folder::singleton();
  32          $folder_list = $identity->getAllSentmailfolders();
  33  
  34          /* Get rid of duplicates. */
  35          $folder_list = array_unique($folder_list);
  36  
  37          foreach ($folder_list as $sent_folder) {
  38              /* Display a message to the user and rename the folder.
  39                 Only do this if sent-mail folder currently exists. */
  40              if ($imp_folder->exists($sent_folder)) {
  41                  $old_folder = Maintenance_Task_rename_sentmail_monthly::_renameSentmailMonthlyName($sent_folder);
  42                  $GLOBALS['notification']->push(sprintf(_("%s folder being renamed at the start of the month."), IMP::displayFolder($sent_folder)), 'horde.message');
  43                  if ($imp_folder->exists($old_folder)) {
  44                      $GLOBALS['notification']->push(sprintf(_("%s already exists. Your %s folder was not renamed."), IMP::displayFolder($old_folder), IMP::displayFolder($sent_folder)), 'horde.warning');
  45                      $success = false;
  46                  } else {
  47                      if ($imp_folder->rename($sent_folder, $old_folder)) {
  48                          if (!$imp_folder->create($sent_folder, $GLOBALS['prefs']->getValue('subscribe'))) {
  49                              $success = false;
  50                          }
  51                      } else {
  52                          $success = false;
  53                      }
  54                  }
  55              }
  56  
  57          }
  58  
  59          return $success;
  60      }
  61  
  62      /**
  63       * Returns information for the maintenance function.
  64       *
  65       * @return string  Description of what the operation is going to do during
  66       *                 this login.
  67       */
  68      function describeMaintenance()
  69      {
  70          include_once 'Horde/Identity.php';
  71          $identity = &Identity::singleton(array('imp', 'imp'));
  72          $folder_list = $identity->getAllSentmailfolders();
  73  
  74          /* Get rid of duplicates. */
  75          $folder_list = array_unique($folder_list);
  76  
  77          $new_folders = $old_folders = array();
  78          foreach ($folder_list as $folder) {
  79              if (!empty($folder)) {
  80                  $old_folders[] = IMP::displayFolder($folder);
  81                  $new_folders[] = IMP::displayFolder(Maintenance_Task_rename_sentmail_monthly::_renameSentmailMonthlyName($folder));
  82              }
  83          }
  84  
  85          return sprintf(_("The current folder(s) \"%s\" will be renamed to \"%s\"."), implode(', ', $old_folders), implode(', ', $new_folders));
  86      }
  87  
  88      /**
  89       * Determines the name the sent-mail folder will be renamed to.
  90       * <pre>
  91       * Folder name: sent-mail-month-year
  92       *   month = English:         3 letter abbreviation
  93       *           Other Languages: Month value (01-12)
  94       *   year  = 4 digit year
  95       * The folder name needs to be in this specific format (as opposed to a
  96       *   user-defined one) to ensure that 'delete_sentmail_monthly' processing
  97       *   can accurately find all the old sent-mail folders.
  98       * </pre>
  99       *
 100       * @access private
 101       *
 102       * @param string $folder  The name of the sent-mail folder to rename.
 103       *
 104       * @return string  New sent-mail folder name.
 105       */
 106      function _renameSentmailMonthlyName($folder)
 107      {
 108          $last_maintenance = $GLOBALS['prefs']->getValue('last_maintenance');
 109          $last_maintenance = empty($last_maintenance) ? mktime(0, 0, 0, date('m') - 1, 1) : $last_maintenance;
 110  
 111          if (substr($GLOBALS['language'], 0, 2) == 'en') {
 112              return $folder . String::convertCharset(strtolower(strftime('-%b-%Y', $last_maintenance)), NLS::getExternalCharset(), 'UTF7-IMAP');
 113          } else {
 114              return $folder . String::convertCharset(strftime('-%m-%Y', $last_maintenance), NLS::getExternalCharset(), 'UTF7-IMAP');
 115          }
 116      }
 117  
 118  }


Généré le : Thu Nov 29 12:30:07 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics