A simple Webmail system

Source: Internet
Author: User
Tags http authentication
Sadly is a demo code of WebMail. it is not very functional, but its structure is still complete. its main functions include viewing folders, viewing letters, replying to letters, and writing letters. However, the program does not consider the issue of attachment interpretation and sending. (The original article is here ). It is only recommended to users who want to know Webmail programming for reference. For more comprehensive Webmail, please check WebMail here

Sadly

This is a demo code of Web Mail. it is not very functional, but has a complete structure. its main functions include viewing folders, viewing letters, replying to letters, and writing letters. However, the program does not consider the issue of attachment interpretation and sending. (The original article is here ). It is only recommended to users who want to know Webmail programming for reference. For more comprehensive Webmail, please visit here.
Note: http authentication is used in the program. this function must be used with the apache server.


--------------------------------------------------------------------------------
Save the following code as index. php3, imapfuncs. phl
Configure $ M_HOST = "localhost" in the imapfuncs. phl file; $ M_MAILSERVER = "transit. fast. no ";
Then browse index. php3.
--------------------------------------------------------------------------------
Index. php3

/* $ Id: index. php3, v 1.3 12:12:32 borud Exp $ */

/* Load the IMAP library functions we 've written */
Include ("imapfuncs. phl ");

M_login ($ m );

?>


<? PHP echo "$ M_SYSNAME";?>




If ($ cmd = "delete "){
M_delete ($ marked, $ m );
M_list ($ m );
}

Elseif ($ cmd = "display "){
M_display ($ n, $ m );
}

Elseif ($ cmd = "compose" | $ cmd = "reply "){
M_compose ($ n, $ m );
}

Elseif ($ cmd = "send "){
M_send ($ to, $ subject, $ body );
M_list ($ m );
}

Else {
M_list ($ m );
}
?>




--------------------------------------------------------------------------------
Imapfuncs. phl

/* $ Id: imapfuncs. phl, v 1.4 12:12:32 borud Exp $ */

/* Retriable parameters */


$ M_HOST = "localhost ";
$ M_MAILSERVER = "transit. fast. no ";

$ M_COLOR_ODD = "# CCCCCC ";
$ M_COLOR_EVEN = "# EEEEEE ";
$ M_COLOR_HEAD = "# AAAAFF ";
$ M_COLOR_BG = "# FFFFFF ";


/* Globals */
$ M_PORT = 143;
$ M_SERVICE = "imap ";
$ M_SYSNAME = "Simple PHP3 IMAP Interface 1.0 ";
$ M_MBOX = "{$ M_HOST: $ M_PORT/$ M_SERVICE }";
$ M_REALM = "IMAP Interface ";
$ MBOX = false;

/* Functions */

Function m_login ($ mailbox = ')
{
Global $ MBOX, $ M_REALM;
Global $ PHP_AUTH_USER, $ PHP_AUTH_PW;

If ($ MBOX ){
Return true;
}

If (! $ PHP_AUTH_USER ){
M_reject ($ M_REALM );
}

$ MBOX = @ imap_open (m_mailbox_name ($ mailbox), $ PHP_AUTH_USER, $ PHP_AUTH_PW );

If (! $ MBOX ){
M_reject ($ M_REALM );
}

Return true;
}


Function m_list ($ mailbox = ')
{
Global $ MBOX, $ PHP_SELF;
Global $ M_COLOR_ODD, $ M_COLOR_EVEN, $ M_COLOR_HEAD, $ M_COLOR_BG;

/* If not logged into server, do so */
If (! $ MBOX ){
If (! M_login ($ mailbox )){
Return false;
}
}

$ Num = imap_num_msg ($ MBOX );

Echo "\ n ";

Return true;
}


Function m_display ($ msgno, $ mailbox = ')
{
Global $ MBOX, $ M_COLOR_HEAD, $ M_COLOR_BG;
Global $ PHP_SELF;

If (! $ MBOX ){
If (! M_login ($ mailbox )){
Return false;
}
}

$ Struc = imap_fetchstructure ($ MBOX, $ msgno );
If (! $ Struc ){
Return false;
}

$ Head = imap_header ($ MBOX, $ msgno, 50, 50, 0 );

$ From = $ head-> fromaddress;
$ Subj = $ head-> subject;
$ Date = $ head-> date;
$ Body = htmlentities (imap_body ($ MBOX, $ msgno ));

Echo"

\ N ";
Echo"


\ N ";Echo" \ N ";Echo" \ N ";Echo"
Message # $ msgno: $ from/$ subj
\n";
echo "From: $from\n";
echo "Subject: $subj\n";
echo "Date: $date\n";
echo " \n";
echo "$body\n";
echo "
";

Echo "\ n ";
Echo"\ N ";
}


Function m_send ($ to, $ subject, $ body)
{
Global $ PHP_AUTH_USER, $ M_MAILSERVER, $ M_SYSNAME;

If ($ PHP_AUTH_USER & $ M_MAILSERVER & $ to & $ body ){

$ Headers = "From: $ PHP_AUTH_USER @ $ M_MAILSERVER \ n ";
$ Headers. = "Reply-to: $ PHP_AUTH_USER @ $ M_MAILSERVER \ n ";
$ Headers. = "Content-Type: text/plain; charset = ISO-8859-1 \ n ";
$ Headers. = "Content-Transfer-Encoding: 8bit \ n ";
$ Headers. = "X-Mailer: $ M_SYSNAME/". phpversion (). "\ n ";

Return mail ($ to, $ subject, $ body, $ headers );
}

Return false;
}

Function m_date_format ($ datestr)
{

If (ereg ("([[: digit:] {1, 2}) [[: space:] + ([[: alpha:] {3 })[[: space:] + ([[: digit:] {4 })",
$ Datestr, $ regs )){
Return $ regs [0];
}

Return $ datestr;
}

Function m_mailbox_name ($ mbx)
{
Global $ M_MBOX;

/* No mailbox specified means we map it to the inbox */
If ($ mbx = ""){
Return $ M_MBOX. "INBOX ";
}

/* Replace some special chars */
$ Mbx = ereg_replace ("[^ [: alnum:]", "_", $ mbx );

Return $ M_MBOX. $ mbx;
}


Function m_reject ($ dom)
{
Header ("HTTP/1.0 401 Unauthorized ");
Header ("WWW-authenticate: basic realm = \" $ dom \"");
Echo "Access denied \ n ";
Exit;
}

/* Make sure there is NO trailing space here !!! */
?>


--------------------------------------------------------------------------------

Edit: China PHP Free Alliance
[Close the window]-2000-03-28-

Copyright? 2000 Chinese PHP Power All rights reserved.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.