Skip to content

Commit

Permalink
Added option to use reply-to header for replies
Browse files Browse the repository at this point in the history
  • Loading branch information
willbrowningme committed Feb 24, 2021
1 parent 9a83bf7 commit 6920570
Show file tree
Hide file tree
Showing 13 changed files with 993 additions and 646 deletions.
19 changes: 19 additions & 0 deletions app/Http/Controllers/UseReplyToController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\UpdateUseReplyToRequest;

class UseReplyToController extends Controller
{
public function update(UpdateUseReplyToRequest $request)
{
if ($request->use_reply_to) {
user()->update(['use_reply_to' => true]);
} else {
user()->update(['use_reply_to' => false]);
}

return back()->with(['status' => $request->use_reply_to ? 'Use Reply To Enabled Successfully' : 'Use Reply To Disabled Successfully']);
}
}
30 changes: 30 additions & 0 deletions app/Http/Requests/UpdateUseReplyToRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateUseReplyToRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'use_reply_to' => 'required|boolean'
];
}
}
15 changes: 11 additions & 4 deletions app/Mail/ForwardEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ public function __construct(Alias $alias, EmailData $emailData, Recipient $recip
*/
public function build()
{
$this->fromEmail = $this->alias->local_part . '+' . Str::replaceLast('@', '=', $this->replyToAddress) . '@' . $this->alias->domain;
// Check if the user is using the old reply-to and from headers
if ($this->user->use_reply_to) {
$this->fromEmail = $this->alias->email;

$replyToEmail = $this->alias->local_part . '+' . Str::replaceLast('@', '=', $this->replyToAddress) . '@' . $this->alias->domain;
} else {
$this->fromEmail = $this->alias->local_part . '+' . Str::replaceLast('@', '=', $this->replyToAddress) . '@' . $this->alias->domain;
}

$returnPath = $this->alias->email;

Expand All @@ -106,13 +113,13 @@ public function build()
$this->dkimSigner->ignoreHeader('Return-Path');
}
} else {
$replyToEmail = $this->fromEmail;
if (! isset($replyToEmail)) {
$replyToEmail = $this->fromEmail;
}

$this->fromEmail = config('mail.from.address');
$returnPath = config('anonaddy.return_path');
}
} else {
$returnPath = 'mailer@'.$this->alias->parentDomain();
}

$this->email = $this
Expand Down
6 changes: 5 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class User extends Authenticatable implements MustVerifyEmail
'banner_location',
'catch_all',
'bandwidth',
'default_alias_domain',
'default_alias_format',
'use_reply_to',
'default_recipient_id',
'password',
'two_factor_enabled',
Expand Down Expand Up @@ -67,7 +70,8 @@ class User extends Authenticatable implements MustVerifyEmail
'id' => 'string',
'default_recipient_id' => 'string',
'catch_all' => 'boolean',
'two_factor_enabled' => 'boolean'
'two_factor_enabled' => 'boolean',
'use_reply_to' => 'boolean'
];

protected $dates = [
Expand Down
Loading

0 comments on commit 6920570

Please sign in to comment.