Building a simple Webmail system

Source: Internet
Author: User
Tags date http authentication imap
This is a piece of web mail model code, the function is not very strong, but the structure is relatively complete, the main features such as viewing folders, viewing letters, replies, letters are available. However, the program does not consider the attachment interpretation and transmission issues. (the original is here). Only recommended for users who want to know webmail programming to do a reference. More Perfect Webmail Please come here to find out.
Please note that the HTTP authentication feature is used in the program, and this feature needs to be used with the Apache server.




--------------------------------------------------------------------------------
Save the following code separately as INDEX.PHP3, IMAPFUNCS.PHL
Configure the $m_host = "localhost" in the IMAPFUNCS.PHL file; $M _mailserver = "transit.fast.no";
Then browse index.php3.
--------------------------------------------------------------------------------
Index.php3

? Php
/* $Id: Index.php3,v 1.3 1999/04/14 12:12:32 Borud EXP $ * *

/* Load the IMAP library functions we\ ' ve written * *
Include ("IMAPFUNCS.PHL");

M_login ($m);

?>
<HTML>
<HEAD>
<title><? PHP echo "$M _sysname";?></title>
</HEAD>
<body bgcolor= #AAAAAA text= #000000 link= #440000 vlink= #440000 alink= #FF00FF >

&LT;HR size=1 noshade>

<P>
? Php
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);
}
?>

<P>

&LT;HR size=1 noshade>
? PHP echo "User: $PHP _auth_user";?>

</BODY>
</HTML>






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

? PHP/*-*-c++-*-*

/* $Id: Imapfuncs.phl,v 1.4 1999/04/14 12:12:32 Borud EXP $ * *

/* Configurable 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, does so * *
if (! $MBOX) {
if (! M_login ($mailbox)) {
return false;
}
}

$num = Imap_num_msg ($MBOX);

echo "<form action= $PHP _self type=post>\n";
echo "<center><table border=0 cellspacing=0 cellpadding=1 width=90%>\n";

echo "<tr align=left bgcolor= $M _color_head>";
echo "<TH> </TH><TH>From</TH><TH>Subject</TH><TH>Date</TH>";
echo "</tr>\n";

For ($i =1 $i < ($num + 1); $i + +) {
$head = Imap_header ($MBOX, $i, 50, 50, 0);

$from = $head->fetchfrom;
$SUBJ = $head->fetchsubject;
$date = M_date_format ($head->date);

$bgcolor = ($i%2 = = 0)? $M _color_odd: $M _color_even;

echo "<tr bgcolor=\" $bgcolor \ ">\n";
echo "<td><input Type=checkbox name=marked[] value= $i ></td>\n";
echo "<TD> $from </TD>";
echo "<td><a href=\" $PHP _self?m= $mailbox &n= $i &cmd=display\ "> $subj </A></TD>";
echo "<TD> $date </td>\n";
echo "</tr>\n";
}

if ($num <= 0) {
echo "<tr><td align=center colspan=4 bgcolor= $M _color_bg><br>";
echo "<font size=+1 color= #FF0000 >no messages in mailbox</font>";
echo "<br><br></td></tr>\n";
}

echo "<tr bgcolor= $M _color_head><td colspan=4>";
echo "<input type=submit name=cmd value=delete>";
echo "<input type=submit name=cmd value=compose>";
echo "<input type=submit name=cmd value=refresh>";
echo "</td></tr>\n";

echo "</table></center>\n";
echo "</form>\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 "<center>\n";
echo "<table border=0 cellspacing=0 cellpadding=10 width=100%>\n";
echo "<tr bgcolor= $M _color_head><th>message $msgno: $from/$subj </th></tr>\n";
echo "<tr bgcolor= $M _color_bg><td><pre>\n";
echo "from: $from \ n";
echo "Subject: $SUBJ \ n";
echo "Date: $date \ n";
echo "echo "$body \ n";
echo "</pre></td></tr>\n";
echo "<tr bgcolor= $M _color_head><td>";

echo "<form action= $PHP _self method=post>";
echo "<input type=hidden name=m value= $mailbox >\n";
echo "<input type=hidden name=n value= $msgno >\n";
echo "<input Type=hidden name=marked[] value= $msgno >\n";
echo "<input type=submit name=cmd value=back>";
echo "<input type=submit name=cmd value=reply>";
echo "<input type=submit name=cmd value=delete>";

echo "</td></tr>\n";
echo "</table>\n";
echo "</center>\n";

return true;
}

function M_delete ($msgno, $mailbox = ')
{
Global $MBOX;

if (Is_array ($msgno)) {
while (the list ($dummy, $num) = each ($msgno)) {
Imap_delete ($MBOX, $num);
}
Imap_expunge ($MBOX);
} else {
return false;
}

return true;
}

function M_compose ($msgno = ', $mailbox = ')
{
Global $MBOX, $M _color_head, $M _color_bg;
Global $PHP _self, $PHP _auth_user, $M _mailserver;

if ($msgno!= ') {
$head = Imap_header ($MBOX, $msgno, 150, 150, 0);
$to = $head->fromaddress;
$subject = "Re:". $head->subject;
$body = "$to wrote:\n";
$body. = ereg_replace ("\ n", "\n>", "\ n". Imap_body ($MBOX, $msgno));
} else {
$to = "";
$subject = "";
$body = "";
}

echo "<center>\n";
echo "<form method=post action=\" $PHP _self\ ">\n";
echo "<table border=0 cellpadding=5 cellspacing=0>\n";
echo "<tr bgcolor= $M _color_head><td align=right>to:</td>";
echo "<td><input type=text name=to value=\" $to \ "size=50></td></tr>\n";

echo "<tr bgcolor= $M _color_head><td align=right>subject:</td>";
echo "<td><input type=text name=subject value=\" $subject \ "size=50></td></tr>\n";

echo "<tr bgcolor= $M _color_bg><td colspan=2>";
echo "<textarea cols=76 rows=10 name=body wrap=hard> $body </TEXTAREA>";

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.