Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 68fc152
Showing
26 changed files
with
1,255 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Shopware 5 editor configuration normalization | ||
# http://editorconfig.org/ | ||
|
||
# This is the top-most .editorconfig file; do not search in parent directories. | ||
root = true | ||
|
||
# All files. | ||
[*] | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 4 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.ini] | ||
insert_final_newline = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
$finder = PhpCsFixer\Finder::create()->in(__DIR__ . '/'); | ||
|
||
return PhpCsFixer\Config::create() | ||
->setUsingCache(false) | ||
->setRules( | ||
[ | ||
'@PSR2' => true, | ||
'@Symfony' => true, | ||
'no_useless_else' => true, | ||
'no_useless_return' => true, | ||
'ordered_class_elements' => true, | ||
'ordered_imports' => true, | ||
'phpdoc_order' => true, | ||
'phpdoc_summary' => false, | ||
'blank_line_after_opening_tag' => false, | ||
'concat_space' => ['spacing' => 'one'], | ||
'array_syntax' => ['syntax' => 'short'], | ||
'declare_strict_types' => true, | ||
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], | ||
] | ||
) | ||
->setFinder($finder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace TinectMailArchive\Components; | ||
|
||
use Doctrine\DBAL\Connection; | ||
|
||
/** | ||
* Class DatabaseMailTransport | ||
* @package TinectMailArchive\Components | ||
*/ | ||
class DatabaseMailTransport extends \Zend_Mail_Transport_Abstract | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
private $connection; | ||
|
||
/** | ||
* DatabaseMailTransport constructor. | ||
* @param Connection $connection | ||
*/ | ||
public function __construct(Connection $connection) | ||
{ | ||
$this->connection = $connection; | ||
} | ||
|
||
/** | ||
* Send an email independent from the used transport | ||
* | ||
* The requisite information for the email will be found in the following | ||
* properties: | ||
* | ||
* - {@link $recipients} - list of recipients (string) | ||
* - {@link $header} - message header | ||
* - {@link $body} - message body | ||
*/ | ||
protected function _sendMail() | ||
{ | ||
$attachments = []; | ||
if ($this->_mail->hasAttachments) { | ||
$parts = $this->_mail->getParts(); | ||
|
||
/** @var \Zend_Mime_Part $part */ | ||
foreach ($parts as $part) { | ||
if ($part->disposition === 'attachment') { | ||
$attachments[] = [ | ||
'file_name' => $part->filename, | ||
'content' => $part->getContent() | ||
]; | ||
} | ||
} | ||
} | ||
|
||
$this->connection->insert('s_plugin_tinectmailarchive', [ | ||
'created' => date('Y-m-d H:i:s'), | ||
'senderAddress' => $this->_mail->getFrom(), | ||
'receiverAddress' => implode(',', $this->_mail->getRecipients()), | ||
'subject' => iconv_mime_decode($this->_mail->getSubject()), | ||
'bodyText' => $this->_mail->getPlainBodyText(), | ||
'bodyHtml' => $this->_mail->getPlainBody() | ||
]); | ||
|
||
$insertId = $this->connection->lastInsertId(); | ||
foreach ($attachments as $attachment) { | ||
$attachment['mail_id'] = $insertId; | ||
$this->connection->insert('s_plugin_tinectmailarchive_attachments', $attachment); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
use Doctrine\ORM\AbstractQuery; | ||
use TinectMailArchive\Models\Attachment; | ||
use TinectMailArchive\Models\Mails; | ||
|
||
/** | ||
* Class Shopware_Controllers_Backend_Mailarchive | ||
*/ | ||
class Shopware_Controllers_Backend_Mailarchive extends Shopware_Controllers_Backend_Application implements \Shopware\Components\CSRFWhitelistAware { | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $model = Mails::class; | ||
|
||
public function preDispatch() | ||
{ | ||
parent::preDispatch(); | ||
$this->View()->addTemplateDir($this->container->getParameter('tinect_mail_archive.view_dir')); | ||
} | ||
|
||
/** | ||
* Provides the last mail id for notifications | ||
*/ | ||
public function lastMailAction() | ||
{ | ||
$this->View()->success = true; | ||
$this->View()->id = (int) $this->container->get('dbal_connection')->fetchColumn('SELECT id FROM s_plugin_tinectmailarchive ORDER BY id DESC LIMIT 1'); | ||
} | ||
|
||
/** | ||
* Provides the new mails for notifications | ||
*/ | ||
public function getNewMailsAction() | ||
{ | ||
$this->View()->success = true; | ||
$mails = $this->container->get('dbal_connection')->fetchAll('SELECT id, subject, receiverAddress FROM s_plugin_tinectmailarchive WHERE id > :id ORDER BY id ASC', ['id' => $this->Request()->getParam('id')]); | ||
$this->View()->mails = $mails; | ||
} | ||
|
||
/** | ||
* Attachment list | ||
*/ | ||
public function getAttachmentsAction() | ||
{ | ||
$mailId = $this->Request()->getParam('mailId'); | ||
|
||
$qb = $this->getModelManager()->createQueryBuilder(); | ||
$result = $qb->from(Attachment::class, 'attachment') | ||
->select(['attachment.id', 'attachment.fileName']) | ||
->where('attachment.mail = :mailId') | ||
->setParameter('mailId', $mailId) | ||
->getQuery() | ||
->setHydrationMode(AbstractQuery::HYDRATE_ARRAY) | ||
->execute(); | ||
|
||
$this->View()->success = true; | ||
$this->View()->data = $result; | ||
$this->View()->total = count($result); | ||
} | ||
|
||
/** | ||
* Download a attachment | ||
*/ | ||
public function downloadAttachmentAction() | ||
{ | ||
$attachmentId = $this->Request()->getParam('id'); | ||
$attachment = $this->getModelManager()->find(Attachment::class, $attachmentId); | ||
|
||
header('Content-Type: application/octet-stream'); | ||
header('Content-Disposition: attachment; filename="' . $attachment->getFileName() . '"'); | ||
|
||
echo base64_decode($attachment->getContent()); | ||
exit(); | ||
} | ||
|
||
/** | ||
* Clear all entries in mailbox | ||
*/ | ||
public function clearAction() | ||
{ | ||
$this->container->get('dbal_connection')->executeQuery('SET FOREIGN_KEY_CHECKS = 0'); | ||
$this->container->get('dbal_connection')->executeQuery('TRUNCATE TABLE s_plugin_tinectmailarchive_attachments'); | ||
$this->container->get('dbal_connection')->executeQuery('TRUNCATE TABLE s_plugin_tinectmailarchive'); | ||
$this->container->get('dbal_connection')->executeQuery('SET FOREIGN_KEY_CHECKS = 1'); | ||
} | ||
|
||
/** | ||
* Returns a list with actions which should not be validated for CSRF protection | ||
* | ||
* @return string[] | ||
*/ | ||
public function getWhitelistedCSRFActions() | ||
{ | ||
return ['downloadAttachment']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 tinect | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace TinectMailArchive\Models; | ||
|
||
use Shopware\Components\Model\ModelEntity; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Table(name="s_plugin_tinectmailarchive_attachments") | ||
* @ORM\Entity | ||
*/ | ||
class Attachment extends ModelEntity | ||
{ | ||
/** | ||
* @var int | ||
* | ||
* @ORM\Column(name="id", type="integer", nullable=false) | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* OWNING SIDE | ||
* | ||
* @var Mails | ||
* | ||
* @ORM\ManyToOne(targetEntity="TinectMailArchive\Models\Mails") | ||
* @ORM\JoinColumn(name="mail_id", referencedColumnName="id") | ||
*/ | ||
protected $mail; | ||
|
||
/** | ||
* @ORM\Column(name="file_name", type="string", nullable=false) | ||
*/ | ||
private $fileName; | ||
|
||
/** | ||
* @ORM\Column(name="content", type="text", nullable=false) | ||
*/ | ||
private $content; | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @param int $id | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* @return Mails | ||
*/ | ||
public function getMail() | ||
{ | ||
return $this->mail; | ||
} | ||
|
||
/** | ||
* @param Mails $mail | ||
*/ | ||
public function setMail(Mails $mail) | ||
{ | ||
$this->mail = $mail; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getFileName() | ||
{ | ||
return $this->fileName; | ||
} | ||
|
||
/** | ||
* @param mixed $fileName | ||
*/ | ||
public function setFileName($fileName) | ||
{ | ||
$this->fileName = $fileName; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getContent() | ||
{ | ||
return $this->content; | ||
} | ||
|
||
/** | ||
* @param mixed $content | ||
*/ | ||
public function setContent($content) | ||
{ | ||
$this->content = $content; | ||
} | ||
} |
Oops, something went wrong.