<commit_before><?php
/**
 * Invoice_Method_Mail class
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

class Invoice_Method_Mail extends Invoice_Method {

	/**
	 * Remind
	 *
	 * @access public
	 * @param Customer_Contact $customer_contact
	 */
	public function remind(Customer_Contact $customer_contact) {
		$email = new Email('invoice_reminder', $customer_contact->language);
		$email->add_to($customer_contact->email, $customer_contact->firstname . ' ' . $customer_contact->lastname);
		$email->set_sender(Setting::get('email'), Setting::get('company'));

		$invoices = $customer_contact->get_expired_invoices();
		$email->assign('invoices', $invoices);
		$email->assign('customer_contact', $customer_contact);
		foreach ($invoices as $invoice) {
			$email->add_attachment($invoice->get_pdf());
			Log::create('Sending reminder to ' . $customer_contact->firstname . ' ' . $customer_contact->lastname . ' (' . $customer_contact->email . ')', $invoice);
		}
		$email->send();
	}

	/**
	 * Send the invoice via email
	 *
	 * @access public
	 * @param Invoice $invoice
	 */
	public function send(Invoice $invoice) {
		$mail = new Email('invoice', $invoice->customer_contact->language);
		if ($invoice->customer_contact->email != '') {
			$mail->add_to($invoice->customer_contact->email, $invoice->customer_contact->firstname . ' ' . $invoice->customer_contact->lastname);
		}
		if ($invoice->customer_contact->email == '' and $invoice->customer->email != '') {
			$mail->add_to($invoice->customer->email, $invoice->customer->firstname . ' ' . $invoice->customer->lastname);
		}
		if ($invoice->customer_contact->email != $invoice->customer->email AND $invoice->customer->email != '') {
			$mail->add_cc($invoice->customer->email, $invoice->customer->firstname . ' ' . $invoice->customer->lastname);
		}

		try {
			$email_from = Setting::get_by_name('email')->value;
			$company = Setting::get_by_name('company')->value;
			$mail->set_sender($email_from, $company);
		} catch (Exception $e) {
		}

		$mail->add_attachment($invoice->get_pdf());
		$mail->assign('invoice', $invoice);

		try {
			$mail->send();
		} catch (Exception $e) {
			throw new \Exception('Mail could not be sent. Error: ' . $e->getMessage());
		}
		Log::create('Invoice sent via email', $invoice);
	}
}
<commit_msg>only log reminder mail if sending succeeded<commit_after><?php
/**
 * Invoice_Method_Mail class
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

class Invoice_Method_Mail extends Invoice_Method {

	/**
	 * Remind
	 *
	 * @access public
	 * @param Customer_Contact $customer_contact
	 */
	public function remind(Customer_Contact $customer_contact) {
		$email = new Email('invoice_reminder', $customer_contact->language);
		$email->add_to($customer_contact->email, $customer_contact->firstname . ' ' . $customer_contact->lastname);
		$email->set_sender(Setting::get('email'), Setting::get('company'));

		$invoices = $customer_contact->get_expired_invoices();
		$email->assign('invoices', $invoices);
		$email->assign('customer_contact', $customer_contact);
		foreach ($invoices as $invoice) {
			$email->add_attachment($invoice->get_pdf());
		}
		$email->send();

		foreach ($invoices as $invoice) {
			Log::create('Sending reminder to ' . $customer_contact->firstname . ' ' . $customer_contact->lastname . ' (' . $customer_contact->email . ')', $invoice);
		}
	}

	/**
	 * Send the invoice via email
	 *
	 * @access public
	 * @param Invoice $invoice
	 */
	public function send(Invoice $invoice) {
		$mail = new Email('invoice', $invoice->customer_contact->language);
		if ($invoice->customer_contact->email != '') {
			$mail->add_to($invoice->customer_contact->email, $invoice->customer_contact->firstname . ' ' . $invoice->customer_contact->lastname);
		}
		if ($invoice->customer_contact->email == '' and $invoice->customer->email != '') {
			$mail->add_to($invoice->customer->email, $invoice->customer->firstname . ' ' . $invoice->customer->lastname);
		}
		if ($invoice->customer_contact->email != $invoice->customer->email AND $invoice->customer->email != '') {
			$mail->add_cc($invoice->customer->email, $invoice->customer->firstname . ' ' . $invoice->customer->lastname);
		}

		try {
			$email_from = Setting::get_by_name('email')->value;
			$company = Setting::get_by_name('company')->value;
			$mail->set_sender($email_from, $company);
		} catch (Exception $e) {
		}

		$mail->add_attachment($invoice->get_pdf());
		$mail->assign('invoice', $invoice);

		try {
			$mail->send();
		} catch (Exception $e) {
			throw new \Exception('Mail could not be sent. Error: ' . $e->getMessage());
		}
		Log::create('Invoice sent via email', $invoice);
	}
}

{'fraction_non_alphanumeric': 0.19088380055638776, 'fraction_numerical': 0.0, 'mean_word_length': 4.658595641646489, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 131, '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': '5980965', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1514, 'n_words': 252}