<?php

run_query('CREATE TABLE IF NOT EXISTS `' . $config['table_prefix'] . 'mail_archive_on_day` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uid` bigint(20) NOT NULL DEFAULT \'0\',
  `thread_id` int(11) NOT NULL DEFAULT \'0\',
  `add_time` timestamp NOT NULL DEFAULT \'0000-00-00 00:00:00\',
  `user_id` int(11) NOT NULL DEFAULT \'0\',
  `line_id` int(11) NOT NULL DEFAULT \'0\',
  `email` varchar(255) NOT NULL,
  `subject` varchar(255) NOT NULL,
  `body` longtext NOT NULL,
  `from_mail` varchar(255) NOT NULL,
  `from_name` varchar(255) NOT NULL,
  `reply_to` varchar(255) NOT NULL,
  `content_type` varchar(255) NOT NULL,
  `charset` varchar(255) NOT NULL,
  `headers` text NOT NULL,
  `sended_time` timestamp NOT NULL DEFAULT \'0000-00-00 00:00:00\',
  `sended_from` varchar(255) NOT NULL,
  `error_type` tinyint(4) NOT NULL DEFAULT \'0\',
  `error_text` varchar(255) NOT NULL,
  `counter_review` int(11) NOT NULL DEFAULT \'0\',
  PRIMARY KEY (`id`),
  KEY `thread_id` (`thread_id`),
  KEY `user_id` (`user_id`),
  KEY `line_id` (`line_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8');

$result = sql_select_field($config['table_prefix'] . 'cron', 'id', "description = 'Архивация писем'");
if (!sql_num_rows($result)) {
    run_query("INSERT INTO " . $config['table_prefix'] . "cron (description, period, command, thread_name) VALUES ('Архивация писем', '0 0 * * *', 'archive_send_mails();', 'main')");
}