- }
- }
- return "BUG! Couldn't get number of messages in $mailbox!";
- }
-
-
- /******************************************************************************
- ** Returns a displayable email address
- ******************************************************************************/
- function sqimap_find_email ($string) {
- /** Luke Ehresman <lehresma@css.tayloru.edu>
- ** <lehresma@css.tayloru.edu>
- ** lehresma@css.tayloru.edu
- **
- ** What about
- ** lehresma@css.tayloru.edu (Luke Ehresman)
- **/
-
- if (ereg("<([^>]+)>", $string, $regs)) {
- $string = $regs[1];
- }
- return trim($string);
- }
-
-
- /******************************************************************************
- ** Takes the From: field, and creates a displayable name.
- ** Luke Ehresman <lkehresman@yahoo.com>
- ** becomes: Luke Ehresman
- ** <lkehresman@yahoo.com>
- ** becomes: lkehresman@yahoo.com
- ******************************************************************************/
- function sqimap_find_displayable_name ($string) {
- $string = ' '.trim($string);
- $orig_string = $string;
- if (strpos($string, '<') && strpos($string, '>')) {
- if (strpos($string, '<') == 1) {
- $string = sqimap_find_email($string);
- } else {
- $string = trim($string);
- $string = substr($string, 0, strpos($string, '<'));
- $string = ereg_replace ('"', '', $string);
- }
-
- if (trim($string) == '') {
- $string = sqimap_find_email($orig_string);
- }
- }
- return $string;
- }
-
-
- /******************************************************************************
- ** Returns the number of unseen messages in this folder
- ******************************************************************************/
- function sqimap_unseen_messages ($imap_stream, $mailbox) {
- //fputs ($imap_stream, sqimap_session_id() . " SEARCH UNSEEN NOT DELETED\r\n");
- fputs ($imap_stream, sqimap_session_id() . " STATUS \"$mailbox\" (UNSEEN)\r\n");
- $read_ary = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $result, $message);
- ereg("UNSEEN ([0-9]+)", $read_ary[0], $regs);
- return $regs[1];
- }
-
-
- /******************************************************************************
- ** Saves a message to a given folder -- used for saving sent messages
- ******************************************************************************/
- function sqimap_append ($imap_stream, $sent_folder, $length) {
- fputs ($imap_stream, sqimap_session_id() . " APPEND \"$sent_folder\" (\\Seen) \{$length}\r\n");
- $tmp = fgets ($imap_stream, 1024);
- }
-
- function sqimap_append_done ($imap_stream) {
- fputs ($imap_stream, "\r\n");
- $tmp = fgets ($imap_stream, 1024);
- }
+ }
+ }
+ 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];
+}
+
+
+/*
+ * Saves a message to a given folder -- used for saving sent messages
+ */
+function sqimap_append ($imap_stream, $sent_folder, $length) {
+ fputs ($imap_stream, sqimap_session_id() . " APPEND \"$sent_folder\" (\\Seen) \{$length}\r\n");
+ $tmp = fgets ($imap_stream, 1024);
+}
+
+function sqimap_append_done ($imap_stream) {
+ fputs ($imap_stream, "\r\n");
+ $tmp = fgets ($imap_stream, 1024);
+}
+