Example #1
0
function ajax_message_tags_save_tags($tag_str, $uid, $mailbox, $tools)
{
    $tags = hm_new('tags', $tools);
    $error = '';
    $new = array();
    $old = array();
    list($valid, $invalid) = $tags->sanitize_tag_string($tag_str);
    if (isset($tags->tag_map[$mailbox][$uid])) {
        foreach ($valid as $tag) {
            if (!in_array($tag, $tags->tag_map[$mailbox][$uid])) {
                $new[] = $tag;
            }
        }
    } else {
        $new = $valid;
    }
    if (isset($tags->tag_map[$mailbox][$uid])) {
        foreach ($tags->tag_map[$mailbox][$uid] as $v) {
            if (!in_array($v, $valid)) {
                $old[] = $v;
            }
        }
    }
    $tags->set_tags($mailbox, $new, $old, $uid);
    if (join(' ', $valid) != $tag_str) {
        $error = 'Invalid or duplicate tags not saved^^^' . join(' ', $valid);
    }
    return $error;
}
Example #2
0
function calendar_message_top($tools)
{
    return '';
    // short circuit during development
    require_once $tools->include_path . 'cal_include.php';
    if ($tools->get_current_message_type() == 'text/calendar' || $tools->get_current_message_type() == 'text/x-vCalendar') {
        $message = $tools->get_current_message();
        $vcal = hm_new('vcal');
        $vcal->import($message);
        $message = $vcal->display();
        $tools->set_current_message($message);
    }
}
Example #3
0
 function form_action_remove_contacts($form, $post)
 {
     global $user;
     global $include_path;
     global $fd;
     if ($user->logged_in) {
         require_once $include_path . 'lib' . $fd . 'vcard.php';
         $vcard = hm_new('vcard');
         $vcard->get_card_list();
         $diff = 0;
         if (isset($post['orig_name']) && in_array($post['orig_name'], $vcard->card_groups)) {
             $members = $this->get_group_contact_members($post, $vcard, $post['orig_name']);
             $orig_members = $vcard->get_group_members($post['orig_name']);
             if (isset($orig_members[$post['orig_name']])) {
                 $diff = count(array_keys($orig_members[$post['orig_name']])) - count($members);
             }
             $vcard->remove_group_members($post['orig_name']);
             $vcard->update_group_members($post['orig_name'], $members);
             $vcard->write_cards();
             if ($diff == 1) {
                 $this->errors[] = sprintf($user->str[517], $diff);
             } else {
                 $this->errors[] = sprintf($user->str[516], $diff);
             }
             $this->form_redirect = true;
         }
     }
 }
Example #4
0
 function form_action_compose_send($form, $post)
 {
     global $user;
     global $imap;
     global $conf;
     global $message;
     global $hastymail_version;
     global $smtp;
     global $include_path;
     global $fd;
     $path = $conf['attachments_path'];
     if ($user->logged_in) {
         if (isset($post['contacts_visible']) && $post['contacts_visible']) {
             $user->page_data['contact_browse'] = true;
         }
         require_once $include_path . 'lib' . $fd . 'smtp_class.php';
         $message = hm_new('mime', $post['compose_session']);
         if (!isset($_SESSION['user_settings']['compose_hide_mailer']) || !$_SESSION['user_settings']['compose_hide_mailer']) {
             $message->set_header('x_Mailer', $hastymail_version);
         }
         if (isset($post['compose_to'])) {
             $message->to = $post['compose_to'];
         }
         if (isset($post['compose_cc'])) {
             $message->cc = $post['compose_cc'];
         }
         if (isset($post['compose_bcc'])) {
             $message->bcc = $post['compose_bcc'];
         }
         if (isset($post['compose_references'])) {
             $message->references = $post['compose_references'];
         }
         if (isset($post['compose_in_reply_to'])) {
             $message->in_reply_to = $post['compose_in_reply_to'];
         }
         if (isset($post['message_id'])) {
             $message->message_id = $post['message_id'];
         }
         if (isset($post['compose_from'])) {
             if (isset($_SESSION['user_settings']['profiles'][$post['compose_from']])) {
                 $from_atts = $_SESSION['user_settings']['profiles'][$post['compose_from']];
                 $message->from = '"' . $from_atts['profile_name'] . '" <' . $from_atts['profile_address'] . '> ';
                 $message->from_address = $from_atts['profile_address'];
                 if (isset($from_atts['profile_reply_to']) && $from_atts['profile_reply_to']) {
                     $message->reply_to = '<' . $from_atts['profile_address'] . '>';
                 }
             }
         }
         if ($message->from_address) {
             $recipients = $message->get_recipient_addresses();
             if (!empty($recipients)) {
                 $message->subject = $post['compose_subject'];
                 $message->body = $post['compose_message'];
                 $priortiy = 0;
                 if (isset($post['compose_priority']) && $post['compose_priority']) {
                     $priortiy = (int) $post['compose_priority'];
                 }
                 if ($priortiy && $priortiy != 3) {
                     $message->set_header('x_Priority', $priortiy);
                 }
                 if (isset($post['compose_mdn']) && $post['compose_mdn']) {
                     $message->set_header('disposition_Notification_To', $message->from_address);
                 }
                 $smtp = hm_new('smtp');
                 $res = $smtp->connect();
                 if (!$res) {
                     do_work_hook('message_send', array($message->body));
                     $res = $smtp->send_message($message->from_address, $recipients, $message);
                     if ($res) {
                         if ($smtp->smtp_err) {
                             $res .= '<br />' . $smtp->smtp_err;
                         }
                         $this->form_vals = $post;
                         $this->errors[] = $res;
                     } else {
                         $user->page_data['sent'] = 1;
                         $this->errors[] = $user->str[355];
                         $this->form_redirect = true;
                         if (isset($post['compose_in_reply_to']) && $post['compose_in_reply_to']) {
                             $this->perform_imap_action('ANSWERED', $post['reply_box'], array($post['reply_uid']), false, false);
                         }
                     }
                     if (!$res && !isset($post['compose_skip_sent']) || isset($post['compose_skip_sent']) && !$post['compose_skip_sent']) {
                         $sent_folder = $_SESSION['user_settings']['sent_folder'];
                         if (isset($_SESSION['sent_folder_override']) && isset($_SESSION['folders'][$_SESSION['sent_folder_override']])) {
                             $sent_folder = $_SESSION['sent_folder_override'];
                             unset($_SESSION['sent_folder_override']);
                         }
                         if (isset($sent_folder) && isset($_SESSION['folders'][$sent_folder])) {
                             $status = stream_imap_append($message, $post['compose_session'], $sent_folder);
                             if (!$status) {
                                 $this->errors[] = $user->str[539];
                             }
                         }
                     }
                     if (!$res && isset($_SESSION['user_settings']['draft_folder']) && isset($post['message_id']) && $post['message_id'] && isset($_SESSION['user_settings']['delete_draft']) && $_SESSION['user_settings']['delete_draft'] && $_SESSION['user_settings']['draft_folder']) {
                         $trash_folder = false;
                         if (isset($_SESSION['user_settings']['trash_folder']) && $_SESSION['user_settings']['trash_folder']) {
                             $trash_folder = $_SESSION['user_settings']['trash_folder'];
                         }
                         $select_res = $imap->select_mailbox($_SESSION['user_settings']['draft_folder'], false, false, true);
                         if ($select_res) {
                             $search_res = $imap->simple_search('header message-id', false, $post['message_id']);
                             if (isset($search_res[0])) {
                                 $this->perform_imap_action('DELETE', $_SESSION['user_settings']['draft_folder'], array($search_res[0]), $trash_folder, false);
                             }
                         }
                     }
                     do_work_hook('compose_after_send');
                 } else {
                     $this->errors[] = $res;
                     $this->form_vals = $post;
                 }
                 if (!$res) {
                     unset_attachments($post['compose_session']);
                 }
                 $smtp->disconnect();
             } else {
                 $this->form_vals = $post;
                 $this->errors[] = $user->str[356];
             }
         } else {
             $this->form_vals = $post;
             $this->errors[] = $user->str[357];
         }
     }
 }
