diff --git a/app/ActivityLog.php b/app/ActivityLog.php index 34463a2d..01484c11 100644 --- a/app/ActivityLog.php +++ b/app/ActivityLog.php @@ -22,6 +22,7 @@ class ActivityLog extends Activity const DESCRIPTION_EMAILS_SENDING_ERROR_TO_USER = 'error_sending_email_to_user'; const DESCRIPTION_EMAILS_SENDING_ERROR_INVITE = 'error_sending_invite_to_user'; const DESCRIPTION_EMAILS_SENDING_ERROR_PASSWORD_CHANGED = 'error_sending_password_changed'; + const DESCRIPTION_EMAILS_SENDING_WRONG_EMAIL = 'error_sending_wrong_email'; const DESCRIPTION_EMAILS_FETCHING_ERROR = 'error_fetching_email'; const DESCRIPTION_SYSTEM_ERROR = 'system_error'; const DESCRIPTION_USER_DELETED = 'user_deleted'; @@ -49,6 +50,8 @@ class ActivityLog extends Activity return __('Error sending invitation email to user'); case self::DESCRIPTION_EMAILS_SENDING_ERROR_PASSWORD_CHANGED: return __('Error sending password changed notification to user'); + case self::DESCRIPTION_EMAILS_SENDING_WRONG_EMAIL: + return __('Error sending email to the user who replied to notiication from wrong email'); case self::DESCRIPTION_EMAILS_FETCHING_ERROR: return __('Error fetching email'); case self::DESCRIPTION_SYSTEM_ERROR: diff --git a/app/Console/Commands/FetchEmails.php b/app/Console/Commands/FetchEmails.php index 82634af7..19e76e6e 100644 --- a/app/Console/Commands/FetchEmails.php +++ b/app/Console/Commands/FetchEmails.php @@ -323,10 +323,10 @@ class FetchEmails extends Command if (Email::sanitizeEmail($user->email) != Email::sanitizeEmail($from)) { $this->logError("From address {$from} is not the same as user {$user->id} email: ".$user->email); $message->setFlag(['Seen']); - // todo: send email with information - // Unable to process your update - // Your email update couldn't be processed - // If you are trying to update a conversation, remember you must respond from the same email address that's on your account. To send your update, please try again and send from your account email address (the email you login with). + + // Send "Unable to process your update email" to user + \App\Jobs\SendEmailReplyError::dispatch($from, $user, $mailbox)->onQueue('emails'); + continue; } diff --git a/app/Jobs/SendEmailReplyError.php b/app/Jobs/SendEmailReplyError.php new file mode 100644 index 00000000..71236edf --- /dev/null +++ b/app/Jobs/SendEmailReplyError.php @@ -0,0 +1,87 @@ +from = $from; + $this->user = $user; + $this->mailbox = $mailbox; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + // Configure mail driver according to Mailbox settings + \App\Misc\Mail::setMailDriver($this->mailbox); + + $exception = null; + try { + Mail::to([['name' => '', 'email' => $this->from]]) + ->send(new UserEmailReplyError()); + } catch (\Exception $e) { + // We come here in case SMTP server unavailable for example + activity() + ->withProperties([ + 'error' => $e->getMessage().'; File: '.$e->getFile().' ('.$e->getLine().')', + ]) + ->useLog(\App\ActivityLog::NAME_EMAILS_SENDING) + ->log(\App\ActivityLog::DESCRIPTION_EMAILS_SENDING_WRONG_EMAIL); + + $exception = $e; + } + + $status_message = ''; + if ($exception) { + $status = SendLog::STATUS_SEND_ERROR; + $status_message = $exception->getMessage(); + } else { + $failures = Mail::failures(); + + // Save to send log + if (!empty($failures)) { + $status = SendLog::STATUS_SEND_ERROR; + } else { + $status = SendLog::STATUS_ACCEPTED; + } + } + + SendLog::log(null, null, $this->from, SendLog::MAIL_TYPE_WRONG_USER_EMAIL_MESSAGE, $status, null, $this->user->id, $status_message); + + if ($exception) { + throw $exception; + } + } +} diff --git a/app/Mail/AutoReply.php b/app/Mail/AutoReply.php index 2f52a7c9..cf4df50d 100644 --- a/app/Mail/AutoReply.php +++ b/app/Mail/AutoReply.php @@ -10,8 +10,6 @@ use Illuminate\Queue\SerializesModels; class AutoReply extends Mailable { - use Queueable, SerializesModels; - /** * Conversation created by customer. * diff --git a/app/Mail/PasswordChanged.php b/app/Mail/PasswordChanged.php index 9bf0e0a9..e453e44a 100644 --- a/app/Mail/PasswordChanged.php +++ b/app/Mail/PasswordChanged.php @@ -11,8 +11,6 @@ use Illuminate\Queue\SerializesModels; class PasswordChanged extends Mailable { - use Queueable, SerializesModels; - /** * User to whom email is sent. */ diff --git a/app/Mail/ReplyToCustomer.php b/app/Mail/ReplyToCustomer.php index f5580715..7d882d5f 100644 --- a/app/Mail/ReplyToCustomer.php +++ b/app/Mail/ReplyToCustomer.php @@ -12,8 +12,6 @@ use Illuminate\Queue\SerializesModels; //abstract class AbstractMessage extends Mailable class ReplyToCustomer extends Mailable { - use Queueable, SerializesModels; - /** * Conversation to send. * diff --git a/app/Mail/Test.php b/app/Mail/Test.php index 1c8d6b59..efa26b16 100644 --- a/app/Mail/Test.php +++ b/app/Mail/Test.php @@ -8,7 +8,6 @@ use Illuminate\Mail\Mailable; class Test extends Mailable { - public $mailbox; /** diff --git a/app/Mail/UserEmailReplyError.php b/app/Mail/UserEmailReplyError.php new file mode 100644 index 00000000..9e61478b --- /dev/null +++ b/app/Mail/UserEmailReplyError.php @@ -0,0 +1,33 @@ +subject(__('Unable to process your update')) + ->view('emails/user/email_reply_error'); + } +} diff --git a/app/Mail/UserInvite.php b/app/Mail/UserInvite.php index 58d55cf5..0db4e0c2 100644 --- a/app/Mail/UserInvite.php +++ b/app/Mail/UserInvite.php @@ -11,8 +11,6 @@ use Illuminate\Queue\SerializesModels; class UserInvite extends Mailable { - use Queueable, SerializesModels; - /** * User to whom invitation is sent. */ diff --git a/app/Mail/UserNotification.php b/app/Mail/UserNotification.php index d86abe22..4571d110 100644 --- a/app/Mail/UserNotification.php +++ b/app/Mail/UserNotification.php @@ -8,8 +8,6 @@ use Illuminate\Queue\SerializesModels; class UserNotification extends Mailable { - use Queueable, SerializesModels; - /** * Recipient. * diff --git a/app/Thread.php b/app/Thread.php index 08cce466..f3870ede 100644 --- a/app/Thread.php +++ b/app/Thread.php @@ -397,35 +397,30 @@ class Thread extends Model } /** - * Get text for the assignee. + * Get text for the assignee in line item. * * @return string */ - public function getAssigneeName($ucfirst = false, $user = null, $self = true) + public function getAssigneeName($ucfirst = false, $by_user = null) { + if (!$by_user) { + $by_user = auth()->user(); + } if (!$this->user_id) { if ($ucfirst) { return __('Anyone'); } else { return __('anyone'); } - } elseif (($user && $this->user_id == $user->id) || (!$user && auth()->user() && $this->user_id == auth()->user()->id)) { - - // Not using mb_ucfirst to avoid possible problems with encoding - if ($ucfirst) { - if ($self) { - $name = __('Yourself'); - } else { - $name = __('You'); - } + } elseif ($by_user && $this->user_id == $by_user->id) { + if ($this->created_by_user_id && $this->created_by_user_id == $this->user_id) { + $name = __('yourself'); } else { - if ($self) { - $name = __('yourself'); - } else { - $name = __('you'); - } + $name = __('you'); + } + if ($ucfirst) { + $name = ucfirst($name); } - return $name; } else { // User may be deleted @@ -500,7 +495,7 @@ class Thread extends Model if ($this->action_type == Thread::ACTION_TYPE_STATUS_CHANGED) { $did_this = __("marked as :status_name conversation #:conversation_number", ['status_name' => $this->getStatusName(), 'conversation_number' => $conversation_number]); } elseif ($this->action_type == Thread::ACTION_TYPE_USER_CHANGED) { - $did_this = __("assigned :assignee convsersation #:conversation_number", ['assignee' => $this->getAssigneeName(false, null, false), 'conversation_number' => $conversation_number]); + $did_this = __("assigned :assignee convsersation #:conversation_number", ['assignee' => $this->getAssigneeName(false, null), 'conversation_number' => $conversation_number]); } elseif ($this->action_type == Thread::ACTION_TYPE_CUSTOMER_CHANGED) { $did_this = __("changed the customer to :customer in conversation #:conversation_number", ['customer' => $this->customer->getFullName(true), 'conversation_number' => $conversation_number]); } diff --git a/resources/views/emails/user/email_reply_error.blade.php b/resources/views/emails/user/email_reply_error.blade.php new file mode 100644 index 00000000..64e92bcb --- /dev/null +++ b/resources/views/emails/user/email_reply_error.blade.php @@ -0,0 +1,8 @@ +@extends('emails/user/layouts/system') + +@section('content') +
{{ __("Your email update couldn't be processed") }}
+

+ {{ __("If you are trying to update a conversation, remember you must respond from the same email address that's on your account. To send your update, please try again and send from your account email address (the email you login with).") }} +

+@endsection \ No newline at end of file diff --git a/resources/views/emails/user/thread_by.blade.php b/resources/views/emails/user/thread_by.blade.php index 098f6cd4..5b9c2ef6 100644 --- a/resources/views/emails/user/thread_by.blade.php +++ b/resources/views/emails/user/thread_by.blade.php @@ -1 +1 @@ -@if ($thread->created_by_user->id == $user->id){{ __("you") }}@else{{ $thread->created_by_user->getFullName(true) }}@endif \ No newline at end of file +@if ($thread->created_by_user_id == $user->id){{ __("you") }}@else{{ $thread->created_by_user->getFullName(true) }}@endif \ No newline at end of file