' . __('Failed to open the domain CSV file.', 'rl-mailwarmer') . '

'; return; } // Read the headers $headers = fgetcsv($handle); while (($row = fgetcsv($handle)) !== false) { $data = array_combine($headers, $row); if (empty($data['name'])) { continue; // Skip invalid rows } // Create or update the domain post $existing_domain = get_posts([ 'post_type' => 'domain', 'title' => $data['name'], 'posts_per_page' => 1, 'fields' => 'ids', ]); $post_id = $existing_domain[0] ?? null; $post_data = [ 'post_title' => $data['name'], 'post_type' => 'domain', 'post_status' => 'publish', ]; if ($post_id) { $post_data['ID'] = $post_id; } $post_id = wp_insert_post($post_data); if (!is_wp_error($post_id)) { update_post_meta($post_id, 'cloudflare_api_email', sanitize_text_field($data['cloudflare_api_email'])); update_post_meta($post_id, 'cloudflare_api_key', sanitize_text_field($data['cloudflare_api_key'])); log_to_file("rl_mailwarmer_process_domain_csv - Imported domain: " . $data['name']); } else { log_to_file("rl_mailwarmer_process_domain_csv - ERROR importing domain: " . $data['name']); } } fclose($handle); echo '

' . __('Domains imported successfully.', 'rl-mailwarmer') . '

'; } function rl_mailwarmer_process_email_account_csv($file_path) { $handle = fopen($file_path, 'r'); if (!$handle) { echo '

' . __('Failed to open the email account CSV file.', 'rl-mailwarmer') . '

'; return; } // Read the headers $headers = fgetcsv($handle); while (($row = fgetcsv($handle)) !== false) { $data = array_combine($headers, $row); if (empty($data['Email Address']) || empty($data['Password'])) { continue; // Skip invalid rows } if (!empty($data['Name'])) { $name = sanitize_text_field($data['Name']); } if (!empty($data['Signature'])) { $signature = sanitize_textarea_field(wp_slash($data['Signature'])); // log_to_file("rl_mailwarmer_process_email_account_csv - Signature: {$signature}"); } // Match the email account to a domain $domain_name = strtolower(substr(strrchr($data['Email Address'], "@"), 1)); $domain = get_posts([ 'post_type' => 'domain', 'title' => $domain_name, 'post_status' => 'publish', 'posts_per_page' => 1, 'fields' => 'ids', ]); // Match the email provider by name $email_provider = $data['Email Provider']; // Check if this is a scrubber account if (!empty($data['Is Scrubber'])) { $include_in_scrubber_pool = true; } else { $include_in_scrubber_pool = false; } // Create or update the email account post $post_data = [ 'post_title' => strtolower($data['Email Address']), 'post_type' => 'email-account', 'post_status' => 'publish', 'meta_input' => [ 'full_name' => $name, 'mail_password' => sanitize_text_field($data['Password']), 'email_provider' => $email_provider, 'email_signature' => $signature, 'include_in_scrubber_pool' => $include_in_scrubber_pool, ], ]; if (!empty($domain)) { $post_data['meta_input']['domain'] = $domain[0]; } $post_id = wp_insert_post($post_data); if (!is_wp_error($post_id)) { // $email_account_connection_status = RL_MailWarmer_Email_Helper::check_mail_login($post_id); log_to_file("rl_mailwarmer_process_email_account_csv - Imported email {$data['Email Address']}: "); } else { log_to_file("rl_mailwarmer_process_email_account_csv - ERROR importing email: " . $data['Email Address']); } } fclose($handle); echo '

' . __('Email accounts imported successfully.', 'rl-mailwarmer') . '

'; }