<commit_before><?php
namespace wcf\system\background\job;
use wcf\system\email\transport\exception\PermanentFailure;
use wcf\system\email\Email;
use wcf\system\email\Mailbox;

/**
 * Delivers the given email to the given mailbox.
 * 
 * @author	<NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Background\Job
 * @since	3.0
 */
class EmailDeliveryBackgroundJob extends AbstractBackgroundJob {
	/**
	 * @inheritDoc
	 */
	const MAX_FAILURES = 24;
	
	/**
	 * email to send
	 * @var	Email
	 */
	protected $email;
	
	/**
	 * sender mailbox
	 * @var	Mailbox
	 */
	protected $envelopeFrom;
	
	/**
	 * recipient mailbox
	 * @var	Mailbox
	 */
	protected $envelopeTo;
	
	/**
	 * instance of the default transport
	 * @var	\wcf\system\email\transport\IEmailTransport
	 */
	protected static $transport = null;
	
	/**
	 * Creates the job using the given the email and the destination mailbox.
	 * 
	 * @param	Email		$email
	 * @param	Mailbox		$envelopeFrom
	 * @param	Mailbox		$envelopeTo
	 * @see		\wcf\system\email\transport\IEmailTransport
	 */
	public function __construct(Email $email, Mailbox $envelopeFrom, Mailbox $envelopeTo) {
		$this->email = $email;
		$this->envelopeFrom = $envelopeFrom;
		$this->envelopeTo = $envelopeTo;
	}
	
	/**
	 * Emails will be sent with an increasing timeout between the tries.
	 * 
	 * @return	int	between 15 minutes and 24 hours
	 */
	public function retryAfter() {
		$lookup = [
			1 => 15,
			2 => 45,     // running total:
			3 => 1 * 60, // 2 hours
			4 => 2 * 60, // 4 hours
			5 => 4 * 60, // 8 hours
			6 => 4 * 60, // 12 hours
			7 => 6 * 60, // 18 hours
			8 => 6 * 60, // 24 hours
			9 => 6 * 60, // 30 hours
			10 => 6 * 60, // 36 hours
			11 => 6 * 60, // 42 hours
			11 => 6 * 60, // 48 hours
			12 => 12 * 60, // 60 hours
			13 => 12 * 60, // 72 hours
			14 => 24 * 60, // 4 days
			15 => 24 * 60, // 5 days
			16 => 24 * 60, // 6 days
			17 => 24 * 60, // 7 days
			18 => 24 * 60, // 8 days
			19 => 24 * 60, // 9 days
			20 => 24 * 60, // 10 days
			21 => 24 * 60, // 11 days
			22 => 24 * 60, // 12 days
			23 => 24 * 60, // 13 days
			24 => 24 * 60, // 14 days
		];
		
		$result = 24 * 60;
		if (isset($lookup[$this->getFailures()])) {
			$result = $lookup[$this->getFailures()];
		}
		
		return $result * 60;
	}
	
	/**
	 * @inheritDoc
	 */
	public function perform() {
		if (self::$transport === null) {
			$name = '\wcf\system\email\transport\\'.ucfirst(MAIL_SEND_METHOD).'EmailTransport';
			self::$transport = new $name();
		}
		
		try {
			self::$transport->deliver($this->email, $this->envelopeFrom, $this->envelopeTo);
		}
		catch (PermanentFailure $e) {
			// no need for retrying. Eat Exception and log the error.
			\wcf\functions\exception\logThrowable($e);
		}
	}<commit_msg>Fix retryAfter for EmailDeliveryBackgroundJob<commit_after><?php
namespace wcf\system\background\job;
use wcf\system\email\transport\exception\PermanentFailure;
use wcf\system\email\Email;
use wcf\system\email\Mailbox;

/**
 * Delivers the given email to the given mailbox.
 * 
 * @author	<NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Background\Job
 * @since	3.0
 */
class EmailDeliveryBackgroundJob extends AbstractBackgroundJob {
	/**
	 * @inheritDoc
	 */
	const MAX_FAILURES = 25;
	
	/**
	 * email to send
	 * @var	Email
	 */
	protected $email;
	
	/**
	 * sender mailbox
	 * @var	Mailbox
	 */
	protected $envelopeFrom;
	
	/**
	 * recipient mailbox
	 * @var	Mailbox
	 */
	protected $envelopeTo;
	
	/**
	 * instance of the default transport
	 * @var	\wcf\system\email\transport\IEmailTransport
	 */
	protected static $transport = null;
	
	/**
	 * Creates the job using the given the email and the destination mailbox.
	 * 
	 * @param	Email		$email
	 * @param	Mailbox		$envelopeFrom
	 * @param	Mailbox		$envelopeTo
	 * @see		\wcf\system\email\transport\IEmailTransport
	 */
	public function __construct(Email $email, Mailbox $envelopeFrom, Mailbox $envelopeTo) {
		$this->email = $email;
		$this->envelopeFrom = $envelopeFrom;
		$this->envelopeTo = $envelopeTo;
	}
	
	/**
	 * Emails will be sent with an increasing timeout between the tries.
	 * 
	 * @return	int	between 15 minutes and 24 hours
	 */
	public function retryAfter() {
		$lookup = [
			1 => 15,
			2 => 45,     // running total:
			3 => 1 * 60, // 2 hours
			4 => 2 * 60, // 4 hours
			5 => 4 * 60, // 8 hours
			6 => 4 * 60, // 12 hours
			7 => 6 * 60, // 18 hours
			8 => 6 * 60, // 24 hours
			9 => 6 * 60, // 30 hours
			10 => 6 * 60, // 36 hours
			11 => 6 * 60, // 42 hours
			12 => 6 * 60, // 48 hours
			13 => 12 * 60, // 60 hours
			14 => 12 * 60, // 72 hours
			15 => 24 * 60, // 4 days
			16 => 24 * 60, // 5 days
			17 => 24 * 60, // 6 days
			18 => 24 * 60, // 7 days
			19 => 24 * 60, // 8 days
			20 => 24 * 60, // 9 days
			21 => 24 * 60, // 10 days
			22 => 24 * 60, // 11 days
			23 => 24 * 60, // 12 days
			24 => 24 * 60, // 13 days
			25 => 24 * 60, // 14 days
		];
		
		$result = 24 * 60;
		if (isset($lookup[$this->getFailures()])) {
			$result = $lookup[$this->getFailures()];
		}
		
		return $result * 60;
	}
	
	/**
	 * @inheritDoc
	 */
	public function perform() {
		if (self::$transport === null) {
			$name = '\wcf\system\email\transport\\'.ucfirst(MAIL_SEND_METHOD).'EmailTransport';
			self::$transport = new $name();
		}
		
		try {
			self::$transport->deliver($this->email, $this->envelopeFrom, $this->envelopeTo);
		}
		catch (PermanentFailure $e) {
			// no need for retrying. Eat Exception and log the error.
			\wcf\functions\exception\logThrowable($e);
		}
	}
{'fraction_non_alphanumeric': 0.15582608695652173, 'fraction_numerical': 0.06469565217391304, 'mean_word_length': 2.5456226880394577, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5455759', 'n_tokens_mistral': 2539, 'n_tokens_neox': 1957, 'n_words': 589}