Beispiel #1
0
/**
 * Loads failed emails from the database
 *
 * - If its a message or topic will build the link to that for viewing
 * - If supplied a specific ID will load only that failed email
 *
 * @package Maillist
 * @param int $id
 * @param int $start
 * @param int $chunk_size
 * @param string $sort
 */
function list_maillist_unapproved($id = 0, $start = 0, $chunk_size = 0, $sort = '')
{
    global $txt, $boardurl, $user_info;
    $db = database();
    // Init
    $i = 0;
    $sort = empty($sort) ? 'id_email DESC' : $sort;
    $postemail = array();
    require_once SUBSDIR . '/Emailpost.subs.php';
    // Where can they approve items?
    $approve_boards = !empty($user_info['mod_cache']['ap']) ? $user_info['mod_cache']['ap'] : boardsAllowedTo('approve_posts');
    // Work out the query
    if ($approve_boards == array(0)) {
        $approve_query = '';
    } elseif (!empty($approve_boards)) {
        $approve_query = ' AND e.id_board IN (' . implode(',', $approve_boards) . ')';
    } else {
        $approve_query = ' AND 0';
    }
    if ($id === 0) {
        $where_query = 'id_email > {int:id} AND (({query_see_board}' . $approve_query . ') OR e.id_board = -1)';
    } else {
        $where_query = 'id_email = {int:id} AND (({query_see_board}' . $approve_query . ') OR e.id_board = -1)';
    }
    // Load them errors
    $request = $db->query('', '
		SELECT e.id_email, e.error, e.data_id, e.subject, e.id_message, e.email_from, e.message_type, e.message, e.id_board
		FROM {db_prefix}postby_emails_error e
			LEFT JOIN {db_prefix}boards AS b ON (b.id_board = e.id_board)
		WHERE ' . $where_query . '
		ORDER BY {raw:sort}
		' . (!empty($chunk_size) ? 'LIMIT {int:offset}, {int:limit} ' : 'LIMIT 1'), array('offset' => $start, 'limit' => $chunk_size, 'sort' => $sort, 'id' => $id));
    while ($row = $db->fetch_assoc($request)) {
        $postemail[$i] = array('id_email' => $row['id_email'], 'error' => $txt[$row['error'] . '_short'], 'error_code' => $row['error'], 'key' => $row['data_id'], 'subject' => $row['subject'], 'message' => $row['id_message'], 'from' => $row['email_from'], 'type' => $row['message_type'], 'body' => $row['message'], 'link' => '#');
        // Sender details we can use
        $temp = query_load_user_info($row['email_from']);
        $postemail[$i]['name'] = !empty($temp['user_info']['name']) ? $temp['user_info']['name'] : '';
        $postemail[$i]['language'] = !empty($temp['user_info']['language']) ? $temp['user_info']['language'] : '';
        // Build a link to the topic or message in case someone wants to take a look at that thread
        if ($row['message_type'] === 't') {
            $postemail[$i]['link'] = $boardurl . '?topic=' . $row['id_message'];
        } elseif ($row['message_type'] === 'm') {
            $postemail[$i]['link'] = $boardurl . '?msg=' . $row['id_message'];
        } elseif ($row['message_type'] === 'p') {
            $postemail[$i]['subject'] = $txt['private'];
        }
        $i++;
    }
    $db->free_result($request);
    return $postemail;
}
 /**
  * New Topic posting controller, reads, parses, checks and posts a new topic
  *
  * What it does:
  * - New topics do not have security keys in them so they are subject to spoofing
  * - It must be from the email of a registered user
  * - It must have been sent to an email ID that has been set to post new topics
  * - Accessed through emailtopic.
  *
  * @param string|null $data used to supply a full body+headers email
  */
 public function action_pbe_topic($data = null)
 {
     global $modSettings, $user_info, $maintenance;
     // The function is not even on ...
     if (empty($modSettings['maillist_enabled'])) {
         return;
     }
     // Our mail parser and our main subs
     require_once SUBSDIR . '/EmailParse.class.php';
     require_once SUBSDIR . '/Emailpost.subs.php';
     // Init
     loadLanguage('Maillist');
     setMemoryLimit('256M');
     // Get the data from one of our sources
     $email_message = new Email_Parse();
     $email_message->read_data($data, BOARDDIR);
     if (!$email_message->raw_message) {
         return false;
     }
     // Parse the header and some needed details
     $email_message->read_email(true, $email_message->raw_message);
     $email_message->load_address();
     // No key for this, so set some blanks for the error function (if needed)
     $email_message->message_type = 'x';
     $email_message->message_key_id = '';
     $email_message->message_id = 0;
     // If the feature is on but the post/pm function is not enabled, just log the message.
     if (empty($modSettings['pbe_post_enabled'])) {
         return pbe_emailError('error_email_notenabled', $email_message);
     }
     // Load the user from the database based on the sending email address
     $email_message->email['from'] = !empty($email_message->email['from']) ? strtolower($email_message->email['from']) : '';
     $pbe = query_load_user_info($email_message->email['from']);
     // Can't find this email as one of our users?
     if (empty($pbe)) {
         return pbe_emailError('error_not_find_member', $email_message);
     }
     // Getting hammy with it?
     if ($email_message->load_spam()) {
         return pbe_emailError('error_found_spam', $email_message);
     }
     // The board that this email address corresponds to
     $board_number = pbe_find_board_number($email_message);
     if (empty($board_number)) {
         return pbe_emailError('error_not_find_board', $email_message);
     }
     // In maintenance mode so just save it for the moderators to deal with
     if (!empty($maintenance) && $maintenance !== 2 && !$pbe['user_info']['is_admin'] && !$user_info['is_admin']) {
         return pbe_emailError('error_in_maintenance_mode', $email_message);
     }
     // Any additional spam / security checking
     call_integration_hook('integrate_mailist_checks_before', array($email_message, $pbe));
     // To post a NEW topic, we need some board details for where it goes
     $board_info = query_load_board_details($board_number, $pbe);
     if (empty($board_info)) {
         return pbe_emailError('error_board_gone', $email_message);
     }
     // Load up this users permissions for that board
     query_load_permissions('board', $pbe, $board_info);
     // Account for any moderation they may be under
     pbe_check_moderation($pbe);
     // Create the topic, send notifications
     return pbe_create_topic($pbe, $email_message, $board_info);
 }