- /******************************************************************************
- ** 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);
+/*
+ * 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);
+}
+
+function sqimap_get_user_server ($imap_server, $username) {
+
+ if (substr($imap_server, 0, 4) != "map:") {
+ return $imap_server;