Example #5
0
 function url_action_contact_groups($get)
 {
     global $user;
     global $include_path;
     global $fd;
     if ($user->logged_in) {
         $user->dsp_page = 'contact_groups';
         require_once $include_path . 'lib' . $fd . 'vcard.php';
         $vcard = hm_new('vcard');
         $vcard->get_card_list();
         $user->page_data['contact_groups'] = $vcard->card_groups;
         $user->page_data['group_members'] = $vcard->get_group_members();
         $user->page_data['contacts'] = $vcard->card_list;
         if (isset($get['edit_group']) && in_array($get['edit_group'], $vcard->card_groups)) {
             $user->page_data['edit_group'] = $get['edit_group'];
         }
     }
 }
Example #6
0
function ajax_update_page($mailbox, $page_id, $title, $new = false, $folder_list = false, $mailbox_page = false, $sort_by = false, $filter_by = false, $show_all = false, $force = false)
{
    global $force_page_update;
    $res = array();
    if ($mailbox_page == -1) {
        $class_name = 'site_page_new';
    } else {
        $class_name = 'site_page_mailbox';
    }
    $pd = hm_new($class_name);
    $continue = true;
    $clock = false;
    $unread = false;
    $new_page = false;
    $tree = false;
    $dropdown = false;
    $mailbox_html = false;
    $mailbox_meta = false;
    if ($new) {
        $quick = true;
        list($mailbox_meta, $new_page) = refresh_new_page($page_id, $pd);
        if (!$new_page) {
            $continue = false;
        }
    } else {
        $quick = false;
    }
    if ($continue || $force) {
        list($dropdown, $clock, $unread) = update_dropdown($mailbox, $quick, $page_id, $pd);
        if (!$dropdown) {
            $continue = false;
        }
    }
    $title = update_title($title);
    if ($folder_list && ($force || $continue)) {
        $tree = update_folder_list($mailbox, $pd);
    }
    if (!$clock) {
        $clock = $pd->print_clock();
    }
    if ($mailbox_page != -1) {
        if (!$continue) {
            $period = $_SESSION['user_settings']['ajax_update_interval'];
            if (!isset($_SESSION['page_refresh_count'])) {
                $_SESSION['page_refresh_count'] = 1;
            } else {
                $_SESSION['page_refresh_count']++;
            }
            $count = $_SESSION['page_refresh_count'];
            if ($count * $period >= $force_page_update) {
                list($mailbox_meta, $mailbox_html) = update_mailbox_page($pd, $mailbox_page, $mailbox, $page_id, $sort_by, $filter_by, $show_all, $force);
                $_SESSION['page_refresh_count'] = 0;
            }
        }
        if ($continue || $force) {
            list($mailbox_meta, $mailbox_html) = update_mailbox_page($pd, $mailbox_page, $mailbox, $page_id, $sort_by, $filter_by, $show_all, $force);
            $_SESSION['page_refresh_count'] = 0;
        }
    }
    return implode('^^' . $page_id . '^^', array($new_page, $dropdown, $clock, $unread, $title, $tree, $mailbox_html, $mailbox_meta));
}
Example #7
0
function do_work_hook($location, $args = array(), $plugin_array = array())
{
    global $conf;
    global $tools;
    global $include_path;
    global $fd;
    if (empty($plugin_array) && isset($_SESSION['plugins'])) {
        $plugin_array = $_SESSION['plugins'];
    }
    if (isset($plugin_array['work_hooks'])) {
        $plugins = $plugin_array['work_hooks'];
        if (!empty($plugins)) {
            foreach ($plugins as $plugin => $vals) {
                foreach ($vals as $v) {
                    if ($location == $v) {
                        $function_name = $plugin . '_' . $location;
                        $file = 'plugins' . $fd . $plugin . $fd . 'work.php';
                        if (is_readable($file)) {
                            require_check($file);
                            require_once $include_path . $file;
                            if (function_exists($function_name)) {
                                if (!$tools || !isset($tools[$plugin])) {
                                    $tools[$plugin] = hm_new('plugin_tools', $plugin);
                                }
                                if (isset($tools[$plugin])) {
                                    $function_name($tools[$plugin], $args);
                                } else {
                                    error_log('HM2 Plugin Warning: ' . $plugin . ' unable to execute work hook: ' . $location);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Example #8
0
function print_tag_list($tools, $ajax = false)
{
    $res = '';
    if (!$ajax) {
        $res .= '<div id="folder_tag_list">';
    }
    $res .= '<div class="tag_title"><a href="?page=message_tags">' . $tools->str[0] . '</a></div>';
    $tags = hm_new('tags', $tools);
    foreach ($tags->tag_list as $tag => $folders) {
        $cnt = 0;
        foreach ($folders as $v) {
            $cnt += $v;
        }
        $res .= '<span class="tag_img"></span><a class="tag_link" href="?page=message_tags&amp;tag=' . urlencode($tag) . '">' . $tools->display_safe($tag) . ' (' . $cnt . ')</a><br />';
    }
    if (!$ajax) {
        $res .= '</div>';
    }
    return $res;
}
Example #9
0
function get_feed($tools, $url, $type, $limit, $feed_id, $ttl)
{
    if ($ttl > 0) {
        $cache = hm_new('cache');
        $cache->ttl = $ttl;
        $data = $cache->get_feed($feed_id);
        if ($data) {
            return $data;
        }
    }
    $feed = hm_new('feed');
    $feed->limit = $limit;
    $feed->feed_type = $type;
    $feed->parse_feed($url);
    $cache = hm_new('cache');
    $cache->save_feed($feed_id, $feed->parsed_data);
    return $feed->parsed_data;
}
Example #10
0
function message_tags_msglist_after_subject($tools, $msg_vals)
{
    global $page_id;
    if ($tools->get_setting('tags_disabled')) {
        return '';
    }
    $tags = hm_new('tags', $tools);
    $tag_list = array();
    $res = '';
    if (isset($tags->tag_map[$msg_vals['mailbox']][$msg_vals['uid']])) {
        $arg = join(' ', $tags->tag_map[$msg_vals['mailbox']][$msg_vals['uid']]);
        $label = $tools->display_safe($arg);
    } else {
        $arg = false;
        $label = '<span class="tag_image" title="' . $tools->str[1] . '"></span>';
    }
    $res = '</div><div style="float: right;"><complex-' . $page_id . '><div class="tag_cell"><a id="link_' . $msg_vals['uid'] . '" onclick="return edit_tags(\'' . $msg_vals['uid'] . '\', \'' . esc_sq($msg_vals['mailbox']) . '\');">' . $label . '</a></div></complex-' . $page_id . '>';
    return $res;
}
Example #11
0
 function get_contact_list($sort = 'sort_name', $page = 1, $source = 'local', $filter = false, $page_size = false, $filter_regex = false)
 {
     require_once 'vcard.php';
     $vcard = hm_new('vcard');
     return $vcard->get_quick_list($sort, $page, $source, $filter, $page_size, $filter_regex);
 }
Example #12
0
 function default_page_data()
 {
     global $imap;
     global $conf;
     global $user;
     global $tools;
     global $start_pages;
     global $hm_tags;
     if (!isset($user->dsp_page)) {
         $user->dsp_page = 'not_found';
         $user->page_data['top_link'] = '';
     }
     if (isset($_SESSION['last_message_read'])) {
         $user->page_data['last_message_read'] = $_SESSION['last_message_read'];
     } else {
         $user->page_data['last_message_read'] = array();
     }
     $user->page_data['site_title'] = $conf['page_title'];
     $user->page_data['sort_by'] = 'ARRIVAL';
     $user->page_data['top_link'] = '';
     $user->page_data['plugin_js'] = array();
     $user->page_data['inline_plugin_js'] = array();
     $user->page_data['plugin_style'] = array();
     $user->page_data['base_href'] = $conf['http_prefix'] . '://' . $conf['host_name'] . $conf['url_base'];
     $user->page_data['theme'] = 'default';
     $user->page_data['new_window'] = false;
     $user->page_data['new_window_arg'] = false;
     $user->page_data['parent_refresh'] = false;
     if ($user->logged_in) {
         if (isset($_SESSION['frozen_folders'])) {
             $user->page_data['frozen_folders'] = $_SESSION['frozen_folders'];
             if (isset($_GET['mailbox']) && isset($_SESSION['frozen_folders'][$_GET['mailbox']]) || isset($_POST['mailbox']) && isset($_SESSION['frozen_folders'][$_POST['mailbox']])) {
                 $imap->read_only = true;
             }
         } else {
             $user->page_data['frozen_folders'] = array();
         }
         $this->set_user_config();
         $imap->get_folders();
         if (!isset($_SESSION['user_settings']['profiles'])) {
             $user->page_data['settings']['profiles'] = array(array());
             $_SESSION['user_settings']['profiles'] = array(array());
         }
         $theme = 'default';
         if (isset($user->page_data['settings']['theme'])) {
             $user_theme = $user->page_data['settings']['theme'];
             if (isset($conf['site_themes'][$user_theme])) {
                 if ($conf['site_themes'][$user_theme]['css']) {
                     $theme = $user_theme;
                 }
             }
         }
         $user->page_data['theme'] = $theme;
         $user->page_data['new_link_class'] = '';
         $user->page_data['search_link_class'] = '';
         $user->page_data['options_link_class'] = '';
         $user->page_data['profile_link_class'] = '';
         $user->page_data['folder_link_class'] = '';
         $user->page_data['compose_link_class'] = '';
         $user->page_data['contacts_link_class'] = '';
         $user->page_data['folders'] =& $_SESSION['folders'];
         $user->page_data['mailbox'] = 'INBOX';
         $user->page_data['url_mailbox'] = 'INBOX';
         $user->page_data['simple_mode'] = false;
         if (isset($user->page_data['settings']['compose_window']) && $user->page_data['settings']['compose_window']) {
             $sid = '';
             if (!$user->use_cookies) {
                 $sid = '&amp;PHPSESSID=' . session_id();
             }
             $user->page_data['compose_onclick'] = 'open_window(\'?page=compose&amp;new_window=1' . $sid . '\', 900, 950); return false;';
         } else {
             $user->page_data['compose_onclick'] = false;
         }
         if (isset($_GET['parent_refresh'])) {
             $user->page_data['parent_refresh'] = true;
         }
         if (isset($_GET['new_window'])) {
             $user->page_data['new_window'] = true;
             $user->page_data['new_window_arg'] = '&amp;new_window=1';
         }
         if (isset($_SESSION['destination_folder'])) {
             $user->page_data['current_destination'] = $_SESSION['destination_folder'];
         } else {
             $user->page_data['current_destination'] = false;
         }
         $user->page_data['imap_capability'] = $_SESSION['imap_capability'];
         if (isset($_SESSION['plugin_list'])) {
             foreach ($_SESSION['plugin_list'] as $v) {
                 $tools[$v] = hm_new('plugin_tools', $v);
             }
         }
         do_work_hook('init');
         if (!isset($user->page_data['plugin_ajax'])) {
             $user->page_data['plugin_ajax'] = array();
         }
         if (!empty($user->page_data['plugin_ajax'])) {
             foreach ($user->page_data['plugin_ajax'] as $i => $v) {
                 $_SESSION['plugin_ajax'][$i] = $v;
             }
         }
         if (($user->user_agent_class == 'palm' || $user->user_agent_class == 'simple') && isset($_SESSION['user_settings']['auto_switch_simple_mode']) && $_SESSION['user_settings']['auto_switch_simple_mode']) {
             $user->page_data['simple_mode'] = true;
             $hm_tags['complex'] = true;
             $hm_tags['simple'] = false;
         } elseif (isset($_SESSION['user_settings']['display_mode']) && $_SESSION['user_settings']['display_mode'] != 1) {
             switch ($_SESSION['user_settings']['display_mode']) {
                 case 2:
                     $user->page_data['simple_mode'] = true;
                     $hm_tags['complex'] = true;
                     $hm_tags['simple'] = false;
                     break;
             }
         }
         if (isset($_GET['folder_state'])) {
             $f_id = (int) $_GET['folder_state'];
             if (strlen($f_id) > 1) {
                 $state = substr($f_id, -1);
                 $f_id = substr($f_id, 0, -1);
                 if (!$state) {
                     $state = true;
                 } else {
                     $state = false;
                 }
                 $_SESSION['folder_state'][$f_id] = $state;
             }
         }
         purge_old_attachments();
     } else {
         if (isset($conf['site_theme'])) {
             $theme = $conf['site_theme'];
             if (isset($conf['site_themes'][$theme])) {
                 $user->page_data['settings']['theme'] = $theme;
                 $user->page_data['theme'] = $theme;
             }
         }
         do_work_hook('logged_out_init', array(), get_plugins(true, true));
     }
     if (!$user->logged_in && ($user->user_agent_class == 'simple' || $user->user_agent_class == 'palm')) {
         $hm_tags['complex'] = true;
         $hm_tags['simple'] = false;
     }
     if ($user->just_logged_in && !isset($_SESSION['total_unread'])) {
         $_SESSION['total_unread'] = 0;
         if (isset($_SESSION['user_settings']['start_page']) && $_SESSION['user_settings']['start_page'] != 'mailbox' && $_SESSION['user_settings']['start_page'] != 'new' && isset($start_pages[$_SESSION['user_settings']['start_page']])) {
             if (isset($_SESSION['user_settings']['folder_check']) && is_array($_SESSION['user_settings']['folder_check'])) {
                 $imap->get_unseen_status($_SESSION['user_settings']['folder_check']);
             } else {
                 $_SESSION['total_unread'] = 0;
             }
         }
     }
 }
Example #13
0
 function url_action_message($get)
 {
     global $sort_types;
     global $client_sort_types;
     global $max_read_length;
     global $user;
     global $imap;
     global $include_path;
     global $message_part_types;
     global $override_missing_mime_header;
     global $add_contact_headers;
     global $conf;
     global $sort_filters;
     global $fd;
     global $sticky_url;
     $user->page_data['top_link'] = '<a href="' . $sticky_url . '#top">' . $user->str[186] . '</a>';
     if ($user->logged_in) {
         if (isset($_SESSION['iframe_content']) && $_SESSION['iframe_content'] && isset($get['inline_html']) && $get['inline_html']) {
             ob_clean();
             echo $_SESSION['iframe_content'];
             unset($_SESSION['iframe_content']);
             exit;
         }
         do_work_hook('message_page_start');
         $user->page_data['unseen_uids'] = 0;
         $user->page_data['show_previous_options'] = 0;
         $user->page_data['show_up_options'] = 0;
         $user->page_data['show_next_options'] = 0;
         $user->page_data['full_header'] = -1;
         $user->page_data['full_part_header'] = -1;
         $user->page_data['message_part_headers'] = array();
         $user->page_data['sort_filters'] = array('ALL' => 'All messages', 'UNSEEN' => 'Unread', 'SEEN' => 'Read', 'FLAGGED' => 'Flagged', 'UNFLAGGED' => 'Unflagged', 'ANSWERED' => 'Answered', 'UNANSWERED' => 'Unanswered', 'DELETED' => 'Deleted', 'UNDELETED' => 'Not Deleted');
         $user->page_data['message_link_class'] = 'current_page';
         $mailbox = false;
         if (isset($get['mailbox'])) {
             if (isset($_SESSION['folders'][$get['mailbox']])) {
                 $mailbox = $get['mailbox'];
             }
         }
         if (isset($get['full_part_header'])) {
             $user->page_data['full_part_header'] = intval($get['full_part_header']);
         }
         if (isset($get['full_header'])) {
             $user->page_data['full_header'] = intval($get['full_header']);
         }
         if (isset($get['find_response']) && isset($get['current_uid']) && isset($get['response_id'])) {
             $uid = false;
             if (isset($_SESSION['user_settings']['sent_folder'])) {
                 $select_res = $imap->select_mailbox($_SESSION['user_settings']['sent_folder'], false, false, true);
                 if ($select_res) {
                     $search_res = $imap->simple_search('header in-reply-to', false, $get['response_id']);
                     if (isset($search_res[0])) {
                         $get['uid'] = $search_res[0];
                         $uid = $get['uid'];
                         $mailbox = $_SESSION['user_settings']['sent_folder'];
                         $_GET['mailbox'] = $mailbox;
                         $this->errors[] = $user->str[388];
                     }
                 }
             }
             if (!$uid) {
                 $get['uid'] = $get['current_uid'];
                 $this->errors[] = $user->str[389];
             }
         }
         if ($mailbox && isset($get['uid'])) {
             if (isset($_SESSION['frozen_folders'][$mailbox])) {
                 $user->page_data['frozen_dsp'] = '<span id="frozen">(Mailbox Frozen)</span>';
             } else {
                 $user->page_data['frozen_dsp'] = '';
             }
             $id = (int) $get['uid'];
             if ($id) {
                 $sort_by = 'ARRIVAL';
                 if (isset($get['sort_by'])) {
                     if (stristr($_SESSION['imap_capability'], 'SORT')) {
                         $types = $sort_types;
                     } else {
                         $types = $client_sort_types;
                     }
                     if (isset($types[$get['sort_by']])) {
                         $sort_by = $get['sort_by'];
                     }
                 }
                 $filter_by = 'ALL';
                 if (isset($get['filter_by'])) {
                     if (isset($sort_filters[$get['filter_by']])) {
                         $filter_by = $get['filter_by'];
                     }
                 }
                 $user->page_data['filter_by'] = $filter_by;
                 $user->page_data['sort_by'] = $sort_by;
                 if ($imap->select_mailbox($mailbox, $sort_by, false, true, $filter_by)) {
                     do_work_hook('message_page_selected');
                     $user->page_data['mailbox'] = $mailbox;
                     if ($mailbox == 'INBOX') {
                         $user->page_data['mailbox_dsp'] = $user->str[436];
                     } else {
                         $user->page_data['mailbox_dsp'] = $user->htmlsafe($mailbox, 0, 0, 1);
                     }
                     $user->page_data['url_mailbox'] = urlencode($mailbox);
                     if ((!isset($get['show_all_mp']) || !$get['show_all_mp']) && isset($_SESSION['user_settings']['short_message_parts']) && $_SESSION['user_settings']['short_message_parts']) {
                         if (isset($_SESSION['user_settings']['html_first']) && $_SESSION['user_settings']['html_first']) {
                             $mfilter = 'html';
                         } else {
                             $mfilter = 'plain';
                         }
                     } else {
                         $mfilter = false;
                     }
                     if (!isset($get['show_all_mp']) || !$get['show_all_mp']) {
                         $user->page_data['show_all_mp'] = false;
                     } else {
                         $user->page_data['show_all_mp'] = true;
                     }
                     if ($mfilter) {
                         list($struct, $user->page_data['filtered_mp']) = $imap->get_message_structure($id, $mfilter);
                     } else {
                         $user->page_data['filtered_mp'] = 0;
                         $struct = $imap->get_message_structure($id);
                     }
                     $flat_list = $this->get_flat_part_list($struct);
                     $user->page_data['part_nav_list'] = $flat_list;
                     if (isset($get['message_part'])) {
                         $mpart = $get['message_part'];
                     } else {
                         $mpart = 0;
                     }
                     $sort_by = 'ARRIVAL';
                     if (!isset($get['show_image']) && !isset($get['download']) || isset($get['framed_part'])) {
                         $user->page_data['full_message_headers'] = $imap->get_message_headers($id, false);
                     }
                     if ($override_missing_mime_header) {
                         $struct = $this->override_missing_mime_header($struct, $user->page_data['full_message_headers']);
                     }
                     if (isset($_SESSION['user_settings']['html_first']) && $_SESSION['user_settings']['html_first']) {
                         list($message_data, $viewable) = $this->find_message_part($struct, $mpart, 'text', 'html');
                         if (empty($message_data) && !empty($viewable)) {
                             list($message_data, $viewable) = $this->find_message_part($struct, $viewable[0]);
                         }
                     } else {
                         list($message_data, $viewable) = $this->find_message_part($struct, $mpart, 'text', 'plain');
                         if (empty($message_data) && !empty($viewable)) {
                             list($message_data, $viewable) = $this->find_message_part($struct, $viewable[0]);
                         }
                     }
                     if (isset($get['raw_view']) && $get['raw_view']) {
                         $raw = 1;
                         $message_data['imap_id'] = 0;
                         $message_data['type'] = 'text';
                         $message_data['subtype'] = 'plain';
                     } else {
                         $raw = 0;
                     }
                     if (empty($message_data) && !empty($user->page_data['full_message_headers'])) {
                         $message_data['imap_id'] = 0;
                         $message_data['type'] = 'text';
                         $message_data['subtype'] = 'plain';
                         $user->page_data['broken_msg'] = true;
                     }
                     $user->page_data['raw_view'] = $raw;
                     $user->page_data['message_struct'] = $struct;
                     $user->page_data['message_uid'] = $id;
                     $user->page_data['message_part'] = $mpart;
                     $count = $_SESSION['uid_cache'][$mailbox]['total'];
                     $page = 1;
                     if (isset($get['mailbox_page'])) {
                         $page = (int) $get['mailbox_page'];
                         if (!$page) {
                             $page = 1;
                         }
                     }
                     $user->page_data['previous_uid'] = false;
                     $user->page_data['uid_index'] = false;
                     $user->page_data['next_uid'] = false;
                     for ($i = 0; $i < $count; $i++) {
                         if ($id == $_SESSION['uid_cache'][$mailbox]['uids'][$i]) {
                             $page = floor($i / $user->page_data['settings']['mailbox_per_page_count']) + 1;
                             $user->page_data['uid_index'] = $i;
                             if (isset($_SESSION['uid_cache'][$mailbox]['uids'][$i + 1])) {
                                 $user->page_data['next_uid'] = $_SESSION['uid_cache'][$mailbox]['uids'][$i + 1];
                                 $user->page_data['next_uid_page'] = floor(($i + 1) / $user->page_data['settings']['mailbox_per_page_count']) + 1;
                             }
                             if (isset($_SESSION['uid_cache'][$mailbox]['uids'][$i - 1])) {
                                 $user->page_data['previous_uid'] = $_SESSION['uid_cache'][$mailbox]['uids'][$i - 1];
                                 $user->page_data['prev_uid_page'] = floor(($i - 1) / $user->page_data['settings']['mailbox_per_page_count']) + 1;
                             }
                             break;
                         }
                     }
                     $user->page_data['show_small_headers'] = 0;
                     $user->page_data['show_full_headers'] = 0;
                     if (isset($get['full_headers']) && $get['full_headers']) {
                         $user->page_data['show_full_headers'] = 1;
                     } elseif (isset($get['small_headers']) && $get['small_headers']) {
                         $user->page_data['show_small_headers'] = 1;
                     }
                     if (!empty($message_data)) {
                         $user->page_data['message_part'] = $message_data['imap_id'];
                         $type = strtolower($message_data['type'] . '/' . $message_data['subtype']);
                         $user->page_data['charset'] = 'us-ascii';
                         if (isset($message_data['charset'])) {
                             $user->page_data['charset'] = strtolower($message_data['charset']);
                         }
                         $user->page_data['raw_message_type'] = $type;
                         if (isset($message_part_types[$type]) || isset($get['download'])) {
                             $user->page_data['message_type'] = false;
                             if (isset($message_part_types[$type])) {
                                 $user->page_data['message_type'] = $message_part_types[$type];
                             }
                             if (isset($get['show_image']) && strtolower($message_data['type'] == 'image')) {
                                 $data = $imap->get_message_part($id, $message_data['imap_id']);
                                 if (isset($message_data['encoding']) && strtolower($message_data['encoding']) == 'base64') {
                                     $data = base64_decode($data);
                                 } elseif (isset($message_data['encoding']) && strtolower($message_data['encoding']) == 'quoted-printable') {
                                     $data = quoted_printable_decode($data);
                                 }
                                 ob_end_clean();
                                 if ($data) {
                                     if (isset($get['thumbnail']) && $get['thumbnail'] && function_exists('imagecreatefromstring')) {
                                         $im = @imagecreatefromstring($data);
                                         $width = imagesx($im);
                                         $height = imagesy($im);
                                         $max_width = 80;
                                         $max_height = 60;
                                         if ($width > $max_width) {
                                             $new_width = $max_width;
                                             $new_height = $new_width * $height / $width;
                                             if ($new_height > $max_height) {
                                                 $new_height = $max_height;
                                                 $new_width = $new_height * $width / $height;
                                             }
                                         } elseif ($height > $max_height) {
                                             $new_height = $max_height;
                                             $new_width = $new_height * $width / $height;
                                         } else {
                                             $new_height = $height;
                                             $new_width = $width;
                                         }
                                         if (!$new_height || !$new_width) {
                                             $new_height = 50;
                                             $new_width = 50;
                                         }
                                         $im2 = @imagecreatetruecolor($new_width, $new_height);
                                         if ($im2 !== false && $im !== false) {
                                             imagecolortransparent($im2, imagecolorallocate($im2, 0, 0, 0));
                                             imagealphablending($im2, false);
                                             imagesavealpha($im2, true);
                                             imagecopyresampled($im2, $im, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                                             imagepng($im2);
                                         }
                                         $imap->disconnect();
                                         $user->clean_up();
                                         exit;
                                     }
                                     $size = (int) $message_data['size'];
                                     header("Content-Type: " . $type);
                                     header("Content-Length: " . strlen($data));
                                     echo $data;
                                     $imap->disconnect();
                                     $user->clean_up();
                                     exit;
                                 }
                             } elseif (isset($get['framed_part'])) {
                                 if (isset($message_data['filename']) && $message_data['filename']) {
                                     $name = $message_data['filename'];
                                 } elseif (isset($message_data['name']) && $message_data['name']) {
                                     $name = $message_data['name'];
                                 } else {
                                     $name = 'message_' . $message_data['imap_id'];
                                 }
                                 $exten = get_mimetype_extension($type);
                                 if (strtolower(substr($name, -4)) != $exten) {
                                     $name .= $exten;
                                 }
                                 $encoding = false;
                                 if (isset($message_data['encoding']) && strtolower($message_data['encoding']) == 'base64') {
                                     $encoding = 'base64_decode';
                                 } elseif (isset($message_data['encoding']) && strtolower($message_data['encoding'] == 'quoted-printable')) {
                                     $encoding = 'quoted_decode';
                                 }
                                 $left_over = '';
                                 $read_size = 0;
                                 $lit_size = $imap->get_message_part_start($id, $message_data['imap_id']);
                                 header("Content-Type: {$type}");
                                 header('Content-Transfer-Encoding: binary');
                                 header('Accept-Ranges: bytes');
                                 header("Pragma: public");
                                 header("Expires: 0");
                                 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                                 ob_end_clean();
                                 while ($data = $imap->get_message_part_line()) {
                                     $read_size += strlen($data);
                                     if ($read_size > $lit_size) {
                                         $extra = $read_size - $lit_size;
                                         if (strlen($data) > $extra) {
                                             $data = substr($data, 0, strlen($data) - $extra);
                                         } else {
                                             $data = false;
                                         }
                                     }
                                     if ($data && $encoding == 'base64_decode') {
                                         $data = base64_decode($data);
                                     } elseif ($data && $encoding == 'quoted_decode') {
                                         $data = $user->user_action->quoted_decode($data);
                                     }
                                     if ($data) {
                                         echo $data;
                                         flush();
                                     }
                                     $data = false;
                                 }
                                 $imap->disconnect();
                                 $user->clean_up();
                                 exit;
                             } elseif (isset($get['download'])) {
                                 if (isset($message_data['filename']) && $message_data['filename']) {
                                     $name = $message_data['filename'];
                                 } elseif (isset($message_data['name']) && $message_data['name']) {
                                     $name = $message_data['name'];
                                 } else {
                                     $name = 'message_' . $message_data['imap_id'];
                                 }
                                 $exten = get_mimetype_extension($type);
                                 if (strtolower(substr($name, -4)) != $exten) {
                                     $name .= $exten;
                                 }
                                 $encoding = false;
                                 if (isset($message_data['encoding']) && strtolower($message_data['encoding']) == 'base64') {
                                     $encoding = 'base64_decode';
                                 } elseif (isset($message_data['encoding']) && strtolower($message_data['encoding'] == 'quoted-printable')) {
                                     $encoding = 'quoted_decode';
                                 }
                                 $left_over = '';
                                 $read_size = 0;
                                 $lit_size = $imap->get_message_part_start($id, $message_data['imap_id']);
                                 header("Content-Type: text");
                                 //$type");
                                 header('Content-Transfer-Encoding: binary');
                                 header('Accept-Ranges: bytes');
                                 if (isset($message_data['att_size']) && intval($message_data['att_size']) > 0) {
                                     header('Content-Length: ' . $message_data['att_size']);
                                 } elseif (!$encoding && intval($lit_size) > 0) {
                                     header('Content-Length: ' . $lit_size);
                                 }
                                 header("Pragma: public");
                                 header("Expires: 0");
                                 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                                 header('Content-Disposition: attachment; filename="' . $name . '"');
                                 ob_end_clean();
                                 while ($data = $imap->get_message_part_line()) {
                                     $read_size += strlen($data);
                                     if ($read_size > $lit_size) {
                                         $extra = $read_size - $lit_size;
                                         if (strlen($data) > $extra) {
                                             $data = substr($data, 0, strlen($data) - $extra);
                                         } else {
                                             $data = false;
                                         }
                                     }
                                     if ($data && $encoding == 'base64_decode') {
                                         $data = base64_decode($data);
                                     } elseif ($data && $encoding == 'quoted_decode') {
                                         $data = $user->user_action->quoted_decode($data);
                                     }
                                     if ($data) {
                                         echo $data;
                                     }
                                     $data = false;
                                 }
                                 $imap->disconnect();
                                 $user->clean_up();
                                 ob_flush();
                                 flush();
                                 exit;
                             } else {
                                 /*if (isset($_SESSION['header_cache'][$mailbox][$page][$id]['flags'])) {
                                       if (!stristr($_SESSION['header_cache'][$mailbox][$page][$id]['flags'], 'seen')) {
                                           if (isset($_SESSION['folders'][$mailbox]['status']['unseen']) && $_SESSION['folders'][$mailbox]['status']['unseen'] > 0) {
                                               $_SESSION['folders'][$mailbox]['status']['unseen'] -= 1;
                                               $user->page_data['folders'] = $_SESSION['folders'];
                                           }
                                       }
                                       if (!stristr($_SESSION['header_cache'][$mailbox][$page][$id]['flags'], 'Seen')) {
                                           $_SESSION['header_cache'][$mailbox][$page][$id]['flags'] .= ' \Seen';
                                           if (isset($_SESSION['total_unread']) && $_SESSION['total_unread'] > 0 &&
                                               isset($_SESSION['user_settings']['folder_check']) && is_array($_SESSION['user_settings']['folder_check']) &&
                                               in_array($mailbox, $_SESSION['user_settings']['folder_check'])) {
                                               $_SESSION['total_unread']--;
                                           }
                                       }
                                   }*/
                                 if (!isset($user->page_data['full_message_headers'])) {
                                     $user->page_data['full_message_headers'] = $imap->get_message_headers($id, false);
                                 }
                                 $user->page_data['message_headers'] = $this->prep_headers($user->page_data['full_message_headers']);
                                 if (!$user->page_data['charset']) {
                                     foreach ($user->page_data['message_headers'] as $vals) {
                                         if (strtolower($vals[0]) == 'content-type') {
                                             if (preg_match("/charset=([^\\s;]+)/", $vals[1], $matches)) {
                                                 $user->page_data['charset'] = trim(str_replace(array("'", '"'), '', $matches[1]));
                                             }
                                             break;
                                         }
                                     }
                                 }
                                 if (count($user->page_data['part_nav_list']) > 1) {
                                     $parent_id = 0;
                                     foreach ($flat_list as $vals) {
                                         if ($vals[0] == $message_data['imap_id'] && $vals[1]) {
                                             $parent_id = $vals[1];
                                             break;
                                         }
                                     }
                                     if ($parent_id && $parent_id != 1) {
                                         $user->page_data['message_part_headers'] = $this->prep_headers($imap->get_message_headers($id, $parent_id));
                                     }
                                 }
                                 if ($raw) {
                                     $user->page_data['message_data'] = $imap->get_message_part($id, false, $raw, $max_read_length);
                                     if (isset($user->page_data['message_part_headers'])) {
                                         unset($user->page_data['message_part_headers']);
                                     }
                                     $user->page_data['part_nav_list'] = array();
                                 } elseif ($message_part_types[$type] == 'text' || $message_part_types[$type] == 'html') {
                                     $user->page_data['message_data'] = $imap->get_message_part($id, $message_data['imap_id'], $raw, $max_read_length);
                                     if ($imap->max_read) {
                                         $this->errors[] = $user->str[390];
                                         $imap->max_read = false;
                                     }
                                     if ($message_part_types[$type] == 'html') {
                                         if (isset($get['show_external_images'])) {
                                             if ($get['show_external_images']) {
                                                 $user->page_data['show_external_images'] = true;
                                             } else {
                                                 $user->page_data['show_external_images'] = false;
                                             }
                                         }
                                     }
                                     if (!$raw) {
                                         if (isset($message_data['encoding']) && strtolower($message_data['encoding']) == 'base64') {
                                             $user->page_data['message_data'] = base64_decode($user->page_data['message_data']);
                                         } elseif (isset($message_data['encoding']) && strtolower($message_data['encoding'] == 'quoted-printable')) {
                                             $user->page_data['message_data'] = $user->user_action->quoted_decode($user->page_data['message_data']);
                                         }
                                     }
                                     if (isset($conf['html_message_iframe']) && $conf['html_message_iframe'] && $message_part_types[$type] == 'html') {
                                         if ($user->sub_class_names['url']) {
                                             $class_name = 'site_page_' . $user->sub_class_names['url'];
                                             $pd = hm_new($class_name);
                                         } else {
                                             $pd = hm_new('site_page');
                                         }
                                         $_SESSION['iframe_content'] = $pd->print_message_iframe_content();
                                     }
                                     if (strstr($type, 'x-vcard')) {
                                         require_once $include_path . 'lib' . $fd . 'vcard.php';
                                         $vcard = hm_new('vcard');
                                         $vcard->import_card(explode("\r\n", $user->page_data['message_data']));
                                         if (is_array($vcard->card) && !empty($vcard->card)) {
                                             $user->page_data['card_detail'] = $vcard->card;
                                             $_SESSION['import_card_detail'] = $vcard->card;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if (!isset($user->page_data['full_message_headers'])) {
                         $user->page_data['full_message_headers'] = $imap->get_message_headers($id, false);
                     }
                     if (!isset($user->page_data['charset'])) {
                         $user->page_data['charset'] = false;
                         if (isset($user->page_data['message_headers'])) {
                             foreach ($user->page_data['message_headers'] as $vals) {
                                 if (strtolower($vals[0]) == 'content-type') {
                                     if (preg_match("/charset=([^ ]+)/", $vals[1], $matches)) {
                                         $user->page_data['charset'] = trim(str_replace(array("'", '"'), '', $matches[1]));
                                     }
                                     break;
                                 }
                             }
                         }
                     }
                     $user->page_data['mailbox_page'] = $page;
                     $user->page_data['mailbox_total'] = $_SESSION['uid_cache'][$mailbox]['total'];
                     $user->page_data['page_links'] = build_page_links($page, $_SESSION['uid_cache'][$mailbox]['total'], $user->page_data['settings']['mailbox_per_page_count'], '?page=mailbox&amp;sort_by=' . $sort_by . '&amp;filter_by=' . $filter_by . '&amp;mailbox=' . urlencode($mailbox), $user->str[88]);
                     $user->dsp_page = 'message';
                     $_SESSION['last_message_read'][$mailbox] = $id;
                     if (isset($get['print_view']) && $get['print_view']) {
                         ob_clean();
                         if ($user->sub_class_names['url']) {
                             $class_name = 'site_page_' . $user->sub_class_names['url'];
                             $pd = hm_new($class_name);
                         } else {
                             $pd = hm_new('site_page');
                         }
                         echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                           <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
                             <head><title>Message Print View</title><base href="' . $pd->pd['base_href'] . '" /><title id="title">' . $pd->user->page_title . '</title>
                             <style type="text/css">table {padding:10px;margin-left:-10px;padding-bottom:20px;}
                             b{font-weight: normal;} table td {padding-left:10px;} table th {text-align:left;font-weight:normal;}
                             pre {white-space: pre-wrap; white-space: -moz-pre-wrap !important; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;}
                             </style></head>
                         <body style="background: none; background-image: none; background-color: #fff; color: #000; margin: 30px;">' . '<table>' . $pd->print_message_headers() . '</table>';
                         if (isset($pd->pd['message_part_headers'])) {
                             '<table>' . $pd->print_part_headers() . '</table>';
                         }
                         //$pd->pd['raw_view'] = true;
                         switch ($user->page_data['message_type']) {
                             case 'text':
                             case 'image':
                             case 'html':
                                 echo $pd->{'print_message_' . $user->page_data['message_type']}();
                                 break;
                             default:
                                 echo '<div style="text-align: center; margin-top: 100px;">Unsupported MIME type: ' . $user->htmlsafe($user->page_data['raw_message_type']) . '</div>';
                                 break;
                         }
                         echo '
                     </body>
                     </html>';
                         exit;
                     }
                     if (isset($get['show_up_options'])) {
                         $user->page_data['show_up_options'] = 1;
                     }
                     if (isset($get['show_next_options'])) {
                         $user->page_data['show_next_options'] = 1;
                     }
                     if (isset($get['show_previous_options'])) {
                         $user->page_data['show_previous_options'] = 1;
                     }
                     $new_contacts = array();
                     if (isset($user->page_data['full_message_headers'])) {
                         foreach ($user->page_data['full_message_headers'] as $vals) {
                             $i = $vals[0];
                             $v = $vals[1];
                             if (!in_array(strtolower($i), $add_contact_headers)) {
                                 continue;
                             }
                             if (strstr($v, ' ')) {
                                 $bits = explode(' ', trim($v));
                             } elseif (strstr($v, ',')) {
                                 $bits = explode(',', trim($v));
                             } else {
                                 $bits = array($v);
                             }
                             foreach ($bits as $val) {
                                 $val = rtrim(ltrim($val, '<,'), '>,');
                                 if ($this->match_email($val)) {
                                     $new_contacts[] = $val;
                                 }
                             }
                         }
                     }
                     $user->page_data['new_contacts'] = $new_contacts;
                     list($total_unread, $user->page_data['unseen_uids']) = $imap->get_mailbox_unseen($mailbox);
                     if ($total_unread) {
                         $user->page_data['unseen_uids'][] = $user->page_data['message_uid'];
                         $user->page_data['unseen_uids'] = $this->sort_uid_list($user->page_data['unseen_uids'], $mailbox);
                     }
                     if (isset($_SESSION['search_results'][$mailbox])) {
                         $user->page_data['search_results'] = $this->sort_uid_list($_SESSION['search_results'][$mailbox], $mailbox);
                     }
                     if (isset($_SESSION['uid_cache'][$mailbox]['thread_data'])) {
                         $user->page_data['thread_data'] = $_SESSION['uid_cache'][$mailbox]['thread_data'];
                     }
                     $user->page_data['folders'] = $_SESSION['folders'];
                     $user->page_title .= ' | Message |';
                 }
             }
         }
     }
 }
Example #14
0
function pop3_session($tools, $user, $pass, $port, $host, $ssl, $starttls, $keep, $destination, $acct_id, $uid_map)
{
    $pop3 = hm_new('pop3');
    $pop3->server = $host;
    $pop3->port = $port;
    $pop3->starttls = $starttls;
    $pop3->ssl = $ssl;
    $msg_count = 0;
    $read_size = 0;
    $seen = false;
    $msg_list = array();
    if ($pop3->connect()) {
        if ($pop3->auth($user, $pass)) {
            $msg_list = $pop3->mlist();
            $uid_list = $pop3->uidl();
            foreach ($msg_list as $id => $size) {
                $headers = true;
                if ($keep) {
                    if (isset($uid_map[$acct_id][$uid_list[$id]])) {
                        continue;
                    }
                    $uid_map[$acct_id][$uid_list[$id]] = false;
                }
                $msg_count++;
                if ($pop3->retr_start($id)) {
                    if ($tools->imap_append_start($destination, $size, false)) {
                        $continue = true;
                        while ($continue) {
                            list($line, $continue) = $pop3->retr_feed();
                            $read_size += strlen($line);
                            if ($keep && $headers) {
                                $dt = date_check($line);
                                if ($dt) {
                                    $uid_map[$acct_id][$uid_list[$id]] = $dt;
                                }
                            }
                            if (!trim($line)) {
                                $headers = false;
                            }
                            if ($continue && strlen($line)) {
                                $tools->imap_append_feed($line, true);
                            } else {
                                $tools->imap_append_feed("\r\n", true);
                                $tools->imap_append_end();
                                break;
                            }
                        }
                    }
                }
                if (!$keep) {
                    $pop3->dele($id);
                }
            }
            if ($keep) {
                $new_uid_map = array();
                foreach ($msg_list as $id => $size) {
                    if (isset($uid_map[$acct_id][$uid_list[$id]])) {
                        $new_uid_map[$uid_list[$id]] = $uid_map[$acct_id][$uid_list[$id]];
                    } else {
                        $new_uid_map[$uid_list[$id]] = false;
                    }
                }
                $uid_map[$acct_id] = $new_uid_map;
            }
            $pop3->quit();
        }
    }
    return array($msg_count, $uid_map);
}
Example #15
0
function url_action_message_tags($tools, $get, $post)
{
    if (!$tools->logged_in() || $tools->get_setting('tags_disabled')) {
        $tools->page_not_found();
        return;
    }
    $tools->add_style('<link rel="stylesheet" type="text/css" href="?page=mailbox&amp;theme=' . $tools->get_theme() . '&amp;css=1" />');
    $tools->add_inline_js('
        function clear_rename_tag(tag) {
            document.getElementById("rename_"+tag).innerHTML = "";
            return false;
        }
        function submit_tag_rename(tag) {
            if( window.event ) {
                e = window.event;
            }
            if( typeof( e.keyCode ) == "number"  ) {
                e = e.keyCode;
            } else if( typeof( e.which ) == "number" ) {
                e = e.which;
            } else if( typeof( e.charCode ) == "number"  ) {
                e = e.charCode;
            }
            if (e == 13) {
                var new_tag = document.getElementById("rename_fld").value;
                if (new_tag != tag) {
                    document.getElementById("dest_name").value = new_tag;
                    document.getElementById("src_name").value = tag;
                    document.forms["rename_form"].submit();
                }
                else {
                    clear_rename_tag(tag);
                }
            }
            return false;
        }
        function rename_tag(tag) {
            document.getElementById("rename_"+tag).innerHTML = \'<input onkeyup="return submit_tag_rename(\\\'\'+tag+\'\\\')" onblur="return clear_rename_tag(\\\'\'+tag+\'\\\')" type="text" id="rename_fld" value="\'+tag+\'" />\';
            document.getElementById("rename_fld").select();
            return false;
        }
        function repair_tags(tag) {
            if (confirm("Attempting to correct tag data could result in some tags being lost. Continue?")) {
                document.getElementById("del_tag").value = "^repair^";
                document.forms["del_form"].submit();
            }
            return false;
        }
        function delete_all_tags(tag) {
            if (confirm("Are you sure you want to delete ALL your tags?")) {
                document.getElementById("del_tag").value = "^all^";
                document.forms["del_form"].submit();
            }
            return false;
        }
        function delete_tag(tag) {
            if (confirm("Are you sure you want to delete the \\""+tag+"\\" tag?")) {
                document.getElementById("del_tag").value = tag;
                document.forms["del_form"].submit();
            }
            return false;
        }
        function remove_tag(tag) {
            var url = document.location.href;
            var pattern = new RegExp(/tag\\=(.+)/);
            var mymatch = pattern.exec(url);
            if (mymatch.length > 1) {
                var tags = mymatch[1].replace("%2B"+tag, "").replace("/%5E"+tag, "").replace(tag, "");
                tags = tags.replace(/^(%2B|%5E)/, "");
                if (tags) {
                    document.location.href = "?page=message_tags&tag="+tags;
                }
                else {
                    document.location.href = "?page=message_tags";
                }
            }
            return false;
        }
        function add_tag_start() {
            var tag_type = document.getElementById("add_type");
            if (tag_type) {
                if (tag_type.options[tag_type.selectedIndex].value == "or") {
                    return add_tag_or();
                }
            }
            return add_tag_and();
        }
        function add_tag_or() {
            var new_tag = get_tag();
            if (new_tag) {
                document.location.href = document.location.href+urlencode("^"+new_tag);
            }
            return false;
        }
        function add_tag_and() {
            var new_tag = get_tag();
            if (new_tag) {
                document.location.href = document.location.href+urlencode("+"+new_tag);
            }
            return false;
        }
        function reset_tag_list() {
            document.location.href = "?page=message_tags";
        }
        function get_tag() {
            var new_tag;
            var tag_list = document.getElementById("tag_list");
            if (tag_list) {
                new_tag = tag_list.options[tag_list.selectedIndex].value;
            }
            return new_tag;
        }
    ');
    $tags = hm_new('tags', $tools);
    $tools->set_title('Message Tags');
    $pd = array();
    $pd['tag'] = false;
    $pd['header_data'] = array();
    $pd['tag_list'] = $tags->tag_list;
    if (!$tools->logged_in()) {
        $tools->page_not_found();
    } else {
        if (isset($_POST['del_tag']) && isset($tags->tag_list[$_POST['del_tag']])) {
            $tools->send_notice($tags->delete_tag($_POST['del_tag']));
            $pd['tag_list'] = $tags->tag_list;
        } elseif (isset($_POST['del_tag']) && $_POST['del_tag'] == '^repair^') {
            $tags->repair();
            $pd['tag_list'] = $tags->tag_list;
            $tools->send_notice('Tag information repaired');
        } elseif (isset($_POST['del_tag']) && $_POST['del_tag'] == '^all^') {
            $tags->reset();
            $pd['tag_list'] = array();
            $tools->send_notice('All Tags Deleted');
        } elseif (isset($_POST['src_name']) && isset($_POST['dest_name'])) {
            if (isset($tags->tag_list[$_POST['src_name']])) {
                if ($tags->valid_tag($_POST['dest_name'])) {
                    $tools->send_notice($tags->rename_tag($_POST['src_name'], $_POST['dest_name']));
                    $pd['tag_list'] = $tags->tag_list;
                } else {
                    $tools->send_notice('Invalid tag name');
                }
            }
        }
        $tag_list = array();
        $tag = false;
        $_SESSION['tag_page_list'] = array();
        if (isset($_GET['tag'])) {
            if (isset($tags->tag_list[$_GET['tag']])) {
                $tag_list[0] = array($_GET['tag']);
                $tag = true;
            } elseif (strpos($_GET['tag'], '^') !== false || strpos($_GET['tag'], '+') !== false) {
                $group_id = 0;
                $bits = preg_split("/(\\^|\\+)/", $_GET['tag'], -1, PREG_SPLIT_DELIM_CAPTURE);
                $bucket = false;
                foreach ($bits as $i => $v) {
                    if (!$bucket && isset($tags->tag_list[$v])) {
                        $tag_list[$group_id][] = $v;
                        $tag = true;
                    } elseif ($bucket == 'and' && isset($tags->tag_list[$v])) {
                        $tag_list[$group_id][] = $v;
                        $tag = true;
                    } elseif ($bucket == 'or' && isset($tags->tag_list[$v])) {
                        $group_id++;
                        $tag_list[$group_id][] = $v;
                        $tag = true;
                    }
                    if ($v == '^') {
                        $bucket = 'or';
                    } elseif ($v == '+') {
                        $bucket = 'and';
                    }
                }
            }
        }
        if ($tag) {
            $_SESSION['tag_page_list'] = $tag_list;
            $pd['tag'] = true;
            $res = get_tag_msg_list($tag_list, $tools, $tags);
            if (isset($res['header_data'])) {
                $pd['header_data'] = $res['header_data'];
            }
            $pd['tag_dsp'] = $res['tag_dsp'];
            $pd['tags'] = $res['tags'];
            usort($pd['header_data'], 'sort_date');
        }
    }
    return $pd;
}
Example #16
0
   for this request is complete. */
if ($imap->connected) {
    $imap->disconnect();
}
/* Do a handy work hook. This is a good way for plugins to get access to the completed
   data for a page request before the XHTML is built. */
do_work_hook('page_end');
/* Build the XHTML and sent it to the browser 
----------------------------------------------------------------*/
/* Setup template data. The code is broken out into multiple includes to keep
   the application memory footprint smaller. */
if ($user->sub_class_names['url']) {
    $class_name = 'site_page_' . $user->sub_class_names['url'];
    $pd = hm_new($class_name);
} else {
    $pd = hm_new('site_page');
}
/* Build the page XHTML. The resulting page is constructed but not sent to the browser yet */
build_page($pd);
/* Filter the output XHTML for the current display mode, and send it to the browser */
output_filtered_content($hm_tags);
/* IMAP debug. Outputs debug information below the page if the show_imap_debug setting
   is enabled in the hastymail2.conf file. */
if (isset($conf['show_imap_debug']) && $conf['show_imap_debug']) {
    if (isset($conf['show_full_debug']) && $conf['show_full_debug']) {
        $imap->puke(true);
    } else {
        $imap->puke();
    }
}
/* SMTP debug. Outputs debug information about any SMTP operations performed */