diff --git a/.travis.yml b/.travis.yml index bcf3576..096fb46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,6 @@ before_install: - echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - cp ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ~/xdebug.ini - phpenv config-rm xdebug.ini - - composer global require hirak/prestissimo --update-no-dev - composer require "laravel/framework:${LARAVEL_VERSION}" --no-update --prefer-dist - composer require "orchestra/testbench:${TESTBENCH}" --no-update --prefer-dist diff --git a/README.md b/README.md index 9aba9fa..c0a6cd5 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ Once installed, all outgoing mail will be logged to the database. The following - **admin-route**: The route information for the admin. Set the prefix and middleware. - **admin-template**: The params for the Admin Panel and Views. You can integrate your existing Admin Panel with the MailTracker admin panel. - **date-format**: You can define the format to show dates in the Admin Panel. +- **content-max-size**: You can overwrite default maximum length limit for `content` database field. Do not forget update it's type from `text` if make it longer. If you do not wish to have an email tracked, then you can add the `X-No-Track` header to your message. Put any random string into this header to prevent the tracking from occurring. The header will be removed from the email prior to being sent. diff --git a/config/mail-tracker.php b/config/mail-tracker.php index 365ad86..523739b 100644 --- a/config/mail-tracker.php +++ b/config/mail-tracker.php @@ -78,4 +78,8 @@ */ 'tracker-queue' => null, + /** + * Size limit for content length stored in database + */ + 'content-max-size' => 65535, ]; diff --git a/src/MailTracker.php b/src/MailTracker.php index d00f449..9d97584 100644 --- a/src/MailTracker.php +++ b/src/MailTracker.php @@ -65,13 +65,13 @@ protected function addTrackers($html, $hash) protected function injectTrackingPixel($html, $hash) { // Append the tracking url - $tracking_pixel = ''; + $tracking_pixel = ''; $linebreak = app(Str::class)->random(32); $html = str_replace("\n", $linebreak, $html); if (preg_match("/^(.*]*>)(.*)$/", $html, $matches)) { - $html = $matches[1].$matches[2].$tracking_pixel; + $html = $matches[1] . $matches[2] . $tracking_pixel; } else { $html = $html . $tracking_pixel; } @@ -101,7 +101,7 @@ protected function inject_link_callback($matches) $url = str_replace('&', '&', $matches[2]); } - return $matches[1].route( + return $matches[1] . route( 'mailTracker_n', [ 'l' => $url, @@ -132,7 +132,8 @@ public static function hash_url($url) * @param $buffer * @return string|string[]|null */ - protected function sanitizeHtml($html) { + protected function sanitizeHtml($html) + { if (is_null($html)) { return null; @@ -183,7 +184,8 @@ protected function createTrackers($message) $original_content = $message->getBody(); - if ($message->getContentType() === 'text/html' || + if ( + $message->getContentType() === 'text/html' || ($message->getContentType() === 'multipart/alternative' && $message->getBody()) || ($message->getContentType() === 'multipart/mixed' && $message->getBody()) ) { @@ -202,18 +204,16 @@ protected function createTrackers($message) } $tracker = SentEmail::create([ - 'hash'=>$hash, - 'headers'=>$headers->toString(), - 'sender_name'=>$from_name, - 'sender_email'=>$from_email, - 'recipient_name'=>$to_name, - 'recipient_email'=>$to_email, - 'subject'=>$subject, - 'opens'=>0, - 'clicks'=>0, - 'message_id'=>$message->getId(), - 'mailable'=>$mailable, - 'meta'=>[], + 'hash' => $hash, + 'headers' => $headers->toString(), + 'sender' => $from_name . " <" . $from_email . ">", + 'recipient' => $to_name . ' <' . $to_email . '>', + 'subject' => $subject, + 'content' => config('mail-tracker.log-content', true) ? (strlen($original_content) > config('mail-tracker.content-max-size', 65535) ? substr($original_content, 0, config('mail-tracker.content-max-size', 65535)) . '...' : $original_content) : null, + 'opens' => 0, + 'clicks' => 0, + 'message_id' => $message->getId(), + 'meta' => [], ]); $content_text = strlen($original_content) > 65535 ? substr($original_content, 0, 65532) . "..." : $original_content; diff --git a/src/MailTrackerController.php b/src/MailTrackerController.php index 4cc4f93..2db7da5 100644 --- a/src/MailTrackerController.php +++ b/src/MailTrackerController.php @@ -19,7 +19,7 @@ class MailTrackerController extends Controller public function getT($hash) { // Create a 1x1 ttransparent pixel and return it - $pixel = sprintf('%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%', 71, 73, 70, 56, 57, 97, 1, 0, 1, 0, 128, 255, 0, 192, 192, 192, 0, 0, 0, 33, 249, 4, 1, 0, 0, 0, 0, 44, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 2, 68, 1, 0, 59); + $pixel = sprintf('%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c', 71, 73, 70, 56, 57, 97, 1, 0, 1, 0, 128, 255, 0, 192, 192, 192, 0, 0, 0, 33, 249, 4, 1, 0, 0, 0, 0, 44, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 2, 68, 1, 0, 59); $response = Response::make($pixel, 200); $response->header('Content-type', 'image/gif'); $response->header('Content-Length', 42);