note 104946 added to function.imap-getmailboxes
| From: | jamesdotmattinglyatgmaildotcom at osu1 dot php dot net | Date: | Mon, 18 Jul 2011 07:19:09 +0000 |
| Subject: | note 104946 added to function.imap-getmailboxes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181633@lists.php.net to get a copy of this message | ||
For the purposes of passing along the attributes as a json array, I wanted to pass the attributes as
an indexed array to save on bandwidth and session storage. The human readable translation is then
performed in javascript by relating each key to the proper attribute label. I also wanted a cleaner
way of converting the attributes without calling another function or using a complex iteration. This
puts each binary attribute into it's own array element for easy testing.
<?php
$mailboxes = imap_getmailboxes($mailbox, $username, $password);
foreach($mailboxes as $key=>$mailbox){
...
$attrs =
preg_split('//',str_pad(decbin($mailbox->attributes),7,"0",STR_PAD_LEFT),8);
// convert decimal to an array of attributes
array_shift($attrs); // Remove the extra element at the front of the array in position 0
...
}
?>
With temporary variables, the conversion would look like this.
<?php
$attr_binary = decbin($mailbox->attributes); // convert decimal to binary
$attr_binary = str_pad($attr_binary,7,"0",STR_PAD_LEFT); // pad with 0's on the left
$attrs = $preg_split('//',$attr_binary,8); // split into an array after each character
array_shift($attrs); // Remove the extra element at the front of the array in position 0
?>
By defining the attributes as a map to the array index, you can test as follows.
<?php
define("ATTR_NOINFERIORS",6);
define("ATTR_NOSELECT "5);
define("ATTR_MARKED ",4);
define("ATTR_UNMARKED ",3);
define("ATTR_REFERRAL ",2);
define("ATTR_HASCHILDREN ",1);
define("ATTR_HASNOCHILDREN ",0);
if ($attrs[ATTR_HASCHILDREN]){
// do something
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 76.228.125.148
----
Manual Page -- http://www.php.net/manual/en/function.imap-getmailboxes.php
Edit -- https://master.php.net/note/edit/104946
Del: integrated -- https://master.php.net/note/delete/104946/integrated
Del: useless -- https://master.php.net/note/delete/104946/useless
Del: bad code -- https://master.php.net/note/delete/104946/bad+code
Del: spam -- https://master.php.net/note/delete/104946/spam
Del: non-english -- https://master.php.net/note/delete/104946/non-english
Del: in docs -- https://master.php.net/note/delete/104946/in+docs
Del: other reasons-- https://master.php.net/note/delete/104946
Reject -- https://master.php.net/note/reject/104946
Search -- https://master.php.net/manage/user-notes.php