<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: nlmail.php,v 1.15.2.7 2004/08/15 12:57:28 kirilt Exp $



/*************************************************************************/
 #  Mailbox 0.9.2a   by Sivaprasad R.L (http://netlogger.net)              #
 #                                                                        #
 #          --  A pop3 client addon for phpnuked websites --              #
 #                                                                        #
 # 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.                           #
 #                                                                        #
 # You should have received a copy of the GNU General Public License      #
 # along with this program; if not, write to the Free Software            #
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              #
 #                                                                        #
 #             Copyright (C) by Sivaprasad R.L                            #
 #                                                                        #
/*************************************************************************/

if( ! _MPN_USER ) { $_SERVER['F_LIB'] -> redirectRequest( 'user.php' ); exit; }

$index = 2;
$userid =& $GLOBALS['uinf']['uid'];

include "header.php";
include "mailheader.php";
include_once "emailconfig.php";

srand((double) microtime() * 1000000);
$messageid = rand();

$sql = "SELECT * FROM ".$mpnTables['users']." WHERE uid = $userid && uid > 1";

$resultID = mysql_query($sql);

$myrow = mysql_fetch_array($resultID);

$email = $myrow['email'];
$name = $myrow['name'];
$uname = $myrow['uname'];
if ( $name == '' ) { $name = $uname; }

global $contenttype;

// Validate Info

// Check For Empty

$check_ary = array( $_POST['to'], $_POST['subject'], $_POST['message'] );

$verify_check_ary = $_SERVER['SAN'] -> verifyContent( $check_ary, 3 );

if ( in_array( (bool)FALSE, $verify_check_ary ) )
{
    goBack( translate( 'You Failed To Include Required Information' ) );
    exit;
}

// Check Email Addresses

$check_ary = $verify_check_ary = array();
$send_cc = array();
$send_bcc = array();

$send_to = explode( ',' , $_POST['to'] );
$check_ary = array_merge( $check_ary, $send_to );

if ( ! empty( $_POST['cc'] ) )
{
    $send_cc = explode( ',' , $_POST['cc'] );
    $check_ary = array_merge( $check_ary, $send_cc );
}

if ( ! empty( $_POST['bcc'] ) )
{
    $send_bcc = explode( ',' , $_POST['bcc'] );
    $check_ary = array_merge( $check_ary, $send_bcc );
}

if ( count( $check_ary ) > 10 )
{
    goBack( translate( 'You Have Exceeded The Maximum Number Of Mails You Can Send' ) );
    exit;
}

$verify_check_ary = $_SERVER['SAN'] -> verifyContent( $check_ary, 2 );

if ( in_array( (bool)FALSE, $verify_check_ary ) )
{
    goBack( translate( 'Invalid Email Found' ) );
    exit;
}

unset( $check_ary, $verify_check_ary );

require_once './class.phpmailer.php';

$mail = new phpmailer();

/* SET MAIL DELIVERY OPTIONS*/

$mail -> IsHTML( FALSE );

if ( $mailmethod == 0 )
{
    $mail -> IsMail();
}
else
{
    $mail -> IsSMTP();
    $mail -> Host = $smtp;
}


$txtfooter = "\n\n___________________________________________________________________________\n";
$txtfooter .= "$footermsgtxt";

$content = $_POST['message'] . $txtfooter;

$mail -> From = $email;
$mail -> FromName = $name;

foreach( $send_to AS $v )
{
    $mail -> AddAddress( $v );
}

if ( ! empty( $send_cc ) )
{
    foreach( $send_cc AS $v )
    {
        $mail -> AddCC( $v );
    }
}

if ( ! empty( $send_bcc ) )
{
    foreach( $send_bcc AS $v )
    {
        $mail -> AddBCC( $v );
    }
}

$mail -> Priority = $_POST['prior'];
$mail -> Subject = $_POST['subject'];
$mail -> Body = $content;

$allowed_files = array( 'jpg', 'gif', 'txt', 'htm', 'html' );
$attachments = $dir_content = array();

$dir_content = $_SERVER['F_LIB'] -> dirContents( _DP_MAIL_ATTACH, $allowed_files );

if ( is_array( $dir_content ) && sizeof( $dir_content ) > 0 )
{
    foreach( $dir_content AS $key => $v )
    {
        if ( (bool)FALSE !== strpos( $v, $userid ) )
        {
            if ( $key <= 4 )
            {
                $attachments[] = $v;

                $name_start = strpos( $v , '_' ) + 1;
                $name_end   = strrpos( $v , '_' );
                $ext_start  = strpos( $v , '.' );

                $mime_type  =  str_replace( '-', '/', substr( $v, $name_end + 1, ( $ext_start - ( $name_end + 1 ) ) ) );

                $filepath   = _DP_MAIL_ATTACH . $v;
                $filename   = substr( $v,  $name_start, ( $name_end - $name_start ) );
                $fileext    = strchr( $v, '.' );

                if ( isset( $_POST[ $filename ] ) && $_POST[ $filename ] == $key )
                {
                    $mail -> AddAttachment( $filepath, $filename . $fileext, 'base64', $mime_type );
                }
                else
                {
                    @unlink( _DP_MAIL_ATTACH . $v );
                }
            }
            else
            {
                @unlink( _DP_MAIL_ATTACH . $v );
            }
        }
    }

    $sent = $mail -> Send();

    if ( sizeof( $attachments > 0 ) )
    {
        foreach( $attachments AS $v )
        {
            @unlink( $v['path'] );
        }
    }
}
else
{
    $sent = $mail -> Send();
}

if ( ! $sent )
{
    goBack( translate( 'Unable To Send Mail' ) );
    exit;
}
else
{
    $_SERVER['F_LIB'] -> redirectRequest( 'mailbox.php' );
    exit;
}

?>
