2013-02-08 20:11:44 +01:00
< ? php
/**
* Mail - admin , preferences and sidebox - menus and other hooks
*
* @ link http :// www . egroupware . org
* @ package mail
2013-10-24 09:15:48 +02:00
* @ author Stylite AG [ info @ stylite . de ]
* @ copyright ( c ) 2013 by Stylite AG < info - AT - stylite . de >
2013-02-08 20:11:44 +01:00
* @ license http :// opensource . org / licenses / gpl - license . php GPL - GNU General Public License
* @ version $Id $
*/
/**
* Class containing admin , preferences and sidebox - menus and other hooks
*/
class mail_hooks
{
/**
* Several hooks calling an instanciated mail_bo , which need to use the mail_bo :: getInstance () singelton
*
* @ param string | array $hookData
*/
static public function accountHooks ( $hookData )
{
2013-10-29 17:16:56 +01:00
if (( $default_profile_id = emailadmin_bo :: getDefaultAccID ()))
2013-02-08 20:11:44 +01:00
{
$mail_bo = mail_bo :: forceEAProfileLoad ( $default_profile_id );
switch ( is_array ( $hookData ) ? $hookData [ 'location' ] : $hookData )
{
case 'addaccount' :
$mail_bo -> addAccount ( $hookData );
break ;
case 'deleteaccount' :
$mail_bo -> deleteAccount ( $hookData );
break ;
case 'editaccount' :
$mail_bo -> updateAccount ( $hookData );
break ;
}
emailadmin_bo :: unsetCachedObjects ( $default_profile_id );
}
}
/**
* Menu for Admin >> Edit accounts
*/
static public function adminMenu ()
{
2013-10-29 17:16:56 +01:00
if (( $default_profile_id = emailadmin_bo :: getDefaultAccID ()))
2013-02-08 20:11:44 +01:00
{
2013-02-11 18:05:29 +01:00
$mail_bo = mail_bo :: forceEAProfileLoad ( $default_profile_id );
2013-02-08 20:11:44 +01:00
$ogServer = $mail_bo -> mailPreferences -> getOutgoingServer ( $default_profile_id );
//error_log(__METHOD__."() default_profile_id = $default_profile_id, get_class(ogServer)=".get_class($ogServer));
if ( ! in_array ( get_class ( $ogServer ), array ( 'defaultsmtp' , 'emailadmin_smtp' )))
{
global $menuData ;
$menuData [] = Array
(
'description' => 'email settings' ,
'url' => '/index.php' ,
'extradata' => 'menuaction=emailadmin.uiuserdata.editUserData'
);
}
}
}
/**
2013-04-09 16:43:55 +02:00
* Hook called by link - class to include mail in the appregistry of the linkage
2013-02-08 20:11:44 +01:00
*
* @ param array / string $location location and other parameters ( not used )
* @ return array with method - names
*/
static function search_link ( $location )
{
return array (
'view' => array (
2013-06-06 11:14:14 +02:00
'menuaction' => 'mail.mail_ui.displayMessage' ,
2013-02-08 20:11:44 +01:00
),
2013-06-06 11:14:14 +02:00
'view_id' => 'id' ,
2013-10-01 13:29:54 +02:00
'view_popup' => '870xegw_getWindowOuterHeight()' ,
2013-12-17 09:47:16 +01:00
//'view_popup' => '870x800',
2013-06-06 11:14:14 +02:00
'view_list' => 'mail.mail_ui.index' ,
2013-02-08 20:11:44 +01:00
'add' => array (
2013-07-20 09:23:55 +02:00
'menuaction' => 'mail.mail_compose.compose' ,
2013-02-08 20:11:44 +01:00
),
2013-12-17 09:47:16 +01:00
//'add_popup' => '870xegw_getWindowOuterHeight()',
'add_popup' => '870x800' ,
2013-07-20 09:23:55 +02:00
'edit' => array (
'menuaction' => 'mail.mail_compose.compose' ,
),
'edit_id' => 'id' ,
2013-12-17 09:47:16 +01:00
//'edit_popup' => '870xegw_getWindowOuterHeight()',
'edit_popup' => '870x800' ,
2014-01-14 18:16:49 +01:00
// register mail as handler for .eml files
2013-02-08 20:11:44 +01:00
'mime' => array (
'message/rfc822' => array (
2014-01-14 18:16:49 +01:00
'menuaction' => 'mail.mail_ui.importMessageFromVFS2DraftAndDisplay' ,
2013-02-08 20:11:44 +01:00
'mime_url' => 'formData[file]' ,
2014-01-14 18:16:49 +01:00
'mime_popup' => '870xegw_getWindowOuterHeight()' ,
2013-02-08 20:11:44 +01:00
),
),
);
}
/**
* Settings hook
*
* @ param array | string $hook_data
*/
static function settings ( $hook_data )
{
unset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'auto_hide_sidebox' ]);
if ( ! $hook_data [ 'setup' ]) // does not work on setup time
{
$folderList = array ();
$profileID = 0 ;
if ( isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'mail' ][ 'ActiveProfileID' ]))
$profileID = ( int ) $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'mail' ][ 'ActiveProfileID' ];
2013-12-05 13:32:32 +01:00
try
{
$mail_bo = mail_bo :: getInstance ( true , $profileID );
$profileID = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'mail' ][ 'ActiveProfileID' ] = $mail_bo -> profileID ;
} catch ( Exception $ex ) {
error_log ( __METHOD__ . " () " . $ex -> getMessage ());
$profileID = null ;
}
2014-01-10 10:19:07 +01:00
/*
2013-12-05 10:12:17 +01:00
if ( $profileID && $mail_bo -> openConnection ( $profileID )) {
2013-02-08 20:11:44 +01:00
$folderObjects = $mail_bo -> getFolderObjects ( true , false );
foreach ( $folderObjects as $folderName => $folderInfo ) {
#_debug_array($folderData);
$folderList [ $folderName ] = $folderInfo -> displayName ;
}
if ( $GLOBALS [ 'type' ] === 'user' )
{
$trashFolder = $mail_bo -> getTrashFolder ();
$draftFolder = $mail_bo -> getDraftFolder ();
$templateFolder = $mail_bo -> getTemplateFolder ();
$sentFolder = $mail_bo -> getSentFolder ();
// use displaynames, if available
if ( isset ( $folderList [ $trashFolder ])) $trashFolder = $folderList [ $trashFolder ];
if ( isset ( $folderList [ $draftFolder ])) $draftFolder = $folderList [ $draftFolder ];
if ( isset ( $folderList [ $templateFolder ])) $templateFolder = $folderList [ $templateFolder ];
if ( isset ( $folderList [ $sentFolder ])) $sentFolder = $folderList [ $sentFolder ];
}
$mail_bo -> closeConnection ();
}
2014-01-10 10:19:07 +01:00
*/
2013-02-08 20:11:44 +01:00
$availableAutoFolders [ 'none' ] = lang ( 'none, create all' );
2013-02-11 18:05:29 +01:00
foreach ( mail_bo :: $autoFolders as $aname ) {
2013-02-08 20:11:44 +01:00
$availableAutoFolders [ $aname ] = lang ( $aname );
}
2013-02-11 18:05:29 +01:00
$mailConfig = config :: read ( 'mail' );
2013-02-08 20:11:44 +01:00
}
$connectionTimeout = array (
'0' => lang ( 'use default timeout (20 seconds)' ),
'10' => '10' , // timeout used in SIEVE
'20' => '20' ,
'30' => '30' ,
'40' => '40' ,
'50' => '50' ,
'60' => '60' ,
'70' => '70' ,
'80' => '80' ,
'90' => '90' ,
);
$no_yes = array (
'0' => lang ( 'no' ),
'1' => lang ( 'yes' )
);
$no_yes_copy = array_merge ( $no_yes , array ( '2' => lang ( 'yes, offer copy option' )));
$prefAllowManageFolders = $no_yes ;
$test_connection = array (
'full' => lang ( 'yes, show all debug information available for the user' ),
'nocredentials' => lang ( 'yes, but mask all usernames and passwords' ),
'nopasswords' => lang ( 'yes, but mask all passwords' ),
'basic' => lang ( 'yes, show basic info only' ),
'reset' => lang ( 'yes, only trigger connection reset' ),
'none' => lang ( 'no' ),
);
$forwardOptions = array (
'asmail' => lang ( 'forward as attachment' ),
'inline' => lang ( 'forward inline' ),
);
$sortOrder = array (
'0' => lang ( 'date(newest first)' ),
'1' => lang ( 'date(oldest first)' ),
'3' => lang ( 'from(A->Z)' ),
'2' => lang ( 'from(Z->A)' ),
'5' => lang ( 'subject(A->Z)' ),
'4' => lang ( 'subject(Z->A)' ),
'7' => lang ( 'size(0->...)' ),
'6' => lang ( 'size(...->0)' )
);
$trustServersUnseenOptions = array_merge (
$no_yes ,
array ( '2' => lang ( 'yes' ) . ' - ' . lang ( 'but check shared folders' ))
);
$selectOptions = array_merge (
$no_yes ,
array ( '2' => lang ( 'yes' ) . ' - ' . lang ( 'small view' ))
);
$newWindowOptions = array (
'1' => lang ( 'only one window' ),
'2' => lang ( 'allways a new window' ),
);
$deleteOptions = array (
'move_to_trash' => lang ( 'move to trash' ),
'mark_as_deleted' => lang ( 'mark as deleted' ),
'remove_immediately' => lang ( 'remove immediately' )
);
$sendOptions = array (
'move_to_sent' => lang ( 'send message and move to send folder (if configured)' ),
'send_only' => lang ( 'only send message, do not copy a version of the message to the configured sent folder' )
);
$composeOptions = array (
'html' => lang ( 'html' ),
'text' => lang ( 'text/plain' ),
);
$replyOptions = array (
'none' => lang ( 'use source as displayed, if applicable' ),
'html' => lang ( 'force html' ),
'text' => lang ( 'force plain text' ),
);
$saveAsOptions = array (
2014-01-07 14:25:21 +01:00
'text_only' => lang ( 'convert only Mail to item (ignore possible attachments)' ),
2013-02-08 20:11:44 +01:00
'text' => lang ( 'convert Mail to item and attach its attachments to this item (standard)' ),
'add_raw' => lang ( 'convert Mail to item, attach its attachments and add raw message (message/rfc822 (.eml)) as attachment' ),
);
$htmlOptions = array (
'never_display' => lang ( 'never display html emails' ),
'only_if_no_text' => lang ( 'display only when no plain text is available' ),
'always_display' => lang ( 'always show html emails' ),
);
$toggle = false ;
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'select_mode' ] == 'EGW_SELECTMODE_TOGGLE' ) $toggle = true ;
$rowOrderStyle = array (
2013-02-11 18:05:29 +01:00
'mail' => lang ( 'mail' ),
2013-02-08 20:11:44 +01:00
'outlook' => 'Outlook' ,
2013-02-11 18:05:29 +01:00
'mail_wCB' => lang ( 'mail' ) . ' ' . ( $toggle ? lang ( '(select mails by clicking on the line, like a checkbox)' ) : lang ( '(with checkbox enforced)' )),
2013-02-08 20:11:44 +01:00
'outlook_wCB' => 'Outlook' . ' ' . ( $toggle ? lang ( '(select mails by clicking on the line, like a checkbox)' ) : lang ( '(with checkbox enforced)' )),
);
// otherwise we get warnings during setup
if ( ! is_array ( $folderList )) $folderList = array ();
$trashOptions = array_merge (
array (
'none' => lang ( " Don't use Trash " )
),
$folderList
);
$sentOptions = array_merge (
array (
'none' => lang ( " Don't use Sent " )
),
$folderList
);
$draftOptions = array_merge (
array (
'none' => lang ( " Don't use draft folder " )
),
$folderList
);
$templateOptions = array_merge (
array (
'none' => lang ( " Don't use template folder " )
),
$folderList
);
// modify folderlist, add a none entry, to be able to force the regarding settings, if no folders apply
$folderList [ 'none' ] = lang ( 'no folders' );
/* Settings array for this app */
$settingsArray = array (
array (
'type' => 'section' ,
'title' => lang ( 'Mail settings' ),
'no_lang' => true ,
'xmlrpc' => False ,
'admin' => False
),
'message_forwarding' => array (
'type' => 'select' ,
'label' => 'how to forward messages' ,
'help' => 'Which method to use when forwarding a message' ,
'name' => 'message_forwarding' ,
'values' => $forwardOptions ,
'xmlrpc' => True ,
'admin' => False ,
'default' => 'asmail' ,
),
'composeOptions' => array (
'type' => 'select' ,
'label' => 'New message type' ,
'help' => 'start new messages with mime type plain/text or html?' ,
'name' => 'composeOptions' ,
'values' => $composeOptions ,
'xmlrpc' => True ,
'admin' => False ,
'default' => 'html' ,
),
'replyOptions' => array (
'type' => 'select' ,
'label' => 'Reply message type' ,
'help' => 'start reply messages with mime type plain/text or html or try to use the displayed format (default)?' ,
'name' => 'replyOptions' ,
'values' => $replyOptions ,
'xmlrpc' => True ,
'admin' => False ,
'default' => 'none' ,
),
'disableRulerForSignatureSeparation' => array (
'type' => 'select' ,
'label' => 'disable Ruler for separation of mailbody and signature' ,
'help' => 'Turn off horizontal line between signature and composed message (this is not according to RFC).<br>If you use templates, this option is only applied to the text part of the message.' ,
'name' => 'disableRulerForSignatureSeparation' ,
'values' => $no_yes ,
'xmlrpc' => True ,
'default' => 0 ,
'admin' => False ,
),
'insertSignatureAtTopOfMessage' => array (
'type' => 'select' ,
'label' => 'signature at top' ,
'help' => 'insert the signature at top of the new (or reply) message when opening compose dialog (you may not be able to switch signatures)' ,
'name' => 'insertSignatureAtTopOfMessage' ,
'values' => $no_yes ,
'xmlrpc' => True ,
'default' => 0 ,
'admin' => False ,
),
'attachVCardAtCompose' => array (
'type' => 'select' ,
'label' => 'Attach vCard' ,
'help' => 'attach users VCard at compose to every new mail' ,
'name' => 'attachVCardAtCompose' ,
'values' => $no_yes ,
'xmlrpc' => True ,
'default' => 0 ,
'admin' => False ,
),
array (
'type' => 'section' ,
'title' => lang ( 'General settings' ),
'no_lang' => true ,
'xmlrpc' => False ,
'admin' => False
),
'htmlOptions' => array (
'type' => 'select' ,
'label' => 'display of html emails' ,
'help' => 'What do do with html email' ,
'name' => 'htmlOptions' ,
'values' => $htmlOptions ,
'xmlrpc' => True ,
'admin' => False ,
'forced' => 'always_display' ,
),
'message_newwindow' => array (
'type' => 'select' ,
'label' => 'display messages in multiple windows' ,
'help' => 'When displaying messages in a popup, re-use the same popup for all or open a new popup for each message' ,
'name' => 'message_newwindow' ,
'values' => $newWindowOptions ,
'xmlrpc' => True ,
'admin' => False ,
'forced' => '1' ,
),
'allowExternalIMGs' => array (
'type' => 'check' ,
'label' => 'Allow external images' ,
'help' => 'allow images from external sources in html emails' ,
'name' => 'allowExternalIMGs' ,
'xmlrpc' => True ,
'admin' => True ,
'forced' => true ,
),
'sortOrder' => array (
'type' => 'select' ,
'label' => 'Sort order' ,
'help' => 'Default sorting order' ,
'name' => 'sortOrder' ,
'values' => $sortOrder ,
'xmlrpc' => True ,
'admin' => False ,
'default' => '0' , // newest first
),
'rowOrderStyle' => array (
'type' => 'select' ,
'label' => 'row order style' ,
'help' => 'What order the list columns are in' ,
'name' => 'rowOrderStyle' ,
'values' => $rowOrderStyle ,
'xmlrpc' => True ,
'admin' => False ,
2013-02-11 18:05:29 +01:00
'default' => 'mail' ,
2013-02-08 20:11:44 +01:00
),
'prefaskformove' => array (
'type' => 'select' ,
'label' => 'Confirm move to folder' ,
'help' => 'Do you want to be asked for confirmation before moving selected messages to another folder?' ,
'name' => 'prefaskformove' ,
'values' => $no_yes_copy ,
'xmlrpc' => True ,
'admin' => False ,
'forced' => '1' ,
),
'prefaskformultipleforward' => array (
'type' => 'select' ,
'label' => 'Confirm attach message' ,
'help' => 'Do you want to be asked for confirmation before attaching selected messages to new mail?' ,
'name' => 'prefaskformultipleforward' ,
'values' => $no_yes ,
'xmlrpc' => True ,
'admin' => False ,
'forced' => '1' ,
),
2014-01-10 10:19:07 +01:00
/*
2013-02-08 20:11:44 +01:00
'mainscreen_showmail' => array (
'type' => 'select' ,
'label' => 'show new messages on home page' ,
'help' => 'Should new messages show up on the Home page' ,
'name' => 'mainscreen_showmail' ,
'values' => $selectOptions ,
'xmlrpc' => True ,
'admin' => False ,
),
'mainscreen_showfolders' => array (
'type' => 'multiselect' ,
'label' => 'home page folders' ,
'help' => 'if shown, which folders should appear on the Home page' ,
'name' => 'mainscreen_showfolders' ,
'values' => $folderList ,
'xmlrpc' => True ,
'admin' => False ,
),
2014-01-10 10:19:07 +01:00
*/
2013-02-08 20:11:44 +01:00
array (
'type' => 'section' ,
'title' => lang ( 'Folder settings' ),
'no_lang' => true ,
'xmlrpc' => False ,
'admin' => False
),
'deleteOptions' => array (
'type' => 'select' ,
'label' => 'when deleting messages' ,
'help' => 'what to do when you delete a message' ,
'name' => 'deleteOptions' ,
'values' => $deleteOptions ,
'xmlrpc' => True ,
'admin' => False ,
'default' => 'move_to_trash' ,
),
'sendOptions' => array (
'type' => 'select' ,
'label' => 'when sending messages' ,
'help' => 'what to do when you send a message' ,
'name' => 'sendOptions' ,
'values' => $sendOptions ,
'xmlrpc' => True ,
'admin' => False ,
'default' => 'move_to_sent' ,
),
'trustServersUnseenInfo' => array (
'type' => 'select' ,
'label' => 'trust servers SEEN / UNSEEN info' ,
'help' => 'Trust the server when retrieving the folder status. if you select no, we will search for the UNSEEN messages and count them ourselves' ,
'name' => 'trustServersUnseenInfo' ,
'values' => $trustServersUnseenOptions ,
'xmlrpc' => True ,
'default' => 2 ,
'admin' => False ,
),
'showAllFoldersInFolderPane' => array (
'type' => 'select' ,
'label' => 'show all Folders' ,
'help' => 'show all folders, (subscribed AND unsubscribed) in Main Screen Folder Pane' ,
'name' => 'showAllFoldersInFolderPane' ,
'values' => $no_yes ,
'xmlrpc' => True ,
'default' => 0 ,
'admin' => False ,
),
array (
'type' => 'section' ,
'title' => lang ( 'Configuration settings' ),
'no_lang' => true ,
'xmlrpc' => False ,
'admin' => False
),
2014-02-05 21:20:02 +01:00
/* 'prefpreventmanagefolders' => array (
2013-02-08 20:11:44 +01:00
'type' => 'select' ,
'label' => 'Prevent managing folders' ,
'help' => 'Do you want to prevent the managing of folders (creation, accessrights AND subscribtion)?' ,
'name' => 'prefpreventmanagefolders' ,
'values' => $prefAllowManageFolders ,
'xmlrpc' => True ,
'admin' => False ,
'forced' => '0' ,
),
'prefpreventforwarding' => array (
'type' => 'select' ,
'label' => 'Prevent managing forwards' ,
'help' => 'Do you want to prevent the editing/setup for forwarding of mails via settings (, even if SIEVE is enabled)?' ,
'name' => 'prefpreventforwarding' ,
'values' => $no_yes ,
'xmlrpc' => True ,
'admin' => False ,
'forced' => '0' ,
),
'prefpreventnotificationformailviaemail' => array (
'type' => 'select' ,
'label' => 'Prevent managing notifications' ,
'help' => 'Do you want to prevent the editing/setup of notification by mail to other emailadresses if emails arrive (, even if SIEVE is enabled)?' ,
'name' => 'prefpreventnotificationformailviaemail' ,
'values' => $no_yes ,
'xmlrpc' => True ,
'admin' => False ,
'forced' => '1' ,
),
'prefpreventeditfilterrules' => array (
'type' => 'select' ,
'label' => 'Prevent managing filters' ,
'help' => 'Do you want to prevent the editing/setup of filter rules (, even if SIEVE is enabled)?' ,
'name' => 'prefpreventeditfilterrules' ,
'values' => $no_yes ,
'xmlrpc' => True ,
'admin' => False ,
'forced' => '0' ,
),
'prefpreventabsentnotice' => array (
'type' => 'select' ,
'label' => 'Prevent managing vacation notice' ,
'help' => 'Do you want to prevent the editing/setup of the absent/vacation notice (, even if SIEVE is enabled)?' ,
'name' => 'prefpreventabsentnotice' ,
'values' => $no_yes ,
'xmlrpc' => True ,
'admin' => False ,
'forced' => '0' ,
),
'prefcontroltestconnection' => array (
'type' => 'select' ,
'label' => 'Test connection' ,
'help' => 'Show Test Connection section and control the level of info displayed?' ,
'name' => 'prefcontroltestconnection' ,
'values' => $test_connection ,
'xmlrpc' => True ,
'admin' => False ,
'forced' => '0' ,
2014-02-05 21:20:02 +01:00
), */
2013-02-08 20:11:44 +01:00
'notavailableautofolders' => array (
'type' => 'multiselect' ,
'label' => 'do not auto create folders' ,
'help' => 'which folders - in general - should NOT be automatically created, if not existing' ,
'name' => 'notavailableautofolders' ,
'values' => $availableAutoFolders ,
'xmlrpc' => True ,
'admin' => False ,
'forced' => 'none' ,
),
'saveAsOptions' => array (
'type' => 'select' ,
'label' => 'Save as' ,
'help' => 'when saving messages as item of a different app' ,
'name' => 'saveAsOptions' ,
'values' => $saveAsOptions ,
'xmlrpc' => True ,
'admin' => False ,
'default' => 'text' ,
),
2014-01-10 10:19:07 +01:00
'add_popup' => '870x800' ,
2013-02-08 20:11:44 +01:00
);
if ( ! $GLOBALS [ 'egw_info' ][ 'apps' ][ 'stylite' ]) unset ( $settingsArray [ 'attachVCardAtCompose' ]);
return $settingsArray ;
}
/**
* Admin hook
*
* @ param array | string $hook_data
*/
static function admin ( $hook_data )
{
unset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'auto_hide_sidebox' ]);
// Only Modify the $file and $title variables.....
2013-02-11 18:05:29 +01:00
$title = $appname = 'mail' ;
2013-02-08 20:11:44 +01:00
$profileID = 0 ;
2013-02-11 18:05:29 +01:00
if ( isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'mail' ][ 'ActiveProfileID' ]))
$profileID = ( int ) $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'mail' ][ 'ActiveProfileID' ];
2013-02-08 20:11:44 +01:00
$file = Array (
2013-02-11 18:05:29 +01:00
'Site Configuration' => egw :: link ( '/index.php' , array ( 'menuaction' => 'admin.uiconfig.index' , 'appname' => 'mail' )),
2013-02-08 20:11:44 +01:00
);
display_section ( $appname , $title , $file );
}
/**
* Sidebox menu hook
*
* @ param array | string $hook_data
*/
static function sidebox_menu ( $hook_data )
{
//error_log(__METHOD__);
// always show the side bar
unset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'auto_hide_sidebox' ]);
2013-02-11 18:05:29 +01:00
$appname = 'mail' ;
2013-02-08 20:11:44 +01:00
$menu_title = $GLOBALS [ 'egw_info' ][ 'apps' ][ $appname ][ 'title' ] . ' ' . lang ( 'Menu' );
$file = array ();
$profileID = 0 ;
2013-02-11 18:05:29 +01:00
if ( isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'mail' ][ 'ActiveProfileID' ]))
$profileID = ( int ) $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'mail' ][ 'ActiveProfileID' ];
2013-12-05 13:32:32 +01:00
try
{
$mail_bo = mail_bo :: getInstance ( true , $profileID );
$profileID = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'mail' ][ 'ActiveProfileID' ] = $mail_bo -> profileID ;
} catch ( Exception $ex ) {
error_log ( __METHOD__ . " () " . $ex -> getMessage ());
$profileID = null ;
}
2013-02-08 20:11:44 +01:00
$preferences =& $mail_bo -> mailPreferences ;
2013-10-11 13:43:01 +02:00
$serverCounter = $sieveEnabledServerCounter = 0 ;
2013-12-17 09:47:16 +01:00
// account select box
$selectedID = $profileID ;
$allAccountData = emailadmin_account :: search ( $only_current_user = true , $just_name = false , $order_by = null );
if ( $allAccountData ) {
$rememberFirst = $selectedFound = null ;
foreach ( $allAccountData as $tmpkey => $icServers )
2013-10-11 13:43:01 +02:00
{
2013-12-17 09:47:16 +01:00
if ( is_null ( $rememberFirst )) $rememberFirst = $tmpkey ;
if ( $tmpkey == $selectedID ) $selectedFound = true ;
//error_log(__METHOD__.__LINE__.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host));
$host = $icServers -> acc_sieve_host ;
if ( empty ( $host )) continue ;
if ( $icServers -> acc_sieve_enabled && $icServers -> acc_sieve_port ) $sieveEnabledServerCounter ++ ;
2013-10-11 13:43:01 +02:00
$serverCounter ++ ;
2013-12-17 09:47:16 +01:00
//error_log(__METHOD__.__LINE__.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id]));
2013-10-11 13:43:01 +02:00
}
}
2013-12-17 09:47:16 +01:00
$file = array ();
2013-02-13 15:02:02 +01:00
// Destination div for folder tree
$file [] = array (
'no_lang' => true ,
2013-07-20 09:23:55 +02:00
'text' => '<span id="mail-index_buttonmailcreate" class="button" />' ,
'link' => false ,
'icon' => false
);
$file [] = array (
'no_lang' => true ,
'text' => '<span id="mail-tree_target" class="dtree" />' ,
2013-02-13 15:02:02 +01:00
'link' => false ,
'icon' => false
);
2013-12-17 09:47:16 +01:00
$showMainScreenStuff = false ;
2013-02-08 20:11:44 +01:00
// import Message link - only when the required library is available
if (( @ include_once 'Mail/mimeDecode.php' ) !== false )
{
$linkData = array (
2013-02-11 18:05:29 +01:00
'menuaction' => 'mail.mail_ui.importMessage' ,
2013-02-08 20:11:44 +01:00
);
$file += array (
2013-10-01 13:29:54 +02:00
'import message' => " javascript:egw_openWindowCentered2(' " . egw :: link ( '/index.php' , $linkData , false ) . " ','importMessageDialog',870,125,'no',' $appname '); " ,
2013-02-08 20:11:44 +01:00
);
}
2013-12-17 09:47:16 +01:00
// create account wizard
2014-02-05 21:20:02 +01:00
if ( self :: access ( 'createaccount' ))
{
$file += array (
'create new account' => " javascript:egw_openWindowCentered2(' " .
egw :: link ( '/index.php' , array ( 'menuaction' => 'mail.mail_wizard.add' ), '' ) .
" ','_blank',640,480,'yes') " ,
);
}
if ( self :: access ( 'testconnection' ))
{
$file [ 'Test Connection' ] = egw :: link ( '/index.php' , 'menuaction=mail.mail_ui.TestConnection&appname=mail' );
}
2013-02-08 20:11:44 +01:00
// display them all
display_sidebox ( $appname , $menu_title , $file );
2013-12-17 09:47:16 +01:00
unset ( $file );
if ( $preferences && $sieveEnabledServerCounter )
2013-02-08 20:11:44 +01:00
{
$menu_title = lang ( 'Sieve' );
2013-10-11 13:43:01 +02:00
$linkData = array
(
'menuaction' => 'mail.mail_sieve.index' ,
2014-02-11 22:26:31 +01:00
'ajax' => 'true'
2013-10-11 13:43:01 +02:00
);
2013-11-04 12:22:38 +01:00
if ( empty ( $preferences [ 'prefpreventeditfilterrules' ]) || $preferences [ 'prefpreventeditfilterrules' ] == 0 )
2013-10-11 13:43:01 +02:00
$file [ 'filter rules' ] = egw :: link ( '/index.php' , $linkData );
2013-02-08 20:11:44 +01:00
2013-10-11 13:43:01 +02:00
$linkData = array
(
'menuaction' => 'mail.mail_sieve.editVacation' ,
2014-02-11 22:26:31 +01:00
'ajax' => 'true'
2013-10-11 13:43:01 +02:00
);
2013-11-04 12:22:38 +01:00
if ( empty ( $preferences [ 'prefpreventabsentnotice' ]) || $preferences [ 'prefpreventabsentnotice' ] == 0 )
2013-10-11 13:43:01 +02:00
{
$file [ 'vacation notice' ] = egw :: link ( '/index.php' , $linkData );
}
2013-11-04 12:22:38 +01:00
if (( empty ( $preferences [ 'prefpreventnotificationformailviaemail' ]) ||
$preferences [ 'prefpreventnotificationformailviaemail' ] == 0 ))
2013-10-11 13:43:01 +02:00
{
2014-02-11 22:26:31 +01:00
$file [ 'email notification' ] = egw :: link ( '/index.php' , 'menuaction=mail.mail_sieve.editEmailNotification&ajax=true' ); //Added email notifications
2013-10-11 13:43:01 +02:00
}
if ( $sieveEnabledServerCounter >= 1 )
{
if ( $sieveEnabledServerCounter == 1 && ( $icServer instanceof defaultimap )) {
if ( $icServer -> enableSieve )
2013-02-08 20:11:44 +01:00
{
2013-10-11 13:43:01 +02:00
if ( count ( $file )) display_sidebox ( $appname , $menu_title , $file );
unset ( $file );
2013-02-08 20:11:44 +01:00
}
2013-10-11 13:43:01 +02:00
}
else
{
2013-02-08 20:11:44 +01:00
if ( count ( $file )) display_sidebox ( $appname , $menu_title , $file );
unset ( $file );
}
}
2013-07-25 17:35:44 +02:00
2013-02-08 20:11:44 +01:00
}
2013-02-11 18:05:29 +01:00
2013-02-08 20:11:44 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ])
{
$file = Array (
2013-02-11 18:05:29 +01:00
'Site Configuration' => egw :: link ( '/index.php' , 'menuaction=admin.uiconfig.index&appname=' . $appname ),
2013-02-08 20:11:44 +01:00
);
display_sidebox ( $appname , lang ( 'Admin' ), $file );
}
}
2014-01-10 10:19:07 +01:00
/**
* checks users mailbox and sends a notification if new mails have arrived
*
* @ return boolean true or false
*/
static function notification_check_mailbox ()
{
$recipient = ( object ) $GLOBALS [ 'egw' ] -> accounts -> read ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ]);
$prefs = new preferences ( $recipient -> account_id );
$preferences = $prefs -> read ();
// TODO: no possibility to set that at this time; always use INBOX
2014-02-06 11:31:21 +01:00
if ( empty ( $preferences [ 'mail' ][ 'notify_folders' ])) return true ; //$preferences['mail']['notify_folders']='INBOX';
2014-01-10 10:19:07 +01:00
//error_log(__METHOD__.__LINE__.array2string($preferences['mail']['notify_folders']));
if ( ! isset ( $preferences [ 'mail' ][ 'notify_folders' ]) || empty ( $preferences [ 'mail' ][ 'notify_folders' ]) || $preferences [ 'mail' ][ 'notify_folders' ] == 'none' ) {
return true ; //no pref set for notifying - exit
}
$notify_folders = explode ( ',' , $preferences [ 'mail' ][ 'notify_folders' ]);
if ( count ( $notify_folders ) == 0 ) {
return true ; //no folders configured for notifying - exit
}
$activeProfile = ( int ) $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'mail' ][ 'ActiveProfileID' ];
//error_log(__METHOD__.__LINE__.' (user: '.$recipient->account_lid.') Active Profile:'.$activeProfile);
$bomail = mail_bo :: getInstance ( false , $activeProfile );
$activeProfile = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'mail' ][ 'ActiveProfileID' ] = $bomail -> profileID ;
// buffer mail sessiondata, as they are needed for information exchange by the app itself
//$bufferFMailSession = $bomail->sessionData;
try
{
$bomail -> openConnection ( $activeProfile );
} catch ( Exception $e ) {
// TODO: This is ugly. Log a bit nicer!
$error = $e -> getMessage ();
2014-01-14 10:21:34 +01:00
error_log ( __METHOD__ . __LINE__ . ' # ' . ' (user: ' . $recipient -> account_lid . '): cannot connect to mailbox with Profile:' . $activeProfile . '. Please check your prefs!' );
2014-01-10 10:19:07 +01:00
if ( ! empty ( $error )) error_log ( __METHOD__ . __LINE__ . ' # ' . $error );
error_log ( __METHOD__ . __LINE__ . ' # Instance=' . $GLOBALS [ 'egw_info' ][ 'user' ][ 'domain' ] . ', User=' . $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_lid' ]);
return false ; // cannot connect to mailbox
}
$notified_mail_uidsCache = egw_cache :: getCache ( egw_cache :: INSTANCE , 'email' , 'notified_mail_uids' . trim ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ]), null , array (), $expiration = 60 * 60 * 24 * 2 );
//$notified_mail_uidsCache = array();
$recent_messages = array ();
$folder_status = array ();
foreach ( $notify_folders as $id => $notify_folder ) {
if ( empty ( $notify_folder )) continue ;
if ( ! is_array ( $notified_mail_uidsCache [ $activeProfile ][ $notify_folder ])) {
$notified_mail_uidsCache [ $activeProfile ][ $notify_folder ] = array ();
}
$folder_status [ $notify_folder ] = $bomail -> getFolderStatus ( $notify_folder );
$cutoffdate = time ();
$cutoffdate = $cutoffdate - ( 60 * 60 * 24 * 14 ); // last 14 days
$_filter = array ( 'status' => array ( 'UNSEEN' , 'UNDELETED' ), 'type' => " SINCE " , 'string' => date ( " d-M-Y " , $cutoffdate ));
//error_log(__METHOD__.__LINE__.' (user: '.$recipient->account_lid.') Mailbox:'.$notify_folder.' filter:'.array2string($_filter));
// $_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true
$headers = $bomail -> getHeaders ( $notify_folder , 1 , 999 , 0 , true , $_filter , null , false );
if ( is_array ( $headers [ 'header' ]) && count ( $headers [ 'header' ]) > 0 ) {
foreach ( $headers [ 'header' ] as $id => $header ) {
//error_log(__METHOD__.__LINE__.' Found Message:'.$header['uid'].' Subject:'.$header['subject']);
// check if unseen mail has already been notified
if ( ! in_array ( $header [ 'uid' ], $notified_mail_uidsCache [ $activeProfile ][ $notify_folder ])) {
// got a REAL recent message
$header [ 'folder' ] = $notify_folder ;
$header [ 'folder_display_name' ] = $folder_status [ $notify_folder ][ 'displayName' ];
$header [ 'folder_base64' ] = base64_encode ( $notify_folder );
$recent_messages [] = $header ;
}
}
}
}
//error_log(__METHOD__.__LINE__.' Found Messages for Profile'.$activeProfile.':'.array2string($recent_messages).'<->'.array2string($notified_mail_uidsCache[$activeProfile]));
// restore the mail session data, as they are needed by the app itself
if ( count ( $recent_messages ) > 0 ) {
// create notify message
$notification_subject = lang ( " You've got new mail " );
$values = array ();
$values [] = array (); // content array starts at index 1
foreach ( $recent_messages as $id => $recent_message ) {
error_log ( __METHOD__ . __LINE__ . ' Found Message for Profile ' . $activeProfile . ':' . array2string ( $recent_message ));
$values [] = array (
'mail_uid' => $recent_message [ 'uid' ],
'mail_folder' => $recent_message [ 'folder_display_name' ],
'mail_folder_base64' => $recent_message [ 'folder_base64' ],
'mail_subject' => $recent_message [ 'subject' ],
'mail_from' => ! empty ( $recent_message [ 'sender_name' ]) ? $recent_message [ 'sender_name' ] : $recent_message [ 'sender_address' ],
'mail_received' => $recent_message [ 'date' ],
);
// save notification status
$notified_mail_uidsCache [ $activeProfile ][ $recent_message [ 'folder' ]][] = $recent_message [ 'uid' ];
}
// create etemplate
$tpl = new etemplate_old ( 'mail.checkmailbox' );
$notification_message = $tpl -> exec ( false , $values , array (), array (), array (), 1 );
//error_log(__METHOD__.__LINE__.array2string($notification_message));
// send notification
$notification = new notifications ();
$notification -> set_receivers ( array ( $recipient -> account_id ));
$notification -> set_message ( $notification_message );
//$notification->set_popupmessage($notification_message);
$notification -> set_sender ( $recipient -> account_id );
$notification -> set_subject ( $notification_subject );
$notification -> set_skip_backends ( array ( 'email' ));
$notification -> send ();
}
egw_cache :: setCache ( egw_cache :: INSTANCE , 'email' , 'notified_mail_uids' . trim ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ]), $notified_mail_uidsCache , $expiration = 60 * 60 * 24 * 2 );
return true ;
}
2014-02-05 21:20:02 +01:00
/**
* Hook returning options for deny_ * groups
*
* @ param string $name function name
* @ param array $arguments
* @ return string html
*/
public static function __callStatic ( $name , $arguments )
{
if ( substr ( $name , 0 , 5 ) != 'deny_' )
{
throw new egw_exception_wrong_parameter ( " No method $name ! " );
}
$accountsel = new uiaccountsel ();
return '<input type="hidden" value="" name="newsettings[' . $name . ']" />' .
$accountsel -> selection ( 'newsettings[' . $name . ']' , 'deny_prefs' , $arguments [ 0 ][ $name ], 'groups' , 4 );
}
/**
* Check if current user has access to a specific feature
*
* Example : if ( ! mail_hooks :: access ( " managerfolders " )) return ;
*
* @ param string $feature " createaccounts " , " managefolders " , " forwards " , " notifications " , " filters " ,
* " notificationformailviaemail " , " editfilterrules " , " absentnotice " , " testconnection " , " aclmanagement "
* @ return boolean true if user has access , false if not
*/
public static function access ( $feature )
{
static $config = null ;
if ( ! isset ( $config )) $config = ( array ) config :: read ( 'mail' );
2014-02-07 09:33:23 +01:00
//error_log(__METHOD__.__LINE__.' '.$feature.':'.array2string($config['deny_'.$feature]));
2014-02-05 21:20:02 +01:00
if ( ! empty ( $config [ 'deny_' . $feature ]))
{
$denied_groups = explode ( ',' , $config [ 'deny_' . $feature ]);
return array_intersect ( $denied_groups , $GLOBALS [ 'egw' ] -> accounts -> memberships ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ], true ));
}
return true ;
}
2013-02-08 20:11:44 +01:00
}