Momail

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Momail

    someone help me to configure this script..

    <div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'><?php
    /*
    Momail v5 (beta), 22 February 2006

    Copyright © 2004-2006 Maarten Laurs

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details (www.gnu.org).


    So what&#39;s new?

    - Still in beta and therefore disabled by default is the
    possibility to send new emails using Momail. You can enable
    this feature by setting $sendMail = true in the options below.
    At this time you cannot reply to messages, but this will be
    added in later versions.
    - We also have improved the interface. Links to the inbox,
    provider list and so on, are now also available at the
    top of every page.


    Installing Momail : This is what you have do one time only:

    - Copy/paste the entire code
    - Enter the connection data below
    - Give the file a name and a php extension (like .php or .php3)
    (security tip: choose a complex name that no-one will guess)
    - Upload the file to a web server that supports both php and imap
    You can test your web server by running this script: <?php phpinfo(); ?>
    If you can&#39;t find a chapter on IMAP when running this script, chances are it is
    not supported by your webserver and Momail will not work properly and maybe not at all
    - experimental: do not fill in a username or password and use Momail with multiple people
    using the same mail server, but different e-mail accounts. Is not yet available for some
    mobile phones and needs a bit more work.


    Any suggestion or questions are welcome in the forums at
    http://momail.sourceforge.net/forums

    Have fun, Maarten Laurs

    */

    // Number of messages per page (you can change this if you like)
    $num = 9;

    // Maximum message byte size (you can change this if you like)
    // 3600 is best for wap devices with a 5.6k limit (like most popular mobile phones)
    $max_chars = 3600;

    // Enable the Send Mail feature by setting this to true
    $sendMail = false; // can either be true or false

    // connection data //

    /* How to enter the connection data
    Look at the connection arrays below (they are called $serv_#).
    Exchange the information in the arrays so that they reflect your situation.
    "server" should be the path to the mailserver together with some protocol information.
    Examples for the different protocols:
    - imap non-secure: {server:143/imap/notls}Inbox
    - imap secure: {server:993/imap/ssl/novalidate-cert}Inbox
    - pop3 non-secure: {server:110/pop3/notls}Inbox
    - pop3 secure: {server:995/pop3/ssl/novalidate-cert}Inbox
    See http://www.php.net/imap_open for some more examples
    "nickname" is an arbitrary name that you choose to refer to the e-mail provider
    "emailaddress" is your e-mail address that belongs together with the e-mail account
    "name" should reflect the username that you have to use to logon to the mailserver
    "password" comes with the username that was provided to you by the e-mail provider
    If you add or remove an array be sure you number them nicely
    Do not forget to change the $number_of_arrays parameter that is directly below this section
    Be sure to check all the quotation-marks (") and comma&#39;s (,) when you are done or the script will not work
    */

    $number_of_arrays = 3; // this is the number of arrays that are listed below

    $serv_1 = array(
    "server" => "{pop3.server.com:110/pop3/notls}Inbox",
    "nickname" => "nickname provider 1",
    "emailaddress" => "yourname@server.com",
    "name" => "enter username",
    "password" => "enter password"
    );

    $serv_2 = array(
    "server" => "{imap.server.net:993/imap/ssl/novalidate-cert}Inbox",
    "nickname" => "provider two&#39;s nickname",
    "emailaddress" => "you@server.net",
    "name" => "enter username",
    "password" => "enter password"
    );

    $serv_3 = array(
    "server" => "{www.yourdomain.com:110/pop3/notls}Inbox",
    "nickname" => "nickname for a third provider",
    "emailaddress" => "someone@yourdomain.com",
    "name" => "enter username",
    "password" => "enter password"
    );


    // do not forget to change the $number_of_arrays if
    // you add or delete any of the arrays above here!!

    ///////////////////////////////////////////////////////////////////////////
    // that&#39;s it, no more variables to consider beyond this point, have fun! //
    ///////////////////////////////////////////////////////////////////////////

    /************************************************** ******************************
    **\
    * URL variables
    These variables can be expected to travel inside the URL (or URI for that matter)
    c : message offset number when displaying the inbox
    d : parameters for message deletion
    f : message string fetch offset
    m : message number
    p : $serv_# parameter
    w : write message

    * Message functions
    These functions operate on an e-mail message
    - mes_del : delete message
    - mes_incl : include message in a reply
    - mes_prop : retrieve message properties

    * Display functions
    These produce output to the browser
    - disp_prov : e-mail accounts
    - disp_inbox : inbox
    - disp_mes : e-mail message
    - disp_login : login screen
    - disp_sendmail : display links to write e-mail
    - disp_delmes : delete message dialog

    * Other functions
    - send_mail : display send mail interface and send mail handling
    - buidl_wml : build up of wml page
    \************************************************* **************************
    *******/

    // delete message
    function mes_del()
    {
    // set globals
    global $HTTP_GET_VARS, $prov, $conn;

    // get initial message count
    $status_old = imap_status($conn , $prov["server"] , SA_MESSAGES);
    $msg_ini_count = $status_old -> messages;

    // split $d to get msgno and date
    list($del_msgno , $del_date) = split(";" , $HTTP_GET_VARS["d"]);

    // get date of message by msgno, check hash of date against $del_date
    // if the two dates match delete message
    $del_headers = @imap_header($conn , $del_msgno);
    if(md5($del_headers -> date) == $del_date)
    {
    imap_delete($conn , $del_msgno);
    imap_expunge($conn);
    }

    // get final message count
    $status_new = imap_status($conn , $prov["server"] , SA_MESSAGES);
    $msg_final_count = $status_new -> messages;

    // display whether the deletion was succesfull or not
    if($msg_ini_count > $msg_final_count)
    {
    echo "Messagedeleted
    \n";
    }
    else
    {
    echo "Message was not deleted
    \n";
    }

    // reset or unset variables that may have changed
    if($del_msgno == $HTTP_GET_VARS["c"]) $HTTP_GET_VARS["c"] -= 1;
    if($msg_final_count <= 0) unset($HTTP_GET_VARS["c"]);
    }

    // include message
    function mes_incl()
    {
    }

    // retrieve message properties
    function mes_prop($action , $id)
    {
    // set globals
    global $conn;

    // get message headers
    $headers = imap_header($conn , $id);

    // get message structure
    $structure = imap_fetchstructure($conn , $id);

    // what action?
    switch($action)
    {
    // get sender
    case "sender":
    $sender = "";
    $from = $headers -> from;

    if ($from)
    {
    if(!$from[0] -> personal)
    {
    // emailaddress
    $sender = $from[0] -> mailbox . "@" . $from[0] -> host;
    }
    else
    {
    // realname
    $sender = $from[0] -> personal;
    }
    }
    else
    {
    // extract address from unfiltered format header when there is no $from
    $alt_headers = strtolower(imap_fetchheader($conn , $id));
    $return_path = strstr($alt_headers , "return-path");
    $end_pos = strpos($alt_headers , "\r\n" , $return_path);
    $sender = trim(substr($return_path , 12 , $end_pos-13));
    $sender = preg_replace("/<|>/" , "" , $sender);
    }
    return $sender;

    // get date
    case "date":
    $date = "date: not found";
    if($headers -> date)
    {
    $date = $headers -> date;
    }
    else
    {
    $alt_headers = strtolower(imap_fetchheader($conn , $id));
    $date_set = strstr($alt_headers, "delivery-date");
    if($date_set)
    {
    $end_pos = strpos($alt_headers , "\r\n" , $date_set);
    $date = trim(substr($date_set, 15, $end_pos-4));
    $date = ucwords($date);
    }
    }
    return $date;

    // get subject
    case "subject":
    $subject = "No subject";
    if($headers -> subject) $subject = parse_preg($headers -> subject); // function parse_preg() is located elsewhere
    return $subject;

    // get size
    case "size":
    $size = "?";
    if($headers -> Size) $size = round(($headers -> Size / 1024 ), 1);
    return $size;

    // get message body
    case "message":
    $message = "<empty>";
    return $message;

    // get message number
    case "number":
    $message_n = trim($headers -> Msgno);
    return $message_n;

    // get attachment info
    case "attachments":
    $attached = "";
    $attachment_info = "";
    $n_attachments = 0;
    $parts = count($structure -> parts);
    for($i = 0; $i <= $parts; $i++)
    {
    $part = $structure -> parts[$i];
    if($part -> ifdisposition && strtolower($part -> disposition) == "attachment" && $part -> ifdparameters)
    {
    $file = htmlspecialchars($part -> dparameters[0] -> value);
    $size = round($structure -> parts[$i] -> bytes / 1024 , 1);
    $attached .= $file . "(" . $size . "Kb)
    \n";
    $n_attachments += 1;
    }
    }
    if($n_attachments > 0)
    {
    $attachment_info = "
    \nAttachments:
    \n";
    $attachment_info .= $attached . "
    \n";
    }
    return $attachment_info;
    }
    }

    // display e-mail accounts
    function disp_prov()
    {
    // set globals (except $$serv which is set later in this function)
    global $HTTP_SERVER_VARS, $number_of_arrays;

    echo "Select provider
    \n";
    for ($i = 1; $i <= $number_of_arrays; $i++)
    {
    // set provider
    $serv = "serv_" . $i;
    global $$serv;
    $prov_array = $$serv;

    // get number of unseen (imap) / total (pop3) messages on server
    imap_timeout(1,1);
    imap_timeout(2,1);
    $conn = @imap_open ($prov_array["server"] , $prov_array["name"] , $prov_array["password"]);
    $new_messages = "?";
    if ($conn)
    {
    $inbox = imap_status($conn , $prov_array["server"] , SA_UNSEEN);
    if($inbox) $new_messages = $inbox -> unseen;
    }

    // display provider&#39;s nickname and number of new messages
    $nickname = $prov_array["nickname"];
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=" . $serv . "\">" . $nickname . "(" . $new_messages . ")</a>
    \n";
    }
    }

    // display inbox
    function disp_inbox()
    {
    // set globals
    global $HTTP_GET_VARS
    , $HTTP_SERVER_VARS
    , $session_urls
    , $num
    , $conn
    , $number_of_arrays
    ;

    // get number of messages in inbox
    $check = imap_check($conn);
    if($check) $Nmsgs = $check -> Nmsgs;

    // set first and number of messages to be displayed
    if(!ISSET($HTTP_GET_VARS["c"]) || $HTTP_GET_VARS["c"] > $Nmsgs || $HTTP_GET_VARS["c"] < 1) $HTTP_GET_VARS["c"] = $Nmsgs;
    $end = $HTTP_GET_VARS["c"] - $num; // $num is set at the beginning of this script
    if($end < 1) $end = 1;

    // build navigation
    $nav_url = "";
    $nav_frm = "";

    // navigation to previous page
    if ($HTTP_GET_VARS["c"] != $Nmsgs)
    {
    $prev = ($HTTP_GET_VARS["c"] + $num + 1);
    if ($prev > $Nmsgs) $prev = $Nmsgs;
    $href = $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=" . $HTTP_GET_VARS["p"] . "&amp;c=" . $prev;
    $nav_url .= "<a href=\"" . $href . "\">Previous</a>\n";
    $nav_frm .= "<do name=\"previous\" type=\"accept\" label=\"Previous\">\n";
    $nav_frm .= "<go href=\"" . $href . $session_urls["amp"] . "\" />\n";
    $nav_frm .= "</do>\n";
    }

    // navigation to next page
    if($end != 1)
    {
    $next = ($HTTP_GET_VARS["c"] - ($num + 1));
    if ($next < 1) $next = 1;
    $href = $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=" . $HTTP_GET_VARS["p"] . "&amp;c=" . $next;

    $nav_url .= "<a href=\"" . $href . "\">Next</a>\n";
    $nav_frm .= "<do name=\"next\" type=\"accept\" label=\"Next\">\n";
    $nav_frm .= "<go href=\"" . $href . $session_urls["amp"] . "\"/>\n";
    $nav_frm .= "</do>\n";
    }

    // navigation to providers page
    $nav_url .= "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\">Provider</a>\n";
    $nav_frm .= "<do name=\"provider\" type=\"accept\" label=\"Provider\">\n";
    $nav_frm .= "<go href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\" />\n";
    $nav_frm .= "</do>\n";

    if($Nmsgs != 0)
    {
    // display navigation
    echo $nav_url . "
    \n
    \n";

    // display messages
    for ($i = $HTTP_GET_VARS["c"]; $i >= $end; $i--)
    {
    // get message properties
    $sender = mes_prop("sender" , $i);
    $subject = mes_prop("subject" , $i);
    $date = mes_prop("date" , $i);
    $number = mes_prop("number" , $i);
    $size = mes_prop("size" , $i);

    // construct output
    $output = "<a href=\"". $HTTP_SERVER_VARS["PHP_SELF"];
    $output .= "?p=" . $HTTP_GET_VARS["p"] . "&amp;m=" . $number;
    $output .= "&amp;c=" . $HTTP_GET_VARS["c"] . "\">" . $sender . "</a>
    \n";
    $output .= $date . "
    \n";
    $output .= $subject . "(" . $size . "Kb)
    \n
    \n";

    // echo output
    echo $output;
    }

    // display navigation
    echo $nav_url;
    echo $nav_frm;
    }
    else
    {
    // display empty inbox
    echo "Inbox is empty
    \n";
    echo $nav_url;
    echo $nav_frm;
    }
    }

    // display e-mail message
    function disp_mes()
    {
    // set globals
    global $HTTP_GET_VARS, $HTTP_SERVER_VARS, $session_urls, $Nmsgs, $conn, $max_chars;

    // initialize navigation strings
    $nav_url = "";
    $nav_frm = "";

    // output message
    if($HTTP_GET_VARS["m"] <= $Nmsgs && $HTTP_GET_VARS["m"] >= 1)
    {
    // get sender
    $from_var = mes_prop("sender", $HTTP_GET_VARS["m"]);
    $from_var .= " wrote:
    \n";

    // check for multipart message and extract message body
    $structure = imap_fetchstructure($conn , $HTTP_GET_VARS["m"]);
    $part = 1;
    if($structure -> type == 1)
    {
    $part = "1.1";
    if($structure -> parts[0] -> type == 1) $part = "1.1.1";
    }
    if(imap_fetchbody($conn , $HTTP_GET_VARS["m"] , $part) == "") $part = 1;
    $text = imap_fetchbody($conn , $HTTP_GET_VARS["m"] , $part);

    // convert base64 encoded messages
    $base64 = false;
    $headers = strtolower(imap_fetchheader($conn, $HTTP_GET_VARS["m"]));
    if(strstr($headers, "content-transfer-encoding: base64")) $base64 = true;
    if($base64) $text = base64_decode($text);

    // parse preg
    $text = parse_preg($text);

    // truncate message if necessary
    $text_length = strlen($text);
    if($text_length > $max_chars)
    {
    // set length of string to fetch
    if(!ISSET($HTTP_GET_VARS["f"]))
    {
    $HTTP_GET_VARS["f"] = 0;
    }
    $length = $max_chars;
    if(($HTTP_GET_VARS["f"] + $max_chars) > $text_length) $length = ($text_length - $HTTP_GET_VARS["f"]);

    // get part of the message text
    $text = substr($text , $HTTP_GET_VARS["f"] , $length);

    // get position of last "." or
    in message part
    $offset = 0;
    $line_end = ".";
    if(!strpos($text , "." , $offset)) $line_end = "
    ";
    if(strpos($text , $line_end , $offset))
    {
    while(strpos($text , $line_end , $offset))
    {
    $pos = strpos($text , $line_end , $offset);
    $offset = $pos + strlen($line_end);
    }
    }
    else
    {
    // set $offset to $max_char when the $line_end was not found
    $offset = $max_char;
    }

    // get adjusted part of part of message
    $text = substr($text , 0 , $offset);
    }

    // append any useful attachment-info to message string
    $attachments = mes_prop("attachments" , $HTTP_GET_VARS["m"]);
    if($attachments) $text .= $attachments;

    // links to display links to delete message, inbox and provider list
    $href = $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=" . $HTTP_GET_VARS["p"] . "&amp;c=" . $HTTP_GET_VARS["c"];
    $nav_url .= "<a href=\"#del\">Delete</a>\n";
    $nav_frm .= "<do name=\"delete\" type=\"accept\" label=\"Delete\">\n";
    $nav_frm .= "<go href=\"#del\" />\n";
    $nav_frm .= "</do>\n";

    $nav_url .= "<a href=\"" . $href . "\">Inbox</a>\n";
    $nav_frm .= "<do name=\"back\" type=\"accept\" label=\"Inbox\">\n";
    $nav_frm .= "<go href=\"" . $HTTP_SERVER_VARS["PHP_SELF"] . "?p=" . $HTTP_GET_VARS["p"] . "&amp;c=" . $HTTP_GET_VARS["c"] . $session_urls["amp"] . "\" />\n";
    $nav_frm .= "</do>\n";

    $nav_url .= "<a href=\"" . $HTTP_SERVER_VARS["PHP_SELF"] . "\">Provider</a>\n";
    $nav_frm .= "<do name=\"provider\" type=\"accept\" label=\"Provider\">\n";
    $nav_frm .= "<go href=\"" . $HTTP_SERVER_VARS["PHP_SELF"] . "\" />\n";
    $nav_frm .= "</do>\n";

    // build links to next part of messages for message longer than $max_chars
    if(($HTTP_GET_VARS["f"] + $max_chars) < $text_length)
    {
    $offset = $offset + $HTTP_GET_VARS["f"];
    $href = $HTTP_SERVER_VARS["PHP_SELF"]
    . "?p=" . $HTTP_GET_VARS["p"]
    . "&amp;m=" . $HTTP_GET_VARS["m"]
    . "&amp;c=" . $HTTP_GET_VARS["c"]
    . "&amp;f=" . $offset;
    $nav_url .= "<a href=\"$href\">Rest of message</a>\n";
    $nav_frm .= "<do name=\"rest\" type=\"accept\" label=\"Rest message\"><go href=\"$href" . $session_urls["amp"] . "\"/></do>
    \n";
    }

    // preappend sender information
    $text = $from_var . $text;

    // preappend urls
    $text = $nav_url . "
    \n" . $text;

    // display message
    echo utf8_encode($text);

    // append links
    echo $nav_url;
    echo $nav_frm;
    }
    else
    {
    // display error message not on server
    echo "Message is not on server
    \n";
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\">Inbox</a>";
    echo "<do name=\"back\" type=\"accept\" label=\"Inbox\"><go href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . $session_urls["question"];"\"/></do>";
    }
    }

    // display login screen
    function disp_login()
    {
    // set globals
    global $HTTP_GET_VARS, $HTTP_SERVER_VARS, $prov;

    ?>
    Enter login details for <?php echo $prov["nickname"]; ?>

    Username: <input name="name" value="<? if($prov["name"] != "") echo $prov["name"]; ?>"/>

    Password: <input name="ww" type="password" value="<? if($prov["password"] != "") echo $prov["password"]; ?>"/>

    <anchor>Connect
    <go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=" . $HTTP_GET_VARS["p"]; ?>" method="post">
    <postfield name="name" value="$(name)" />
    <postfield name="ww" value="$(ww)" />
    </go>
    </anchor>
    <do type="accept" label="Connect">
    <go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=" . $HTTP_GET_VARS["p"]; ?>" method="post">
    <postfield name="name" value="$(name)" />
    <postfield name="passw" value="$(ww)" />
    </go>
    </do>
    Change provider
    <do name="provider" type="accept" label="Provider"><go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;]; ?>" /></do>
    <?php
    }

    // display link to write new mail
    function disp_sendmail($action , $prov , $id)
    {
    // set globals
    global $HTTP_SERVER_VARS, $sendMail;

    // stop disp_sendmail if sending mail is disabled
    if (!$sendMail) return false;

    // stop disp_sendmail if mail() function is available
    if (!function_exists("mail"))
    {
    echo "Your server doesn&#39;t support sending emails with PHP.";
    return false;
    }

    // create url (action can be &#39;new&#39;, &#39;reply&#39; or &#39;replyall&#39;)
    if ($action == "new")
    {
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?w=" . $action . "\">Write new mail</a>\n";
    }
    else
    {
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?w=" . $action . "&amp;p=" . $prov . "&amp;m=" . $id . "\">Reply</a>\n";
    # Reply to all is not yet implemented
    }
    }

    // display card to delete message
    function disp_delmes()
    {
    // set globals
    global $conn, $HTTP_SERVER_VARS, $HTTP_GET_VARS;

    // display delete message-card
    $del_headers = imap_header($conn , $HTTP_GET_VARS["m"]);

    // hash message date to transfer it succesfully in the query string
    $href_del = $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;]
    . "?p=" . $HTTP_GET_VARS["p"]
    . "&amp;c=" . $HTTP_GET_VARS["c"]
    . "&amp;d=" . $HTTP_GET_VARS["m"]
    . ";" . md5($del_headers -> date);

    ?>
    </p>
    </card>
    <card id="del" title="Delete message">


    Are your sure?

    No

    Yes

    <?php
    }

    /*
    * Parse_preg
    * This function parses a string and converts that
    * string to a character set that is wml compatible
    */
    function parse_preg($text)
    {
    // rid html-only messages of tags and content inside certain tags
    $tags_and_content_to_strip = Array("head" , "title" , "style" , "script");
    foreach ($tags_and_content_to_strip as $tag)
    {
    // this was taken from a message posted anonymously at php.net website and was adapted to fit momail
    $text = preg_replace("/<" . $tag . "(.|\s)*?>(.|\s)*?<\/" . $tag . ">/i" , "" , $text);
    }

    // convert some special characters, like
    and &, to a different character set
    $text = preg_replace("/<br\/?>/i" , "\r\n" , $text);
    $text = preg_replace("//i" , "=20" , $text);
    $text = str_replace("&" , "&amp;" , $text);

    // strip remaining html tags
    $text = strip_tags($text);

    // encode characters like & < > " before adding new ones
    $text = htmlspecialchars($text , ENT_COMPAT , "ISO-8859-1");

    // replace quoted-printable by decimal reference
    $text = preg_replace_callback("/(=)([0-9a-fA-F]{2})/" , "parse_hexdec" , $text); // transform function is written below

    # $text = imap_qprint($text); // is buggie

    // replace dollar sign by ... dollar
    $text = preg_replace_callback("/(\\$)((([0-9])(\\.|,)?){2,})/" , "parse_dollar" , $text); // dollar_transform is written below

    // modify output to comply to xml standard and compact output (rids output of unnecessary
    &#39;s)
    $find = array(
    0 => "/=\r(\n)?/",
    1 => "/\r(\n)?/",
    2 => "/((\s| |)*<br(\s)*\/?>(\r)?(\n)?){3,}/i",
    );
    $replace = array(
    0 => "",
    1 => "
    \r\n",
    2 => "
    \r\n
    \r\n",
    );
    ksort($find);
    ksort($replace);
    $text = preg_replace($find , $replace , $text);

    // quick &#39;n dirty bug fix to &amp;amp;
    $text = str_replace("&amp;amp;" , "&amp;" , $text);

    // return $text
    return $text;
    }

    // additional functions to preg
    function parse_hexdec($matches)
    {
    $hex = $matches[2];
    return "&#" . hexdec($hex) . ";";
    }

    function parse_dollar($matches)
    {
    $amount = $matches[2];
    return $amount . " dollar";
    }
    // end of additional functions

    // send mail
    function send_mail()
    {
    // set globals
    global $HTTP_SERVER_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS, $number_of_arrays;

    // select whether to write or send a message
    if ($HTTP_GET_VARS["w"] != "send")
    {
    // build interface
    if (ISSET($HTTP_GET_VARS["p"]))
    {
    }
    else
    {
    // variable from address
    echo "Sender:<select name=\"sender\">\n";
    for ($i=1; $i <= $number_of_arrays; $i++)
    {
    $serv = "serv_" . $i;
    global $$serv;
    $prov_array = $$serv;
    echo " <option value=\"" . $prov_array["emailaddress"] . "\">" . $prov_array["emailaddress"] . "</option>\n";
    }
    echo "</select>
    \n";
    ?>
    To: <input name="recipient" emptyok="false" value="<? if(ISSET($HTTP_GET_VARS["m"])) echo $HTTP_GET_VARS["r"]; ?>" />

    Subject: <input name="subject" value="<? if(ISSET($HTTP_GET_VARS["s"])) echo "RE:" . $HTTP_GET_VARS["s"]; ?>" />

    <?php
    if ($HTTP_GET_VARS["w"] == "reply")
    {
    ?>
    Include original message? <select name="incl">
    <option value="y">Yes</option>
    <option value="n">No</option>
    </select>

    <?php
    }
    ?>
    Message: <input name="message" value="" />

    <anchor>Send
    <go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;]; ?>?w=send" method="post">
    <postfield name="sender" value="$(sender)"/>
    <postfield name="recipient" value="$(recipient)"/>
    <postfield name="subject" value="$(subject)"/>
    <postfield name="incl" value="$(incl)"/>
    <postfield name="message" value="$(message)"/>
    </go>
    </anchor>
    <do type="accept" label="Send">
    <go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;]; ?>?w=send" method="post">
    <postfield name="sender" value="$(sender)"/>
    <postfield name="recipient" value="$(recipient)"/>
    <postfield name="subject" value="$(subject)"/>
    <postfield name="incl" value="$(incl)"/>
    <postfield name="message" value="$(message)"/>
    </go>
    </do>
    <anchor>Cancel
    <go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;]; ?>" />
    </anchor>
    <do type="accept" label="Cancel">
    <go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;]; ?>" />
    </do>
    <?php
    }
    }
    else /* email verzenden */
    {
    // check for a recipient
    if ($HTTP_POST_VARS["recipient"] != "")
    {
    // send message
    $rc = false;
    $rc = mail($HTTP_POST_VARS["recipient"]
    , $HTTP_POST_VARS["subject"]
    , $HTTP_POST_VARS["message"]
    , "From: " . $HTTP_POST_VARS["sender"] . "\r\n"
    . "Reply-To: " . $HTTP_POST_VARS["sender"] . "\r\n"
    . "Return-path: " . $HTTP_POST_VARS["sender"] . "\r\n"
    . "X-Mailer: Momail PHP/" . phpversion()
    , "-f " . $HTTP_POST_VARS["sender"]
    );

    // check send process and report back to user
    if ($rc=true)
    {
    echo "Message was succesfully send to " . $HTTP_POST_VARS["recipient"] . "
    \n";
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\">Provider</a>
    \n";
    }
    else
    {
    echo "Message couldn&#39;t be send to " . $HTTP_POST_VARS["recipient"] . "
    \n";
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\">Provider</a>
    \n";
    }
    }
    else
    {
    echo "Without a recipient the message couldn&#39;t be send.
    \n";
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\">Provider</a>
    \n";
    }
    }
    }

    function build_wml()
    {
    // set globals
    global $HTTP_GET_VARS;

    // make dynamic title
    $title = "E-mail";
    if (ISSET($HTTP_GET_VARS["p"]))
    {
    $serv = $HTTP_GET_VARS["p"];
    global $$serv;
    $prov_array = $$serv;
    $title = $prov_array["nickname"];
    }

    // cache-control, wml headers and encoding type
    Header("Content-type: text/vnd.wap.wml");
    Header("Cache-Control: no-store, no-cache, must-revalidate");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?".">\n";
    ?>
    <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.openmobilealliance.org/tech/DTD/wml_1_1.dtd">
    <wml>
    <card newcontext="true" id="main" title="<?php echo $title; ?>">
    <p align="left">
    <?php
    }

    /*
    * Program Flow
    * This is where the different functions are called upon
    */
    if (!function_exists("imap_open"))
    {
    build_wml();
    echo "Message from Momail:

    \r\n"
    . "Momail detected a PHP installation without IMAP.

    \r\n"
    . "You cannot use Momail without that.

    \r\n"
    . "Go to www.php.net/imap if you are looking for technical information about installing the IMAP extension on your server.\r\n";
    echo "</p>";
    echo "</card>";
    echo "</wml>";
    return;
    }

    // redirect users that have only one e-mail account directly to that inbox (don&#39;t display provider list)
    if ($number_of_arrays == 1 && !ISSET($HTTP_GET_VARS["p"])) Header("Location: " . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=serv_1");

    // display provider list or inbox/message
    if(!ISSET($HTTP_GET_VARS["p"]))
    {
    // check to see whether user wants to send an e-mail
    if (ISSET($HTTP_GET_VARS["w"]))
    {
    build_wml();
    send_mail();
    }
    else
    {
    // display provider list
    // when only one provider was specified the user is redirected
    // to the inbox of that provicer by a header above
    build_wml();
    disp_prov();
    echo "
    \n";
    disp_sendmail("new" , 0 , 0);
    }
    }
    else
    {
    // get connection data
    $prov = $$HTTP_GET_VARS["p"];

    // check connection data
    if ($prov["name"] == "" || $prov["password"] == "")
    {
    // start session
    $session_name = preg_replace("/\.|\s/" , "_" , $prov["nickname"]);
    session_name("$session_name");
    session_start();

    // check for user input
    if (count($HTTP_POST_VARS) != 0)
    {
    $prov["name"] = $HTTP_POST_VARS["name"];
    $prov["password"] = $HTTP_POST_VARS["ww"];
    $HTTP_SESSION_VARS["name"] = $prov["name"];
    $HTTP_SESSION_VARS["password"] = $prov["password"];
    }
    elseif ($HTTP_SESSION_VARS["name"] && $HTTP_SESSION_VARS["password"])
    {
    $prov["name"] = $HTTP_SESSION_VARS["name"];
    $prov["password"] = $HTTP_SESSION_VARS["password"];
    }
    else
    {
    build_wml();
    disp_login();
    }
    }

    // create special session urls (if necessary) for the hrefs inside <go /> tags
    // is a bug fix for many wap browser that don&#39;t append this standard to these urls
    $session_urls = NULL;
    if($HTTP_SESSION_VARS)
    {
    $session_urls = array();
    $session_urls["amp"] = "&amp;" . session_name() . "=" . session_id();
    $session_urls["question"] = "?" . session_name() . "=" . session_id();
    }

    // connect to server if required arguments are set
    if ($prov["name"] != "" && $prov["password"] != "")
    {
    // connect to server
    $conn = @imap_open ($prov["server"] , $prov["name"] , $prov["password"]);

    if ($conn)
    {
    // build wml page
    build_wml();

    // delete message from server if $d is set
    if(ISSET($HTTP_GET_VARS["d"]) && $HTTP_SERVER_VARS[&#39;HTTP_REFERER&#39;] = $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;])
    {
    mes_del();
    }
    elseif (ISSET($HTTP_GET_VARS["d"]) && $HTTP_SERVER_VARS[&#39;HTTP_REFERER&#39;] != $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;])
    {
    echo "Error: The page that you are coming from is either "
    . "not visible to Momail (due perhaps to firewall software) "
    . "or not a page generated by Momail. Because this is a "
    . "possible security thread, the message was not deleted.
    \n";
    }

    // check inbox and get number of messages
    $check = imap_check($conn);
    if($check) $Nmsgs = $check -> Nmsgs;

    // check for user input
    if (!ISSET($HTTP_GET_VARS["m"]))
    {
    // display inbox
    disp_inbox();
    }
    else
    {
    if (!ISSET($HTTP_GET_VARS["w"]))
    {
    // display message
    # disp_sendmail("reply" , $HTTP_GET_VARS["p"] , $HTTP_GET_VARS["m"]);
    disp_mes();
    # disp_sendmail("reply" , $HTTP_GET_VARS["p"] , $HTTP_GET_VARS["m"]);
    disp_delmes();
    }
    else
    {
    // reply to message
    send_mail($action , $id);
    }
    }
    }
    else
    {
    // display connection error
    build_wml();
    echo "Connection error
    \n";
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\">Back</a>
    \n";
    echo "<do name=\"back\" type=\"accept\" label=\"Back\"><go href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\" /></do>\n";
    }
    }
    }

    // close pop3_stream
    if ($conn) imap_close($conn);
    ?>
    </p>
    </card>
    </wml></div>

    i tried to configure this variable but gives me connection error..

    here&#39;s the line:
    Code:
     $serv_1 = array(
      "server" => "{natasu.net:110/pop3/notls}Inbox",
      "nickname" => "horde",
      "emailaddress" => "myemail@natasu.net",
      "name" => "myemail",
      "password" => "myemailpassword"
    );

    #2
    someone help me to configure this script..

    <div class='codetop'>CODE
    <div class='codemain' style='height:200px;white-space:pre;overflow:auto'><?php
    /*
    Momail v5 (beta), 22 February 2006

    Copyright © 2004-2006 Maarten Laurs

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details (www.gnu.org).
    So what&#39;s new?

    - Still in beta and therefore disabled by default is the
    possibility to send new emails using Momail. You can enable
    this feature by setting $sendMail = true in the options below.
    At this time you cannot reply to messages, but this will be
    added in later versions.
    - We also have improved the interface. Links to the inbox,
    provider list and so on, are now also available at the
    top of every page.
    Installing Momail : This is what you have do one time only:

    - Copy/paste the entire code
    - Enter the connection data below
    - Give the file a name and a php extension (like .php or .php3)
    (security tip: choose a complex name that no-one will guess)
    - Upload the file to a web server that supports both php and imap
    You can test your web server by running this script: <?php phpinfo(); ?>
    If you can&#39;t find a chapter on IMAP when running this script, chances are it is
    not supported by your webserver and Momail will not work properly and maybe not at all
    - experimental: do not fill in a username or password and use Momail with multiple people
    using the same mail server, but different e-mail accounts. Is not yet available for some
    mobile phones and needs a bit more work.
    Any suggestion or questions are welcome in the forums at
    http://momail.sourceforge.net/forums

    Have fun, Maarten Laurs

    */

    // Number of messages per page (you can change this if you like)
    $num = 9;

    // Maximum message byte size (you can change this if you like)
    // 3600 is best for wap devices with a 5.6k limit (like most popular mobile phones)
    $max_chars = 3600;

    // Enable the Send Mail feature by setting this to true
    $sendMail = false; // can either be true or false

    // connection data //

    /* How to enter the connection data
    Look at the connection arrays below (they are called $serv_#).
    Exchange the information in the arrays so that they reflect your situation.
    "server" should be the path to the mailserver together with some protocol information.
    Examples for the different protocols:
    - imap non-secure: {server:143/imap/notls}Inbox
    - imap secure: {server:993/imap/ssl/novalidate-cert}Inbox
    - pop3 non-secure: {server:110/pop3/notls}Inbox
    - pop3 secure: {server:995/pop3/ssl/novalidate-cert}Inbox
    See http://www.php.net/imap_open for some more examples
    "nickname" is an arbitrary name that you choose to refer to the e-mail provider
    "emailaddress" is your e-mail address that belongs together with the e-mail account
    "name" should reflect the username that you have to use to logon to the mailserver
    "password" comes with the username that was provided to you by the e-mail provider
    If you add or remove an array be sure you number them nicely
    Do not forget to change the $number_of_arrays parameter that is directly below this section
    Be sure to check all the quotation-marks (") and comma&#39;s (,) when you are done or the script will not work
    */

    $number_of_arrays = 3; // this is the number of arrays that are listed below

    $serv_1 = array(
    "server" => "{pop3.server.com:110/pop3/notls}Inbox",
    "nickname" => "nickname provider 1",
    "emailaddress" => "yourname@server.com",
    "name" => "enter username",
    "password" => "enter password"
    );

    $serv_2 = array(
    "server" => "{imap.server.net:993/imap/ssl/novalidate-cert}Inbox",
    "nickname" => "provider two&#39;s nickname",
    "emailaddress" => "you@server.net",
    "name" => "enter username",
    "password" => "enter password"
    );

    $serv_3 = array(
    "server" => "{www.yourdomain.com:110/pop3/notls}Inbox",
    "nickname" => "nickname for a third provider",
    "emailaddress" => "someone@yourdomain.com",
    "name" => "enter username",
    "password" => "enter password"
    );
    // do not forget to change the $number_of_arrays if
    // you add or delete any of the arrays above here!!

    ///////////////////////////////////////////////////////////////////////////
    // that&#39;s it, no more variables to consider beyond this point, have fun! //
    ///////////////////////////////////////////////////////////////////////////

    /************************************************** ******************************
    **\
    * URL variables
    These variables can be expected to travel inside the URL (or URI for that matter)
    c : message offset number when displaying the inbox
    d : parameters for message deletion
    f : message string fetch offset
    m : message number
    p : $serv_# parameter
    w : write message

    * Message functions
    These functions operate on an e-mail message
    - mes_del : delete message
    - mes_incl : include message in a reply
    - mes_prop : retrieve message properties

    * Display functions
    These produce output to the browser
    - disp_prov : e-mail accounts
    - disp_inbox : inbox
    - disp_mes : e-mail message
    - disp_login : login screen
    - disp_sendmail : display links to write e-mail
    - disp_delmes : delete message dialog

    * Other functions
    - send_mail : display send mail interface and send mail handling
    - buidl_wml : build up of wml page
    \************************************************* **************************
    *******/

    // delete message
    function mes_del()
    {
    // set globals
    global $HTTP_GET_VARS, $prov, $conn;

    // get initial message count
    $status_old = imap_status($conn , $prov["server"] , SA_MESSAGES);
    $msg_ini_count = $status_old -> messages;

    // split $d to get msgno and date
    list($del_msgno , $del_date) = split(";" , $HTTP_GET_VARS["d"]);

    // get date of message by msgno, check hash of date against $del_date
    // if the two dates match delete message
    $del_headers = @imap_header($conn , $del_msgno);
    if(md5($del_headers -> date) == $del_date)
    {
    imap_delete($conn , $del_msgno);
    imap_expunge($conn);
    }

    // get final message count
    $status_new = imap_status($conn , $prov["server"] , SA_MESSAGES);
    $msg_final_count = $status_new -> messages;

    // display whether the deletion was succesfull or not
    if($msg_ini_count > $msg_final_count)
    {
    echo "Messagedeleted
    \n";
    }
    else
    {
    echo "Message was not deleted
    \n";
    }

    // reset or unset variables that may have changed
    if($del_msgno == $HTTP_GET_VARS["c"]) $HTTP_GET_VARS["c"] -= 1;
    if($msg_final_count <= 0) unset($HTTP_GET_VARS["c"]);
    }

    // include message
    function mes_incl()
    {
    }

    // retrieve message properties
    function mes_prop($action , $id)
    {
    // set globals
    global $conn;

    // get message headers
    $headers = imap_header($conn , $id);

    // get message structure
    $structure = imap_fetchstructure($conn , $id);

    // what action?
    switch($action)
    {
    // get sender
    case "sender":
    $sender = "";
    $from = $headers -> from;

    if ($from)
    {
    if(!$from[0] -> personal)
    {
    // emailaddress
    $sender = $from[0] -> mailbox . "@" . $from[0] -> host;
    }
    else
    {
    // realname
    $sender = $from[0] -> personal;
    }
    }
    else
    {
    // extract address from unfiltered format header when there is no $from
    $alt_headers = strtolower(imap_fetchheader($conn , $id));
    $return_path = strstr($alt_headers , "return-path");
    $end_pos = strpos($alt_headers , "\r\n" , $return_path);
    $sender = trim(substr($return_path , 12 , $end_pos-13));
    $sender = preg_replace("/<|>/" , "" , $sender);
    }
    return $sender;

    // get date
    case "date":
    $date = "date: not found";
    if($headers -> date)
    {
    $date = $headers -> date;
    }
    else
    {
    $alt_headers = strtolower(imap_fetchheader($conn , $id));
    $date_set = strstr($alt_headers, "delivery-date");
    if($date_set)
    {
    $end_pos = strpos($alt_headers , "\r\n" , $date_set);
    $date = trim(substr($date_set, 15, $end_pos-4));
    $date = ucwords($date);
    }
    }
    return $date;

    // get subject
    case "subject":
    $subject = "No subject";
    if($headers -> subject) $subject = parse_preg($headers -> subject); // function parse_preg() is located elsewhere
    return $subject;

    // get size
    case "size":
    $size = "?";
    if($headers -> Size) $size = round(($headers -> Size / 1024 ), 1);
    return $size;

    // get message body
    case "message":
    $message = "<empty>";
    return $message;

    // get message number
    case "number":
    $message_n = trim($headers -> Msgno);
    return $message_n;

    // get attachment info
    case "attachments":
    $attached = "";
    $attachment_info = "";
    $n_attachments = 0;
    $parts = count($structure -> parts);
    for($i = 0; $i <= $parts; $i++)
    {
    $part = $structure -> parts[$i];
    if($part -> ifdisposition && strtolower($part -> disposition) == "attachment" && $part -> ifdparameters)
    {
    $file = htmlspecialchars($part -> dparameters[0] -> value);
    $size = round($structure -> parts[$i] -> bytes / 1024 , 1);
    $attached .= $file . "(" . $size . "Kb)
    \n";
    $n_attachments += 1;
    }
    }
    if($n_attachments > 0)
    {
    $attachment_info = "
    \nAttachments:
    \n";
    $attachment_info .= $attached . "
    \n";
    }
    return $attachment_info;
    }
    }

    // display e-mail accounts
    function disp_prov()
    {
    // set globals (except $$serv which is set later in this function)
    global $HTTP_SERVER_VARS, $number_of_arrays;

    echo "Select provider
    \n";
    for ($i = 1; $i <= $number_of_arrays; $i++)
    {
    // set provider
    $serv = "serv_" . $i;
    global $$serv;
    $prov_array = $$serv;

    // get number of unseen (imap) / total (pop3) messages on server
    imap_timeout(1,1);
    imap_timeout(2,1);
    $conn = @imap_open ($prov_array["server"] , $prov_array["name"] , $prov_array["password"]);
    $new_messages = "?";
    if ($conn)
    {
    $inbox = imap_status($conn , $prov_array["server"] , SA_UNSEEN);
    if($inbox) $new_messages = $inbox -> unseen;
    }

    // display provider&#39;s nickname and number of new messages
    $nickname = $prov_array["nickname"];
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=" . $serv . "\">" . $nickname . "(" . $new_messages . ")</a>
    \n";
    }
    }

    // display inbox
    function disp_inbox()
    {
    // set globals
    global $HTTP_GET_VARS
    , $HTTP_SERVER_VARS
    , $session_urls
    , $num
    , $conn
    , $number_of_arrays
    ;

    // get number of messages in inbox
    $check = imap_check($conn);
    if($check) $Nmsgs = $check -> Nmsgs;

    // set first and number of messages to be displayed
    if(!ISSET($HTTP_GET_VARS["c"]) || $HTTP_GET_VARS["c"] > $Nmsgs || $HTTP_GET_VARS["c"] < 1) $HTTP_GET_VARS["c"] = $Nmsgs;
    $end = $HTTP_GET_VARS["c"] - $num; // $num is set at the beginning of this script
    if($end < 1) $end = 1;

    // build navigation
    $nav_url = "";
    $nav_frm = "";

    // navigation to previous page
    if ($HTTP_GET_VARS["c"] != $Nmsgs)
    {
    $prev = ($HTTP_GET_VARS["c"] + $num + 1);
    if ($prev > $Nmsgs) $prev = $Nmsgs;
    $href = $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=" . $HTTP_GET_VARS["p"] . "&amp;c=" . $prev;
    $nav_url .= "<a href=\"" . $href . "\">Previous</a>\n";
    $nav_frm .= "<do name=\"previous\" type=\"accept\" label=\"Previous\">\n";
    $nav_frm .= "<go href=\"" . $href . $session_urls["amp"] . "\" />\n";
    $nav_frm .= "</do>\n";
    }

    // navigation to next page
    if($end != 1)
    {
    $next = ($HTTP_GET_VARS["c"] - ($num + 1));
    if ($next < 1) $next = 1;
    $href = $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=" . $HTTP_GET_VARS["p"] . "&amp;c=" . $next;

    $nav_url .= "<a href=\"" . $href . "\">Next</a>\n";
    $nav_frm .= "<do name=\"next\" type=\"accept\" label=\"Next\">\n";
    $nav_frm .= "<go href=\"" . $href . $session_urls["amp"] . "\"/>\n";
    $nav_frm .= "</do>\n";
    }

    // navigation to providers page
    $nav_url .= "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\">Provider</a>\n";
    $nav_frm .= "<do name=\"provider\" type=\"accept\" label=\"Provider\">\n";
    $nav_frm .= "<go href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\" />\n";
    $nav_frm .= "</do>\n";

    if($Nmsgs != 0)
    {
    // display navigation
    echo $nav_url . "
    \n
    \n";

    // display messages
    for ($i = $HTTP_GET_VARS["c"]; $i >= $end; $i--)
    {
    // get message properties
    $sender = mes_prop("sender" , $i);
    $subject = mes_prop("subject" , $i);
    $date = mes_prop("date" , $i);
    $number = mes_prop("number" , $i);
    $size = mes_prop("size" , $i);

    // construct output
    $output = "<a href=\"". $HTTP_SERVER_VARS["PHP_SELF"];
    $output .= "?p=" . $HTTP_GET_VARS["p"] . "&amp;m=" . $number;
    $output .= "&amp;c=" . $HTTP_GET_VARS["c"] . "\">" . $sender . "</a>
    \n";
    $output .= $date . "
    \n";
    $output .= $subject . "(" . $size . "Kb)
    \n
    \n";

    // echo output
    echo $output;
    }

    // display navigation
    echo $nav_url;
    echo $nav_frm;
    }
    else
    {
    // display empty inbox
    echo "Inbox is empty
    \n";
    echo $nav_url;
    echo $nav_frm;
    }
    }

    // display e-mail message
    function disp_mes()
    {
    // set globals
    global $HTTP_GET_VARS, $HTTP_SERVER_VARS, $session_urls, $Nmsgs, $conn, $max_chars;

    // initialize navigation strings
    $nav_url = "";
    $nav_frm = "";

    // output message
    if($HTTP_GET_VARS["m"] <= $Nmsgs && $HTTP_GET_VARS["m"] >= 1)
    {
    // get sender
    $from_var = mes_prop("sender", $HTTP_GET_VARS["m"]);
    $from_var .= " wrote:
    \n";

    // check for multipart message and extract message body
    $structure = imap_fetchstructure($conn , $HTTP_GET_VARS["m"]);
    $part = 1;
    if($structure -> type == 1)
    {
    $part = "1.1";
    if($structure -> parts[0] -> type == 1) $part = "1.1.1";
    }
    if(imap_fetchbody($conn , $HTTP_GET_VARS["m"] , $part) == "") $part = 1;
    $text = imap_fetchbody($conn , $HTTP_GET_VARS["m"] , $part);

    // convert base64 encoded messages
    $base64 = false;
    $headers = strtolower(imap_fetchheader($conn, $HTTP_GET_VARS["m"]));
    if(strstr($headers, "content-transfer-encoding: base64")) $base64 = true;
    if($base64) $text = base64_decode($text);

    // parse preg
    $text = parse_preg($text);

    // truncate message if necessary
    $text_length = strlen($text);
    if($text_length > $max_chars)
    {
    // set length of string to fetch
    if(!ISSET($HTTP_GET_VARS["f"]))
    {
    $HTTP_GET_VARS["f"] = 0;
    }
    $length = $max_chars;
    if(($HTTP_GET_VARS["f"] + $max_chars) > $text_length) $length = ($text_length - $HTTP_GET_VARS["f"]);

    // get part of the message text
    $text = substr($text , $HTTP_GET_VARS["f"] , $length);

    // get position of last "." or
    in message part
    $offset = 0;
    $line_end = ".";
    if(!strpos($text , "." , $offset)) $line_end = "
    ";
    if(strpos($text , $line_end , $offset))
    {
    while(strpos($text , $line_end , $offset))
    {
    $pos = strpos($text , $line_end , $offset);
    $offset = $pos + strlen($line_end);
    }
    }
    else
    {
    // set $offset to $max_char when the $line_end was not found
    $offset = $max_char;
    }

    // get adjusted part of part of message
    $text = substr($text , 0 , $offset);
    }

    // append any useful attachment-info to message string
    $attachments = mes_prop("attachments" , $HTTP_GET_VARS["m"]);
    if($attachments) $text .= $attachments;

    // links to display links to delete message, inbox and provider list
    $href = $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=" . $HTTP_GET_VARS["p"] . "&amp;c=" . $HTTP_GET_VARS["c"];
    $nav_url .= "<a href=\"#del\">Delete</a>\n";
    $nav_frm .= "<do name=\"delete\" type=\"accept\" label=\"Delete\">\n";
    $nav_frm .= "<go href=\"#del\" />\n";
    $nav_frm .= "</do>\n";

    $nav_url .= "<a href=\"" . $href . "\">Inbox</a>\n";
    $nav_frm .= "<do name=\"back\" type=\"accept\" label=\"Inbox\">\n";
    $nav_frm .= "<go href=\"" . $HTTP_SERVER_VARS["PHP_SELF"] . "?p=" . $HTTP_GET_VARS["p"] . "&amp;c=" . $HTTP_GET_VARS["c"] . $session_urls["amp"] . "\" />\n";
    $nav_frm .= "</do>\n";

    $nav_url .= "<a href=\"" . $HTTP_SERVER_VARS["PHP_SELF"] . "\">Provider</a>\n";
    $nav_frm .= "<do name=\"provider\" type=\"accept\" label=\"Provider\">\n";
    $nav_frm .= "<go href=\"" . $HTTP_SERVER_VARS["PHP_SELF"] . "\" />\n";
    $nav_frm .= "</do>\n";

    // build links to next part of messages for message longer than $max_chars
    if(($HTTP_GET_VARS["f"] + $max_chars) < $text_length)
    {
    $offset = $offset + $HTTP_GET_VARS["f"];
    $href = $HTTP_SERVER_VARS["PHP_SELF"]
    . "?p=" . $HTTP_GET_VARS["p"]
    . "&amp;m=" . $HTTP_GET_VARS["m"]
    . "&amp;c=" . $HTTP_GET_VARS["c"]
    . "&amp;f=" . $offset;
    $nav_url .= "<a href=\"$href\">Rest of message</a>\n";
    $nav_frm .= "<do name=\"rest\" type=\"accept\" label=\"Rest message\"><go href=\"$href" . $session_urls["amp"] . "\"/></do>
    \n";
    }

    // preappend sender information
    $text = $from_var . $text;

    // preappend urls
    $text = $nav_url . "
    \n" . $text;

    // display message
    echo utf8_encode($text);

    // append links
    echo $nav_url;
    echo $nav_frm;
    }
    else
    {
    // display error message not on server
    echo "Message is not on server
    \n";
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\">Inbox</a>";
    echo "<do name=\"back\" type=\"accept\" label=\"Inbox\"><go href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . $session_urls["question"];"\"/></do>";
    }
    }

    // display login screen
    function disp_login()
    {
    // set globals
    global $HTTP_GET_VARS, $HTTP_SERVER_VARS, $prov;

    ?>
    Enter login details for <?php echo $prov["nickname"]; ?>

    Username: <input name="name" value="<? if($prov["name"] != "") echo $prov["name"]; ?>"/>

    Password: <input name="ww" type="password" value="<? if($prov["password"] != "") echo $prov["password"]; ?>"/>

    <anchor>Connect
    <go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=" . $HTTP_GET_VARS["p"]; ?>" method="post">
    <postfield name="name" value="$(name)" />
    <postfield name="ww" value="$(ww)" />
    </go>
    </anchor>
    <do type="accept" label="Connect">
    <go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=" . $HTTP_GET_VARS["p"]; ?>" method="post">
    <postfield name="name" value="$(name)" />
    <postfield name="passw" value="$(ww)" />
    </go>
    </do>
    Change provider
    <do name="provider" type="accept" label="Provider"><go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;]; ?>" /></do>
    <?php
    }

    // display link to write new mail
    function disp_sendmail($action , $prov , $id)
    {
    // set globals
    global $HTTP_SERVER_VARS, $sendMail;

    // stop disp_sendmail if sending mail is disabled
    if (!$sendMail) return false;

    // stop disp_sendmail if mail() function is available
    if (!function_exists("mail"))
    {
    echo "Your server doesn&#39;t support sending emails with PHP.";
    return false;
    }

    // create url (action can be &#39;new&#39;, &#39;reply&#39; or &#39;replyall&#39;)
    if ($action == "new")
    {
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?w=" . $action . "\">Write new mail</a>\n";
    }
    else
    {
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?w=" . $action . "&amp;p=" . $prov . "&amp;m=" . $id . "\">Reply</a>\n";
    # Reply to all is not yet implemented
    }
    }

    // display card to delete message
    function disp_delmes()
    {
    // set globals
    global $conn, $HTTP_SERVER_VARS, $HTTP_GET_VARS;

    // display delete message-card
    $del_headers = imap_header($conn , $HTTP_GET_VARS["m"]);

    // hash message date to transfer it succesfully in the query string
    $href_del = $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;]
    . "?p=" . $HTTP_GET_VARS["p"]
    . "&amp;c=" . $HTTP_GET_VARS["c"]
    . "&amp;d=" . $HTTP_GET_VARS["m"]
    . ";" . md5($del_headers -> date);

    ?>
    </p>
    </card>
    <card id="del" title="Delete message">


    Are your sure?

    No

    Yes

    <?php
    }

    /*
    * Parse_preg
    * This function parses a string and converts that
    * string to a character set that is wml compatible
    */
    function parse_preg($text)
    {
    // rid html-only messages of tags and content inside certain tags
    $tags_and_content_to_strip = Array("head" , "title" , "style" , "script");
    foreach ($tags_and_content_to_strip as $tag)
    {
    // this was taken from a message posted anonymously at php.net website and was adapted to fit momail
    $text = preg_replace("/<" . $tag . "(.|\s)*?>(.|\s)*?<\/" . $tag . ">/i" , "" , $text);
    }

    // convert some special characters, like
    and &, to a different character set
    $text = preg_replace("/<br\/?>/i" , "\r\n" , $text);
    $text = preg_replace("//i" , "=20" , $text);
    $text = str_replace("&" , "&amp;" , $text);

    // strip remaining html tags
    $text = strip_tags($text);

    // encode characters like & < > " before adding new ones
    $text = htmlspecialchars($text , ENT_COMPAT , "ISO-8859-1");

    // replace quoted-printable by decimal reference
    $text = preg_replace_callback("/(=)([0-9a-fA-F]{2})/" , "parse_hexdec" , $text); // transform function is written below

    # $text = imap_qprint($text); // is buggie

    // replace dollar sign by ... dollar
    $text = preg_replace_callback("/(\\$)((([0-9])(\\.|,)?){2,})/" , "parse_dollar" , $text); // dollar_transform is written below

    // modify output to comply to xml standard and compact output (rids output of unnecessary
    &#39;s)
    $find = array(
    0 => "/=\r(\n)?/",
    1 => "/\r(\n)?/",
    2 => "/((\s| |)*<br(\s)*\/?>(\r)?(\n)?){3,}/i",
    );
    $replace = array(
    0 => "",
    1 => "
    \r\n",
    2 => "
    \r\n
    \r\n",
    );
    ksort($find);
    ksort($replace);
    $text = preg_replace($find , $replace , $text);

    // quick &#39;n dirty bug fix to &amp;amp;
    $text = str_replace("&amp;amp;" , "&amp;" , $text);

    // return $text
    return $text;
    }

    // additional functions to preg
    function parse_hexdec($matches)
    {
    $hex = $matches[2];
    return "&#" . hexdec($hex) . ";";
    }

    function parse_dollar($matches)
    {
    $amount = $matches[2];
    return $amount . " dollar";
    }
    // end of additional functions

    // send mail
    function send_mail()
    {
    // set globals
    global $HTTP_SERVER_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS, $number_of_arrays;

    // select whether to write or send a message
    if ($HTTP_GET_VARS["w"] != "send")
    {
    // build interface
    if (ISSET($HTTP_GET_VARS["p"]))
    {
    }
    else
    {
    // variable from address
    echo "Sender:<select name=\"sender\">\n";
    for ($i=1; $i <= $number_of_arrays; $i++)
    {
    $serv = "serv_" . $i;
    global $$serv;
    $prov_array = $$serv;
    echo " <option value=\"" . $prov_array["emailaddress"] . "\">" . $prov_array["emailaddress"] . "</option>\n";
    }
    echo "</select>
    \n";
    ?>
    To: <input name="recipient" emptyok="false" value="<? if(ISSET($HTTP_GET_VARS["m"])) echo $HTTP_GET_VARS["r"]; ?>" />

    Subject: <input name="subject" value="<? if(ISSET($HTTP_GET_VARS["s"])) echo "RE:" . $HTTP_GET_VARS["s"]; ?>" />

    <?php
    if ($HTTP_GET_VARS["w"] == "reply")
    {
    ?>
    Include original message? <select name="incl">
    <option value="y">Yes</option>
    <option value="n">No</option>
    </select>

    <?php
    }
    ?>
    Message: <input name="message" value="" />

    <anchor>Send
    <go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;]; ?>?w=send" method="post">
    <postfield name="sender" value="$(sender)"/>
    <postfield name="recipient" value="$(recipient)"/>
    <postfield name="subject" value="$(subject)"/>
    <postfield name="incl" value="$(incl)"/>
    <postfield name="message" value="$(message)"/>
    </go>
    </anchor>
    <do type="accept" label="Send">
    <go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;]; ?>?w=send" method="post">
    <postfield name="sender" value="$(sender)"/>
    <postfield name="recipient" value="$(recipient)"/>
    <postfield name="subject" value="$(subject)"/>
    <postfield name="incl" value="$(incl)"/>
    <postfield name="message" value="$(message)"/>
    </go>
    </do>
    <anchor>Cancel
    <go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;]; ?>" />
    </anchor>
    <do type="accept" label="Cancel">
    <go href="<?php echo $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;]; ?>" />
    </do>
    <?php
    }
    }
    else /* email verzenden */
    {
    // check for a recipient
    if ($HTTP_POST_VARS["recipient"] != "")
    {
    // send message
    $rc = false;
    $rc = mail($HTTP_POST_VARS["recipient"]
    , $HTTP_POST_VARS["subject"]
    , $HTTP_POST_VARS["message"]
    , "From: " . $HTTP_POST_VARS["sender"] . "\r\n"
    . "Reply-To: " . $HTTP_POST_VARS["sender"] . "\r\n"
    . "Return-path: " . $HTTP_POST_VARS["sender"] . "\r\n"
    . "X-Mailer: Momail PHP/" . phpversion()
    , "-f " . $HTTP_POST_VARS["sender"]
    );

    // check send process and report back to user
    if ($rc=true)
    {
    echo "Message was succesfully send to " . $HTTP_POST_VARS["recipient"] . "
    \n";
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\">Provider</a>
    \n";
    }
    else
    {
    echo "Message couldn&#39;t be send to " . $HTTP_POST_VARS["recipient"] . "
    \n";
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\">Provider</a>
    \n";
    }
    }
    else
    {
    echo "Without a recipient the message couldn&#39;t be send.
    \n";
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\">Provider</a>
    \n";
    }
    }
    }

    function build_wml()
    {
    // set globals
    global $HTTP_GET_VARS;

    // make dynamic title
    $title = "E-mail";
    if (ISSET($HTTP_GET_VARS["p"]))
    {
    $serv = $HTTP_GET_VARS["p"];
    global $$serv;
    $prov_array = $$serv;
    $title = $prov_array["nickname"];
    }

    // cache-control, wml headers and encoding type
    Header("Content-type: text/vnd.wap.wml");
    Header("Cache-Control: no-store, no-cache, must-revalidate");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?".">\n";
    ?>
    <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.openmobilealliance.org/tech/DTD/wml_1_1.dtd">
    <wml>
    <card newcontext="true" id="main" title="<?php echo $title; ?>">
    <p align="left">
    <?php
    }

    /*
    * Program Flow
    * This is where the different functions are called upon
    */
    if (!function_exists("imap_open"))
    {
    build_wml();
    echo "Message from Momail:

    \r\n"
    . "Momail detected a PHP installation without IMAP.

    \r\n"
    . "You cannot use Momail without that.

    \r\n"
    . "Go to www.php.net/imap if you are looking for technical information about installing the IMAP extension on your server.\r\n";
    echo "</p>";
    echo "</card>";
    echo "</wml>";
    return;
    }

    // redirect users that have only one e-mail account directly to that inbox (don&#39;t display provider list)
    if ($number_of_arrays == 1 && !ISSET($HTTP_GET_VARS["p"])) Header("Location: " . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "?p=serv_1");

    // display provider list or inbox/message
    if(!ISSET($HTTP_GET_VARS["p"]))
    {
    // check to see whether user wants to send an e-mail
    if (ISSET($HTTP_GET_VARS["w"]))
    {
    build_wml();
    send_mail();
    }
    else
    {
    // display provider list
    // when only one provider was specified the user is redirected
    // to the inbox of that provicer by a header above
    build_wml();
    disp_prov();
    echo "
    \n";
    disp_sendmail("new" , 0 , 0);
    }
    }
    else
    {
    // get connection data
    $prov = $$HTTP_GET_VARS["p"];

    // check connection data
    if ($prov["name"] == "" || $prov["password"] == "")
    {
    // start session
    $session_name = preg_replace("/\.|\s/" , "_" , $prov["nickname"]);
    session_name("$session_name");
    session_start();

    // check for user input
    if (count($HTTP_POST_VARS) != 0)
    {
    $prov["name"] = $HTTP_POST_VARS["name"];
    $prov["password"] = $HTTP_POST_VARS["ww"];
    $HTTP_SESSION_VARS["name"] = $prov["name"];
    $HTTP_SESSION_VARS["password"] = $prov["password"];
    }
    elseif ($HTTP_SESSION_VARS["name"] && $HTTP_SESSION_VARS["password"])
    {
    $prov["name"] = $HTTP_SESSION_VARS["name"];
    $prov["password"] = $HTTP_SESSION_VARS["password"];
    }
    else
    {
    build_wml();
    disp_login();
    }
    }

    // create special session urls (if necessary) for the hrefs inside <go /> tags
    // is a bug fix for many wap browser that don&#39;t append this standard to these urls
    $session_urls = NULL;
    if($HTTP_SESSION_VARS)
    {
    $session_urls = array();
    $session_urls["amp"] = "&amp;" . session_name() . "=" . session_id();
    $session_urls["question"] = "?" . session_name() . "=" . session_id();
    }

    // connect to server if required arguments are set
    if ($prov["name"] != "" && $prov["password"] != "")
    {
    // connect to server
    $conn = @imap_open ($prov["server"] , $prov["name"] , $prov["password"]);

    if ($conn)
    {
    // build wml page
    build_wml();

    // delete message from server if $d is set
    if(ISSET($HTTP_GET_VARS["d"]) && $HTTP_SERVER_VARS[&#39;HTTP_REFERER&#39;] = $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;])
    {
    mes_del();
    }
    elseif (ISSET($HTTP_GET_VARS["d"]) && $HTTP_SERVER_VARS[&#39;HTTP_REFERER&#39;] != $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;])
    {
    echo "Error: The page that you are coming from is either "
    . "not visible to Momail (due perhaps to firewall software) "
    . "or not a page generated by Momail. Because this is a "
    . "possible security thread, the message was not deleted.
    \n";
    }

    // check inbox and get number of messages
    $check = imap_check($conn);
    if($check) $Nmsgs = $check -> Nmsgs;

    // check for user input
    if (!ISSET($HTTP_GET_VARS["m"]))
    {
    // display inbox
    disp_inbox();
    }
    else
    {
    if (!ISSET($HTTP_GET_VARS["w"]))
    {
    // display message
    # disp_sendmail("reply" , $HTTP_GET_VARS["p"] , $HTTP_GET_VARS["m"]);
    disp_mes();
    # disp_sendmail("reply" , $HTTP_GET_VARS["p"] , $HTTP_GET_VARS["m"]);
    disp_delmes();
    }
    else
    {
    // reply to message
    send_mail($action , $id);
    }
    }
    }
    else
    {
    // display connection error
    build_wml();
    echo "Connection error
    \n";
    echo "<a href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\">Back</a>
    \n";
    echo "<do name=\"back\" type=\"accept\" label=\"Back\"><go href=\"" . $HTTP_SERVER_VARS[&#39;PHP_SELF&#39;] . "\" /></do>\n";
    }
    }
    }

    // close pop3_stream
    if ($conn) imap_close($conn);
    ?>
    </p>
    </card>
    </wml></div>

    i tried to configure this variable but gives me connection error..

    here&#39;s the line:
    Code:
     $serv_1 = array(
      "server" => "{natasu.net:110/pop3/notls}Inbox",
      "nickname" => "horde",
      "emailaddress" => "myemail@natasu.net",
      "name" => "myemail",
      "password" => "myemailpassword"
    );
    [/b][/quote]




    Code:
    $serv_1 = array(
      "server" => "{natasu.net:110/pop3/notls}Inbox",
      "nickname" => "horde",
      "emailaddress" => "myemail@natasu.net",
      "name" => "myemail",
      "password" => "myemailpassword",
    );
    try this one just a wild guest :D

    Comment


      #3
      Code:
      $serv_1 = array(
        "server" => "{natasu.net:110/pop3/notls}Inbox",
        "nickname" => "horde",
        "emailaddress" => "myemail@natasu.net",
        "name" => "myemail",
        "password" => "myemailpassword",
      );
      try this one just a wild guest :D[/b]
      try this one if it not working for you just tell me i have 2 more scripts like that Enjoy
      Attached Files
      left wap stuff

      Comment

      Working...
      X