//================= Hercules Script =======================================
//=       _   _                     _
//=      | | | |                   | |
//=      | |_| | ___ _ __ ___ _   _| | ___  ___
//=      |  _  |/ _ \ '__/ __| | | | |/ _ \/ __|
//=      | | | |  __/ | | (__| |_| | |  __/\__ \
//=      \_| |_/\___|_|  \___|\__,_|_|\___||___/
//================= License ===============================================
//= This file is part of Hercules.
//= http://herc.ws - http://github.com/HerculesWS/Hercules
//=
//= Copyright (C) 2012-2015  Hercules Dev Team
//= Copyright (C)  Timexy
//= Copyright (C)  Yor
//= Copyright (C)  Athena
//=
//= Hercules 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 3 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.
//=
//= You should have received a copy of the GNU General Public License
//= along with this program.  If not, see <http://www.gnu.org/licenses/>.
//=========================================================================
//= Forward old mail to Rodex
//================= Description ===========================================
//= Add command to send pending mail to Rodex
//================= Current Version =======================================
//= 1.0
//=========================================================================

-	script	convmail	FAKE_NPC,{
end;
OnConvert:
	query_sql "SELECT `dest_id`, `send_name`, `title`, `message`, `zeny`, `nameid`, `amount`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3` FROM `mail` WHERE nameid > 0 OR zeny > 0", .@dest_id, .@send_name$, .@title$, .@message$, .@zeny, .@nameid, .@amount, .@refine, .@attribute, .@card0, .@card1, .@card2, .@card3;

	// WHERE status=0 ?  Im not sure
	// is 0 = unread
	// 1 = read?
	// how about 2?

	if (getarraysize( .@send_name$ )) {
		for ( .@i = 0; .@i < getarraysize( .@send_name$ ); .@i++ )
				rodex_sendmail2(
				.@dest_id[.@i], .@send_name$[.@i], .@title$[.@i], .@message$[.@i],
				.@zeny[.@i],
				.@nameid[.@i], .@amount[.@i], .@refine[.@i], .@attribute[.@i], .@card0[.@i], .@card1[.@i], .@card2[.@i], .@card3[.@i]
				// What will happened to the unique_id?
			);
		dispbottom getarraysize( .@send_name$ )+" pending mail has been sent to RODEX";
		end;
	}
	dispbottom "No pending mail found in the database";
	end;

OnInit:
	bindatcmd( "mail2rodex","convmail::OnConvert",1,99 );
}