- if (sqimap_capability($imap_stream, "NAMESPACE")) {
- /* According to something that I can't find, this is supposed to work on all systems
- OS: This won't work in Courier IMAP.
- OS: According to rfc2342 response from NAMESPACE command is:
- OS: * NAMESPACE (PERSONAL NAMESPACES) (OTHER_USERS NAMESPACE) (SHARED NAMESPACES)
- OS: We want to lookup all personal NAMESPACES...
- */
- fputs ($imap_stream, "a001 NAMESPACE\r\n");
- $read = sqimap_read_data($imap_stream, "a001", true, $a, $b);
- if (eregi('\* NAMESPACE +(\( *\(.+\) *\)|NIL) +(\( *\(.+\) *\)|NIL) +(\( *\(.+\) *\)|NIL)', $read[0], $data)) {
- if (eregi('^\( *\((.*)\) *\)', $data[1], $data2))
- $pn = $data2[1];
- $pna = explode(')(', $pn);
- while (list($k, $v) = each($pna))
- {
- list($_, $n, $_, $d) = explode('"', $v);
- $pn[$n] = $d;
- }
-/* OS: We don't need this code right now, it is for other_users and shared folders
- if (eregi('^\( *\((.*)\) *\)', $data[2], $data2))
- $on = $data2[1];
- if (eregi('^\( *\((.*)\) *\)', $data[3], $data2))
- $sn = $data2[1];
- unset($data);
- $ona = explode(')(', $on);
- while (list($k, $v) = each($ona))
- {
- list($_, $n, $_, $d) = explode('"', $v);
- $on[$n] = $d;
- }
- $sna = explode(')(', $sn);
- while (list($k, $v) = each($sna))
- {
- list($_, $n, $_, $d) = explode('"', $v);
- $sn[$n] = $d;
- }
-*/
- }
- $sqimap_delimiter = $pn[0];
- } else {
- fputs ($imap_stream, ". LIST \"INBOX\" \"\"\r\n");
- $read = sqimap_read_data($imap_stream, ".", true, $a, $b);
- $quote_position = strpos ($read[0], "\"");
- $sqimap_delimiter = substr ($read[0], $quote_position+1, 1);
- }
- }
- return $sqimap_delimiter;
+ if (sqimap_capability($imap_stream, 'NAMESPACE')) {
+ /*
+ * According to something that I can't find, this is supposed to work on all systems
+ * OS: This won't work in Courier IMAP.
+ * OS: According to rfc2342 response from NAMESPACE command is:
+ * OS: * NAMESPACE (PERSONAL NAMESPACES) (OTHER_USERS NAMESPACE) (SHARED NAMESPACES)
+ * OS: We want to lookup all personal NAMESPACES...
+ */
+ $read = sqimap_run_command($imap_stream, 'NAMESPACE', true, $a, $b);
+ if (eregi('\\* NAMESPACE +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL)', $read[0], $data)) {
+ if (eregi('^\\( *\\((.*)\\) *\\)', $data[1], $data2)) {
+ $pn = $data2[1];
+ }
+ $pna = explode(')(', $pn);
+ while (list($k, $v) = each($pna)) {
+ $lst = explode('"', $v);
+ if (isset($lst[3])) {
+ $pn[$lst[1]] = $lst[3];
+ } else {
+ $pn[$lst[1]] = '';
+ }
+ }
+ }
+ $sqimap_delimiter = $pn[0];
+ } else {
+ fputs ($imap_stream, ". LIST \"INBOX\" \"\"\r\n");
+ $read = sqimap_read_data($imap_stream, '.', true, $a, $b);
+ $quote_position = strpos ($read[0], '"');
+ $sqimap_delimiter = substr ($read[0], $quote_position+1, 1);
+ }
+ }
+ return $sqimap_delimiter;
+}
+
+
+/* Gets the number of messages in the current mailbox. */
+function sqimap_get_num_messages ($imap_stream, $mailbox) {
+ $read_ary = sqimap_run_command ($imap_stream, "EXAMINE \"$mailbox\"", true, $result, $message);
+ for ($i = 0; $i < count($read_ary); $i++) {
+ if (ereg("[^ ]+ +([^ ]+) +EXISTS", $read_ary[$i], $regs)) {
+ return $regs[1];
+ }
+ }
+ return "BUG! Couldn't get number of messages in $mailbox!";
+}
+
+
+/* Returns a displayable email address.
+ * Luke Ehresman <lehresma@css.tayloru.edu>
+ * "Luke Ehresman" <lehresma@css.tayloru.edu>
+ * <lehresma@css.tayloru.edu>
+ * lehresma@css.tayloru.edu (Luke Ehresman)
+ * lehresma@css.tayloru.edu
+ * becomes: lehresma@css.tayloru.edu
+ */
+function sqimap_find_email ($string) {
+ if (ereg("<([^>]+)>", $string, $regs)) {
+ $string = $regs[1];
+ } else if (ereg("([^ ]+@[^ ]+)", $string, $regs)) {
+ $string = $regs[1];
+ }
+ return trim($string);
+}
+
+
+/*
+ * Takes the From: field and creates a displayable name.
+ * Luke Ehresman <lkehresman@yahoo.com>
+ * "Luke Ehresman" <lkehresman@yahoo.com>
+ * lkehresman@yahoo.com (Luke Ehresman)
+ * becomes: Luke Ehresman
+ * <lkehresman@yahoo.com>
+ * becomes: lkehresman@yahoo.com
+ */
+function sqimap_find_displayable_name ($string) {
+ $string = trim($string);
+
+ if ( ereg('^(.+)<.*>', $string, $regs) ) {
+ $orig_string = $string;
+ $string = str_replace ('"', '', $regs[1] );
+ if (trim($string) == '') {
+ $string = sqimap_find_email($orig_string);
+ }
+ if( $string == '' || $string == ' ' ){
+ $string = ' ';
+ }
+ }
+ elseif ( ereg('\((.*)\)', $string, $regs) ) {
+ if( ( $regs[1] == '' ) || ( $regs[1] == ' ' ) ){
+ if ( ereg('^(.+) \(', $string, $regs) ) {
+ $string = ereg_replace( ' \(\)$', '', $string );
+ } else {
+ $string = ' ';
+ }
+ } else {
+ $string = $regs[1];
+ }
+ }
+ else {
+ $string = str_replace ('"', '', sqimap_find_email($string));
+ }
+
+ return trim($string);
+}
+
+/*
+ * Returns the number of unseen messages in this folder
+ */
+function sqimap_unseen_messages ($imap_stream, $mailbox) {
+ $read_ary = sqimap_run_command ($imap_stream, "STATUS \"$mailbox\" (UNSEEN)", true, $result, $message);
+ $i = 0;
+ while (isset($read_ary[$i])) {
+ if (ereg("UNSEEN ([0-9]+)", $read_ary[$i], $regs)) {
+ break;
+ }
+ $i++;
+ }
+ return $regs[1];