* @copyright 2005-2006 The SquirrelMail Project Team, Alexandros Vellis * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id: annotate_tests.php,v 1.2 2006/11/01 11:56:45 avel Exp $ * @package plugins * @subpackage imapmetadata */ if (file_exists('../../include/init.php')) { include_once('../../include/init.php'); } else if (file_exists('../../include/validate.php')) { define('SM_PATH','../../'); require_once(SM_PATH . 'include/validate.php'); require_once(SM_PATH . 'functions/global.php'); } require_once(SM_PATH . 'functions/imap.php'); require_once(SM_PATH . 'plugins/imapmetadata/imap_annotate.php'); require_once(SM_PATH . 'functions/date.php'); require_once(SM_PATH . 'functions/mime.php'); require_once(SM_PATH . 'functions/mailbox_display.php'); require_once(SM_PATH . 'functions/html.php'); require_once(SM_PATH . 'functions/plugin.php'); /* lets get the global vars we may need */ sqgetGlobalVar('key', $key, SQ_COOKIE); sqgetGlobalVar('username', $username, SQ_SESSION); sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION); sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); sqgetGlobalVar('imapmetadatatest', $imapmetadatatest, SQ_GET); $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); // Sample ways to call sqimap_get_annotation(): // // $annotations = sqimap_get_annotation($imapConnection, '*', '/*', array('value')); // $annotations = sqimap_get_annotation($imapConnection, '*', '/*', array('value.shared')); // $annotations = sqimap_get_annotation($imapConnection, 'INBOX', '/comment', array('value.shared')); /* Presentation */ // displayPageHeader($color, 'None'); echo ' '; echo '

Annotation Tests

Show Annotations (Internal Flat Structure) | Show All Annotations (Internal Entry Tree Structure) | Show All Annotations (Flat Pretty Print) | Show All Annotations (Entry Tree Pretty Print) | Set an Annotation '; if(strstr($imapmetadatatest, 'tree')) { $tree = true; } else { $tree = false; } switch($imapmetadatatest) { case 'showall_internal': case 'showall_internal_tree': $annotations = sqimap_get_annotation($imapConnection, '*', '/*', '*', $tree); sm_print_r($annotations); break; case 'showall': case 'showall_tree': $annotations = sqimap_get_annotation($imapConnection, '*', '/*', '*', $tree); if(!$tree) { foreach($annotations as $mbox => $anns) { echo '

'.imap_utf7_decode_local($mbox).'

'; echo ''; foreach($anns as $entry => $attributes) { echo ''; foreach($attributes as $attr => $values) { echo ''; } } echo '
'.$entry.''.$attr.' is: '; foreach($values as $scope => $val) { echo ''.htmlspecialchars($val).' ('.$scope.') '; } echo '
 '; } } else { echo '

open all | close all

dtree is ©2002-2003 Geir Landrö

'; } break; case 'set': case 'delete': $boxes = sqimap_mailbox_list_all($imapConnection); $mailbox = "INBOX"; $entry = "/comment"; $attribute = "value"; $scope = 'priv'; $value = 'This is a test.'; sqgetGlobalVar('mailbox', $mailbox, SQ_POST); sqgetGlobalVar('entry', $entry, SQ_POST); sqgetGlobalVar('attribute', $attribute, SQ_POST); sqgetGlobalVar('scope', $scope, SQ_POST); sqgetGlobalVar('value', $value, SQ_POST); sqgetGlobalVar('addannotation', $addannotation, SQ_POST); sqgetGlobalVar('deleteannotation', $deleteannotation, SQ_POST); echo '
Mailbox: '.imapmetadata_mailboxlist('mailbox', $mailbox) .'
Entry:
Attribute:
Scope:
Value: (Not used when deleting)
'; if(isset($addannotation)) { if(sqimap_set_annotation($imapConnection, $mailbox, $entry, array($attribute.'.'.$scope => $value), $response, $message, true)) { echo '

SETANNOTATION succeeded with adding/replacing annotation! :-)

'; } else { echo '

SETANNOTATION failed! Could not add/replace annotation. :-(

'; } } elseif(isset($deleteannotation)) { if(sqimap_delete_annotation($imapConnection, $mailbox, $entry, array($attribute.'.'.$scope), $response, $message, true)) { echo '

SETANNOTATION succeeded with deleting annotation! :-)

'; } else { echo '

SETANNOTATION failed! Could not delete annoation! :-(

'; } } break; } function dtree_recursive_array($array, $parent=0){ $space=""; global $counter; if(!isset($counter)) { $counter = 1; } if(is_array($array)){ while (list ($x, $tmp) = each ($array)){ echo "d.add($counter, $parent, '".$x."', '', '', ''"; if($x == 'shared') { echo ",'img/globe.gif', 'img/globe.gif'"; } elseif($x == 'priv') { echo ",'img/imgfolder.gif', 'img/imgfolder.gif'"; } echo ");\n"; $counter++; echo dtree_recursive_array($tmp, $counter-1); } } else { echo "d.add($counter, $parent, '$array');\n"; $counter++; } } /** * Print mailbox select widget. * * @param string $selectname name for the select HTML variable * @param string $selectedmbox which mailbox to be selected in the form * @param boolean $sub * @return string */ function imapmetadata_mailboxlist($selectname, $selectedmbox, $sub = false) { global $boxes_append, $boxes_admin, $imap_server_type, $default_sub_of_inbox; if(isset($boxes_admin) && $sub) { $boxes = $boxes_admin; } elseif(isset($boxes_append)) { $boxes = $boxes_append; } else { global $boxes; } if (count($boxes)) { $mailboxlist = '