Focus on the one_mail function. Use the Mail_mimeDecode class to extract the mail header and body from the mail. the specific implementation of this class focuses on the one_mail function. Use the Mail_mimeDecode class to extract the mail header and body from the mail.
The code is as follows:
Header ("content-type: text/html; charset = UTF-8 ");
/*
* Record kid words and insert into database
* User by sending email to publication kid words
*
*/
Include 'pop3. php ';
Include 'email _ class. php ';
Include 'mail _ mimeDecode. php ';
// Include 'include/compatible. php ';
Include 'include/extend_common.php ';
// Include '../htdocs/include/extend_common.php ';
Define ('post _ FROM_EMAIL ', 1 );
Define ('database _ CONNECTION_ERROR ', 2); // DATABASE connection failure error
Define ('email _ CONNECTION_ERROR ', 3); // EMAIL connection failure error
Define ('account _ error', 4); // the email ACCOUNT is incorrect.
Define ('sign _ EMAIL_ERROR ', 5); // mail Mark deletion error
Define ('delelet _ error', 6); // mail deletion ERROR
Define ('Insert _ error', 7); // data insertion failure ERROR
Class mail_data {
Function mail_data (){
Include 'config. php ';
$ Mail_log = fopen ("mail_log.txt", "a + ");
$ Conn = @ mysql_connect ($ db_host, $ db_user, $ db_password );
If ($ conn ){
Mysql_select_db ('t', $ conn );
Mysql_query ("set names utf8 ");
$ Pop3 = new Net_POP3 ();
// Determine whether the connection is successful
If ($ pop3-> connect ($ host, 110 )){
// Determine whether the logon is successful
If ($ pop3-> login ($ user, $ password) === true ){
$ List = $ pop3-> _ cmdList ();
$ Sum = $ pop3-> _ 1_stat ();
// How many emails are Retrieved each time
$ Step = 2;
$ R = 0;
// Get the $ step email from the mailbox first
For ($ n = 0; $ n <$ sum [0]; $ n + = $ step ){
$ T = 0;
$ Users = array ();
$ Mail = array ();
$ Offset = ($ sum [0]-$ n) <$ step? $ Sum [0]-$ n: $ step;
// Email loop
For ($ I = $ r; $ I <$ n + $ offset; $ I ++ ){
// Obtain the email information
$ User = $ this-> one_mail ($ I, $ pop3, $ list, $ mail_log );
Array_push ($ mail, $ user ['from _ mail']);
Array_push ($ users, $ user );
$ R = $ I + 1;
}
// Obtain mail user data
$ Str = $ this-> uesr_data ($ mail );
$ Value = array ();
// The current mail array loop, email of the current mail user, child name, and Tongyan
For ($ m = 0; $ m <count ($ users); $ m ++ ){
$ Num = 0;
$ Mn = $ m + $ n;
// Data processing
$ Post_text = $ users [$ m] ['conntent'];
If (! Empty ($ post_text )){
$ Post_text = do_submit_text ($ post_text );
$ Post_text = mysql_real_escape_string ($ post_text );
$ Post_link_num = parsed_text_include_links ($ post_text );
$ Text = do_submit_text ($ post_text );
$ Post_text_undo = mysql_real_escape_string ($ text );
$ Post_text = mysql_real_escape_string ($ post_text );
$ Val = array ();
$ Kid_num = $ users [$ m] ['Kid _ nickname'];
If (is_numeric ($ kid_num) & intval ($ kid_num) <= 3 & intval ($ kid_num)> 0 ){
$ Kid_num = intval ($ kid_num );
$ Val = $ this-> kid_data ($ users, $ m, $ kid_num, $ post_text, $ post_link_num, $ post_text_undo );
If (isset ($ val )){
$ Value ["$ t"] = $ val;
$ Num = 1;
$ T = $ t + 1;
}
} Else {
// Data in the database
For ($ x = 0; $ x <count ($ str); $ x ++ ){
// Determine if it is a child of from_mail
$ Val ["$ x"] = $ this-> is_kid ($ users, $ str, $ m, $ x, $ post_text, $ post_link_num, $ post_text_undo );
If (isset ($ val ["$ x"]) {
$ Value ["$ t"] = $ val ["$ x"];
$ Num = 1;
$ T = $ t + 1;
}
}
}
// Determine whether the data in the database is matched successfully
If ($ num = 0 ){
$ Val = $ this-> kid_data ($ users, $ m, 1, $ post_text, $ post_link_num, $ post_text_undo );
If (isset ($ val )){
$ Value ["$ t"] = $ val;
$ Num = 1;
$ T = $ t + 1;
}
}
}
}
// Perform operations on a piece of data
$ Valu = implode ("), (", $ value );
If ($ valu! = ""){
$ Err_time = $ this-> insert_date ($ valu );
$ This-> kid_message_count ($ value );
}
}
Fclose ($ mail_log );
/*
If ($ pop3-> disconnect () = false ){
$ This-> _ error (DELELET_ERROR );
}
*/
} Else {
Echo "incorrect account or password! ";
$ This-> _ error (ACCOUNT_ERROR );
}
} Else {
Echo "connection failed ...";
$ This-> _ error (EMAIL_CONNECTION_ERROR );
$ Title = $ mail_title [0]-> text;
$ T = $ mail_title [0]-> charset;
If ($ t! = "Default "){
$ Title = iconv ($ t, "UTF-8", $ title );
} Else {
$ Title = iconv ("gb2312", "UTF-8", $ title );
}
} Else {
$ Title = 1;
}
// $ Pop3-> _ includele ($ list [$ I] ['MSG _ id']);
$ Pop3-> deleteMsg ($ list [$ I] ['MSG _ id']);
If ($ pop3-> deleteMsg ($ list [$ I] ['MSG _ id']) = false ){
$ This-> _ error (SIGN_EMAIL_ERROR );
}
// Obtain the user email to be inserted, the child name, and the boy's words.
$ Users ["$ I"] = array (
"From_mail" => "$ from_mail [0]",
"Kid_nickname" => "$ title ",
"Conntent" => "$ text ",
"Body_type" => "$ mail_type"
);
$ Log = $ users ["$ I"];
Array_unshift ($ log, date ("Y-m-d H: I; s "));
$ Log = serialize ($ log );
Fwrite ($ mail_log, $ log. "/r/n ");
Return $ users ["$ I"];
}
/**
* At database search $ mail user's information
* @ Access public
* @ Param string $ mail all email
* @ Return array mail user's information
*/
Function uesr_data ($ mail ){
$ Mails = implode ("','", $ mail );
$ SQL = "SELECT a. mail, a. user_name, a. user_nickname, B. kid_id, B. kid_name, B. kid_avatar, B. kid_birthday
FROM't _ users 'a,'t _ users_kid 'B
WHERE a. mail in ('$ mails') AND a. user_id = B. user_id ";
$ Query = mysql_query ($ SQL) or die (mysql_error ());
$ Str1 = array ();
While ($ arr = mysql_fetch_array ($ query )){
Array_push ($ str1, $ arr );
}
Return $ str1;
}
/*
* Insert $ value into database
* @ Access public
* @ Param string $ value kid information
* @ Return void
*/
Function insert_date ($ value ){
$ SQL _insert = "INSERT INTO't _ posts '(kid_id, user_name, user_nickname, post_time, post_text, user_avatar, post_link_num, post_text_undo, post_from, add_time)
VALUES ($ value )";
$ Num = mysql_query ($ SQL _insert) or die (mysql_error ());
If ($ num! = 1 ){
$ This-> _ error (INSERT_ERROR );
}
}
/*
* Send email to $ smtpemailto
* @ Access public
* @ Param string $ mailtype mail_from type
* @ Param string $ smtpemailto mail_from
* @ Param string $ user_kid_name mail title
* @ Return void
*/
Function reply_email ($ mailtype, $ smtpemailto, $ user_kid_nickname ){
Require "config. php ";
$ Mailsubject = "You have not". $ user_kid_nickname. "";
$ Mailsubject = "=? UTF-8? B? ". Base64_encode ($ mailsubject )."? = ";
$ Mailbody = "Add a baby first ";
If ($ send_mail = false ){
Return "send faile ";
$ Send_mail = $ smtp-> sendmail ($ smtpemailto, $ smtpusermail, $ mailsubject, $ mailbody, $ mail_type ,"","");
}
}
/*
* The kid's age then publication kid words
* @ Access public
* @ Param int $ kid_birthday kid birthday
* @ Return array kid year month day
*/
Function get_kid_age_info ($ kid_birthday ){
$ Cur_date = date ("Ymd ");
$ Age = $ cur_date-$ kid_birthday;
If ($ age <0 ){
Return false;
}
$ Years = 0;
$ Months = 0;
$ Days = 0;
'If ($ age> 10000 ){
$ Years = floor ($ age/10000 );
}
$ Age = $ age % 10000;
$ Months = floor ($ age/100 );
If ($ months> 12)
$ Months-= 88;
$ Days = $ age % 100;
If ($ days> $ cur_date %100 ){
$ Days = $ days-(100-date ("d", strtotime (date ("Ym"). "01")-24*3600 ));
}
Return array (
$ Years,
$ Months,
$ Days
);
}
/**
* Judge the $ m message and the $ x data
* @ Access public
* @ Param array $ users mail information
* @ Param array $ str user information
* @ Param int $ m $ users grade
* @ Param int $ x $ str grade
* @ Param string $ post_text the mail text
* @ Return string information
*/
Function is_kid ($ users, $ str, $ m, $ x, $ post_text, $ post_link_num, $ post_text_undo ){
If ($ users [$ m] ['from _ mail'] = $ str [$ x] ['mail']) {// determines whether the child is from_mail
$ Kid_id = $ str [$ x] ['Kid _ id'];
$ User_name = $ str [$ x] ['User _ name'];
$ User_nickname = $ str [$ x] ['User _ nickname'];
$ Kid_diff = $ str [$ x] ['Kid _ birthday'];
$ Kid_name = $ str [$ x] ['Kid _ name'];
$ Kid_diff = date ("Ymd", $ kid_diff );
$ Kid_birthdy = $ this-> get_kid_age_info ($ kid_diff );
// Format conversion
For ($ j = 0; $ j <count ($ kid_birthdy); $ j ++ ){
If ($ kid_birthdy [$ j]> = 0 & $ kid_birthdy [$ j] <10 ){
$ Kid_birthdy [$ j] = "0". "$ kid_birthdy [$ j]";
}
}
$ Post_time = $ kid_birthdy [0]. $ kid_birthdy [1]. $ kid_birthdy [2];
$ User_avatar = get_kid_avatar ($ user_name, $ kid_id );
$ Kid_avatar = $ user_avatar;
If ($ users [$ m] ['Kid _ nickname'] = $ kid_name ){
$ Kid_id = mysql_real_escape_string ("$ kid_id ");
$ User_name = mysql_real_escape_string ("$ user_name ");
$ Post_time = mysql_real_escape_string ("$ post_time ");
$ Kid_avatar = mysql_real_escape_string ("$ kid_avatar ");
$ From = POST_FROM_EMAIL;
$ Add_time = time ();
$ Values = "'$ kid_id', '$ user_name', '$ user_nickname', '$ post_time', '$ post_text', '$ kid_avatar', '$ post_link_num ', '$ post_text_undo', '$ from', '$ add_time '";
Return $ values;
}
}
}
/**
* Have the kid_num kid of users information
* @ Access public
* @ Param array $ users the array () of users
* @ Param int $ m the m items of array
* @ Param int $ kid_num the kid_num kid
* @ Return array kid information
*/
Function user_kid ($ users, $ m, $ kid_num ){
$ M_mail = $ users ["$ m"] ['from _ mail'];
$ SQL = "SELECT a. user_name, a. user_nickname, B. kid_id, B. kid_name, B. kid_avatar, B. kid_birthday
FROM't _ users 'a,'t _ users_kid 'B
WHERE a. mail = '$ m_mail' AND a. user_id = B. user_id order by B. kid_birthday ASC ";
$ Query = mysql_query ($ SQL) or die (mysql_error ());
$ Str1 = array ();
$ Kids = array ();
$ I = 0;
While ($ arr = mysql_fetch_array ($ query )){
$ Str1 [$ I] = $ arr;
$ I = $ I + 1;
}
$ Kid_num = $ kid_num-1;
If ($ kid_num> (count ($ str1)-1 )){
Return $ num = 0;
} Else {
Return $ str1 ["$ kid_num"];
}
}
/**
* Get the kid_num kid information
* @ Access public
* @ Param array $ users the array () of users
* @ Param int $ m the m items of array
* @ Param int $ kid_num the kid_num kid
* @ Param string $ post_text the message of mail
* @ Param int $ post_link_num count (link) of message body
* @ Return array $ values the kid information
*/
Function kid_data ($ users, $ m, $ kid_num, $ post_text, $ post_link_num, $ post_text_undo ){
$ Use_kid = $ this-> user_kid ($ users, $ m, $ kid_num );
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.