📄 email.class.inc
字号:
{ $folder['id'] = $this->nextid("emFolders"); if ($folder['id'] > 0) { if ($this->insert_row('emFolders', $folder)) { return $folder['id']; } } return false; } function delete_folder($account_id, $name) { $sql = "DELETE FROM emFolders WHERE account_id='$account_id' ". "AND name='$name'"; $this->query($sql); $sql = "DELETE FROM emFilters WHERE account_id='$account_id' ". "AND folder='$name'"; $this->query($sql); } function folder_exists($account_id, $name) { $sql = "SELECT id FROM emFolders WHERE name='$name' AND "> "account_id='$account_id'"; $this->query($sql); if ($this->next_record()) { return $this->f("id"); }else { return false; } } function get_folder($account_id, $name) { $sql = "SELECT * FROM emFolders WHERE name='$name' AND ". "account_id='$account_id'"; $this->query($sql); if ($this->next_record(MYSQL_ASSOC)) { return $this->Record; }else { return false; } } function get_folder_by_id($folder_id) { $sql = "SELECT * FROM emFolders WHERE id=$folder_id"; $this->query($sql); if($this->next_record(MYSQL_ASSOC)) { return $this->Record; } return false; } function get_unseen_recursive($folder_id) { $email = new email(); $unseen = 0; if($folder = $email->get_folder_by_id($folder_id)) { //echo $folder['name'].'<br>'; $unseen += $folder['unseen']; $email->get_folders($folder['account_id'], $folder['id']); while($email->next_record()) { $unseen += $this->get_unseen_recursive($email->f('id')); } } return $unseen; } function get_account_unseen($account_id) { $unseen = 0; $this->get_subscribed($account_id); while($this->next_record()) { $unseen+=$this->f('unseen'); } return $unseen; } function subscribe($account_id, $name) { return $this->query("UPDATE emFolders SET subscribed='1' ". "WHERE account_id='$account_id' AND name='$name'"); } function unsubscribe($account_id, $name) { return $this->query("UPDATE emFolders SET subscribed='0' ". "WHERE account_id='$account_id' AND name='$name'"); } /* Gets the parent_id from a folder path */ function get_parent_id($account_id, $path, $delimiter) { if ($pos = strrpos($path, $delimiter)) { $parent_name = substr($path, 0, $pos); if ($parent_folder = $this->get_folder($account_id, $parent_name)) { return $parent_folder['id']; } }else { return 0; } return false; } function delete_folders($account_id) { $sql = "DELETE FROM emFolders WHERE account_id='$account_id'"; return $this->query($sql); } function cache_accounts($user_id, $auto_check_only=false) { if($this->get_accounts($user_id)) { $email = new email(); while($this->next_record()) { if(!$auto_check_only || $this->f('auto_check')=='1') { $email->cache_account_status($this->Record,$auto_check_only); } } } } function cache_account_status($account,$auto_check_only=false) { $mail = new imap(); $email = new email(); if (!$mail->open( $account['host'], $account['type'], $account['port'], $account['username'], $account['password'], 'INBOX', 0, $account['use_ssl'], $account['novalidate_cert'])) { return false; } if($auto_check_only) { $this->get_auto_check_folders($account['id']); }else { $this->get_subscribed($account['id']); } while($this->next_record()) { $folder['id'] = $this->f('id'); if($status = $mail->status($this->f('name'), SA_ALL)) { if($status->messages!=$this->f('msgcount') || $status->unseen!=$this->f('unseen')) { $folder['msgcount'] = $status->messages; $folder['unseen'] = $status->unseen; $email->__update_folder($folder); } } } $mail->close(); } function get_total_unseen($user_id) { $sql = "SELECT SUM(unseen) FROM emFolders INNER JOIN emAccounts ON emFolders.account_id=emAccounts.id WHERE user_id='$user_id' AND emAccounts.auto_check='1'"; $this->query($sql); $this->next_record(); return $this->f(0); } function synchronize_folders($account) { $mail = new imap(); if (!$mail->open( $account['host'], $account['type'], $account['port'], $account['username'], $account['password'], 'INBOX', 0, $account['use_ssl'], $account['novalidate_cert'])) { return false; } $subscribed = $mail->get_subscribed('', true); $mailboxes = $mail->get_mailboxes(''); $mailbox_names = array(); foreach($mailboxes as $mailbox) { $mailbox_names[] = $mailbox['name']; $folder['account_id'] = $account['id']; $folder['parent_id'] = $this->get_parent_id($account['id'], addslashes($mailbox['name']), $mailbox['delimiter']); $folder['attributes'] = $mailbox['attributes']; $folder['name'] = $mailbox['name']; $folder['subscribed']=in_array($mailbox['name'], $subscribed); //$folder['subscribed']='1'; $folder['delimiter'] = $mailbox['delimiter']; if($status = $mail->status($mailbox['name'], SA_ALL)) { $folder['msgcount'] = $status->messages; $folder['unseen'] = $status->unseen; } if($mailbox['name'] == 'INBOX') { $folder['sort_order'] = 0; }elseif($mailbox['name'] == $account['sent']) { $folder['sort_order'] = 1; }elseif($mailbox['name'] == $account['drafts']) { $folder['sort_order'] = 2; }elseif($mailbox['name'] == $account['trash']) { $folder['sort_order'] = 3; }elseif($mailbox['name'] == $account['spam']) { $folder['sort_order'] = 4; }else { $folder['sort_order'] = 10; } $folder = array_map('addslashes', $folder); if ($existing_folder = $this->get_folder($account['id'],addslashes($mailbox['name']))) { $folder['id'] = $existing_folder['id']; $this->__update_folder($folder); }else { $folder['id'] = $this->__add_folder($folder); } } //Courier doesn't return INBOX if(!in_array('INBOX', $mailbox_names)) { $mailbox_names[] = 'INBOX'; $folder['name']='INBOX'; $folder['account_id'] = $account['id']; $folder['sort_order']=0; $folder['subscribed']=true; $folder['delimiter'] = ''; if($status = $mail->status('INBOX', SA_ALL)) { $folder['msgcount'] = $status->messages; $folder['unseen'] = $status->unseen; } if ($existing_folder = $this->get_folder($account['id'],addslashes('INBOX'))) { $folder['id'] = $existing_folder['id']; $this->__update_folder($folder); }else { $folder['id'] = $this->__add_folder($folder); } } $mail->close(); /* get all the Group-Office folders and delete the folders that no longer exist on the IMAP server */ $this->get_folders($account['id']); $emailobj = new email(); while ($this->next_record()) { if (!in_array($this->f('name'), $mailbox_names)) { $emailobj->delete_folder($account['id'], addslashes($this->f('name'))); } } } function get_filters($account_id) { $sql = "SELECT * FROM emFilters WHERE account_id='$account_id' ". "ORDER BY priority DESC"; $this->query($sql); return $this->num_rows(); } function add_filter($account_id, $field, $keyword, $folder, $mark_as_read) { $next_id = $this->nextid("emFilters"); if ($next_id > 0) { $sql = "INSERT INTO emFilters (id, account_id, field, keyword, ". "folder, priority, mark_as_read) VALUES ('$next_id','$account_id','$field',". "'$keyword','$folder','$next_id', '$mark_as_read')"; return $this->query($sql); }else { return false; } } function get_filter($filter_id) { $sql = "SELECT * FROM emFilters WHERE id='$filter_id'"; $this->query($sql); if ($this->next_record()) { return $this->Record; }else { return false; } } function update_filter($filter_id, $field, $keyword, $folder, $mark_as_read) { $sql = "UPDATE emFilters SET field='$field', keyword='$keyword', folder='$folder', mark_as_read='$mark_as_read' WHERE id='$filter_id'"; $this->query($sql); } function delete_filter($id) { $sql = "DELETE FROM emFilters WHERE id='$id'"; $this->query($sql); } function move_up($move_up_id, $move_dn_id, $move_up_pr, $move_dn_pr) { if ($move_up_pr == $move_dn_pr) $move_up_pr++; $sql = "UPDATE emFilters SET priority='$move_up_pr' WHERE id='$move_up_id'"; $this->query($sql); $sql = "UPDATE emFilters SET priority='$move_dn_pr' WHERE id='$move_dn_id'"; $this->query($sql); } function register_attachment($tmp_file, $filename, $filesize, $filemime='', $disposition='attachment', $content_id='') { global $GO_CONFIG; $filename = smart_addslashes($filename); $tmp_file = smart_addslashes($tmp_file); $attachment['file_name'] = $filename; $attachment['tmp_file'] = $tmp_file; $attachment['file_size'] = $filesize; $attachment['file_mime'] = $filemime; $attachment['disposition'] = $disposition; $attachment['content_id'] = $content_id; $_SESSION['attach_array'][] = $attachment; } function get_zip_of_attachments($account_id, $uid, $mailbox='INBOX') { global $GO_CONFIG; $tmpdir = $GO_CONFIG->tmpdir.uniqid(time()); if(!mkdir($tmpdir)) { return false; } $account = $this->get_account($account_id); $imap = new imap(); if(!$imap->open($account['host'], $account['type'], $account['port'], $account['username'], $account['password'], $mailbox, 0, $account['use_ssl'], $account['novalidate_cert'])) { return false; } if(!$message = $imap->get_message($uid)) { return false; } for ($i = 0; $i < count($message['parts']); $i ++) { if ((eregi("ATTACHMENT", $message['parts'][$i]["disposition"]) || eregi("INLINE", $message['parts'][$i]["disposition"]) && !empty($message['parts'][$i]["name"])) || !empty($message['parts'][$i]["name"])){ $filename = $tmpdir.'/'.$message['parts'][$i]["name"]; $x=0; while(file_exists($filename)) { $x++; $filename .= strip_extension($filename).' ('.$x.').'.get_extension($filename); } if(!$fp = fopen($filename,'w+')) { return false; } if(!fwrite($fp, $imap->view_part($uid, $message['parts'][$i]["number"], $message['parts'][$i]["transfer"]))) { return false; } fclose($fp); } } chdir($tmpdir); exec($GO_CONFIG->cmd_zip.' -r "attachments.zip" *.*'); $data = file_get_contents( $tmpdir.'/attachments.zip'); exec('rm -Rf '.$tmpdir); return $data; } function get_default_account_id($user_id) { $sql = "SELECT id FROM emAccounts WHERE user_id='$user_id' AND standard=1"; $this->query($sql); if ($this->next_record()) { return $this->f("id"); } else { return false; } } function __on_user_delete($user_id) { $del = new email; $this->get_accounts($user_id); while ($this->next_record()) { $del->delete_account($user_id,$this->f("id")); } $this->query("DELETE FROM em_settings WHERE user_id='$user_id'"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -