A simple webmail system

zhaozj2021-02-08  324

A simple webmail system Source: Sadly This is a web mail demonstration code, the function is not very strong, but the structure is complete, the main functions such as viewing folders, view letters, reply, write letters. However, there is no problem with attachment interpretation and transmission. (Originally here). Recommend only for users who want to understand Webmail programming to make a reference. More complete webmail, please find it here. Note: HTTP authentication features are used in the program, which needs to be used with the Apache server.

-------------------------------------------------- ------------------------------ The following code is stored as index.php3, iMapFuncs.phl configuration imapfuncs.phl file $ M_host = "localhost"; $ m_mailserver = "transit.fast.no"; then browse INDEX.PHP3. -------------------------------------------------------------------------------- -------------------------------------------------- ------ Index.php3

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

M_Login ($ M);

?> <pHP echo "$ m_sysname";?> </ Title> </ head> <body bgcolor = # aaaaaa tom = # 000000 link = # 440000 vLink = # 440000 alink = # Ff00ff> <h1 align = center> <? Php echo "$ m_sysname";?> </ H1> <hr size = 1 Noshade></p> <p><P> <? PHPIF ($ cmd == "delete") {m_delete ($ marked, $ m); m_list ($ m);</p> <p>Elseif ($ cmd == "display") {m_display ($ n, $ m);</p> <p>Elseif ($ cmd == "compose" || $ cmd == "reply") {m_compose ($ n, $ m);}</p> <p>Elseif ($ CMD == "Send") {m_send ($ to, $ subject, $ body); m_list ($ m);}</p> <p>Else {m_list ($ m);}?></p> <p><P></p> <p><Hr size = 1 Noshade> <? Php echo "User: $ PHP_AUTH_USER";?></p> <p></ Body> </ html></p> <p>-------------------------------------------------- ----------------------------- ImapFuncs.phl</p> <p><? PHP / * - * - C - * - * /</p> <p>/ * $ ID: ImapFuncs.phl, V 1.4 1999/04/14 12:12:32 Borud EXP $ * // * configurable parameters * /</p> <p>$ M_host = "localhost"; $ m_mailserver = "transit.fast.no";</p> <p>$ M_color_odd = "#cccccc"; $ m_color_even = "#eeeeee"; $ m_color_head = "#aaaaff"; $ m_color_bg = "#fffff";</p> <p>/ * 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;</p> <p>/ * functions * /</p> <p>Function M_Login ($ mailbox = '') {global $ mbox, $ m_realm; global $ pHP_AUTH_USER, $ PHP_AUTH_PW;</p> <p>IF ($ mbox) {return true;}</p> <p>IF ($ PHP_AUTH_USER) {m_reject ($ m_realm);</p> <p>$ Mbox = @imap_open (m_mailbox_name ($ mailbox), $ PHP_AUTH_USER, $ PHP_AUTH_PW);</p> <p>IF (! $ mbox) {m_reject ($ m_realm);</p> <p>Return True;}</p> <p>Function M_List ($ mailbox = ') {Global $ Mbox, $ PHP_SELF; Global $ m_color_odd, $ m_color_even, $ m_color_head, $ m_color_bg;</p> <p>/ * if not logged into server, do so * / if (! $ mbox) {if (! m_login ($ mailbox)) {Return False;}}</p> <p>$ NUM = IMAP_NUM_MSG ($ MBOX);</p> <p>Echo "<form action = $ PHP_SELF TYPE = POST> / N"; ECHO "<center> <Table Border = 0 cellspacing = 0 cellpadding = 1 width = 90%> / n";</p> <p>Echo "<tr align = left bgcolor = $ m_color_head>"; echo "<th> </ th> <tr> from </ th> <th> Subject </ TH> <TH> DATE </ TH>"; ECHO "</ Tr> / n";</p> <p>For ($ I = 1; $ i <NUM 1); $ I ) {$ head = IMAP_HEADER ($ Mbox, $ I, 50, 50, 0);</p> <p>$ from = $ head-> fetchfrom; $ subj = $ head-> fetchsubject; $ date = m_date_format ($ head-> date);</p> <p>$ bgcolor = ($ I% 2 == 0)? $ m_color_odd: $ m_color_even;</p> <p>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= $iperic $ $ subj </a> </ td>; echo <TD > $ DATE </ TD> / N "; ECHO" </ TR> / N ";</p> <p>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 ";}</p> <p>Echo "<tr bgcolor = $ m_color_head> <td color_ = 4>"; echo "<input type = submit name = cmd value = delete>"; echo "<input type = subsmit name = cmd value = compose>; echo <Input type = submit name = cmd value = refresh> "; ECHO" </ td> </ tr> / n ";</p> <p>Echo "</ table> </ center> / n"; ECHO "</ form> / n";</p> <p>Return True;}</p> <p>Function M_Display ($ MSGNO, $ Mailbox = ') {Global $ MBOX, $ M_COLOR_HEAD, $ M_COLOR_BG; GLOBAL $ PHP_SELF;</p> <p>IF (! $ mbox) {if (! m_login ($ mailbox)) {return false;}}</p> <p>$ Struc = IMAP_FETCHSTRUCTURE ($ MBOX, $ MSGNO); if (! $ struc) {Return False;}</p> <p>$ Head = IMAP_HEADER ($ Mbox, $ MSGNO, 50, 50, 0);</p> <p>$ from = $ head-> fromaddress; $ subj = $ head-> subject; $ date = $ head-> date; $ body = htmlentities (IMAP_BOX, $ MSGNO);</p> <p>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" <hr size = 2 Noshade> / N "; 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 = subsmit name = cmd value = reply> "; echo" <input type = submit name = cmd value = delete></p> <p>ECHO "</ td> </ Tr> / N"; ECHO "</ Table> / N"; ECHO "</ center> / n";</p> <p>Return True;}</p> <p>Function M_Delete ($ MSGNO, $ Mailbox = ') {Global $ MBOX;</p> <p>IF (IS_ARRAY ($ Dummy, $ Num) = Each ($ msgno)) {IMAP_DELETE ($ Mbox, $ Num);}} else {return false;}</p> <p>Return True;}</p> <p>Function m_compose ($ msgno = ', $ mailbox =') {global $ mbox, $ m_color_head, $ m_color_bg; global $ pHP_SELF, $ PHP_AUTH_USER, $ M_MAILSERVER;</p> <p>IF ($ MSGNO! = '') {$ head = imap_header ($ Mbox, $ MSGNO, 150, 150, 0); $ to = $ head-> fromaddress; $ subject = "RE:" $ head-> subject $ body = "$ to write: / 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 ";</p> <p>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 ";</p> <p>echo "<tr bgcolor = $ m_color_bg> <TD colspan = 2>"; echo "<textarea cols = 76 rows = 10 name = body wrap = hard> $ body </ textarea> / n"; echo "</ td> </ TR> / N ";</p> <p>Echo "<tr bgcolor = $ m_color_head> <td color_ = 2>"; echo "<input type = hidden name = m value = $ mailbox>"; echo "<input type = submit name = cmd value = send> Echo "<input type = submit name = cmd value = cancel>"; ECHO "</ td> </ tr>";</p> <p>Echo "</ table> </ form> / n"; echo "</ center> / n";</p> <p>Function M_Send ($ To, $ Subject, $ Body) {Global $ PHP_AUTH_USER, $ M_MAILSERVER, $ m_sysname; if ($ PHP_AUTH_USER && $ M_MAILSERVER && $ To && $ Body) {</p> <p>$ headers = "from: $ 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 ";</p> <p>Return Mail ($ To, $ Subject, $ Body, $ Headers);</p> <p>Return false;}</p> <p>Function m_date_format ($ datestr) {</p> <p>IF (EREG ("([: DIGIT:]] {1, 2}) [[: space:]] ([: alpha:]] {3}) [[: space:]] ([[[: Space:]] : Digit:] {4}) ", $ DATESTR, $ regs)) {Return $ regs [0];</p> <p>Return $ datestr;}</p> <p>Function M_Mailbox_name ($ MBX) {Global $ M_MBOX;</p> <p>/ * No Mailbox Specified Means WE Map It To The Inbox * / IF ($ MBX == ") {Return $ M_MBOX." Inbox ";</p> <p>/ * Replace Some Special Chars * / $ MBX = EREG_REPLACE ("[^ [: Alnum:]", "_", $ MBX);</p> <p>Return $ M_MBOX. $ MBX;}</p> <p>Function M_REJECT ($ DOM) {header ("http / 1.0 401 unauthorized"); Header ("WWW-Authenticate: Basic Realm = /" $ DOM / "); Echo" Access Denied / N "; EXIT;</p> <p>/ * Make Sure The Is No Trailing Space Here !!! * /?></p> <p>-------------------------------------------------- ------------------------------</p> <p>Editor's finishing: China PHP Freedom Alliance [Close Window] - 2000-03-28 -</p> <p>CopyRight? 2000 Chinese PHP Power All Rights Reserved.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-1016.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="1016" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.037</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '7bQnyJDp_2FGVcSYNI8f0cGJf3F06UH7_2F_2F_2FBlatXZVtWDyys3jRVjycWb5HPns4Qc_2BPL4n4SIJroPpoM1U_2FIA9Cg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>