From f5ece72ae8caad2040777fd8a919c0456c2f8c4f Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Sun, 29 Oct 2017 11:45:53 -0100 Subject: [PATCH] some comments --- appinfo/info.xml | 3 +++ lib/Command/Addresses.php | 18 +++++++++++++++++- lib/Controller/RemoteController.php | 2 ++ lib/Service/MailService.php | 29 +++++++++++++++++++++-------- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 25d5e48..f25a6bb 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -18,6 +18,9 @@ https://github.com/daita/files_frommail/wiki tools + files + social + https://github.com/daita/files_frommail https://github.com/daita/files_frommail/issues https://github.com/daita/files_frommail.git diff --git a/lib/Command/Addresses.php b/lib/Command/Addresses.php index b84f8f5..5c33bb8 100644 --- a/lib/Command/Addresses.php +++ b/lib/Command/Addresses.php @@ -54,6 +54,15 @@ public function __construct(MailService $mailService) { } + /** + * ./occ files_frommail:address to manage the mail address to get caught by the app. + * + * ./occ files_frommail:address --list + * ./occ files_frommail:address --add mail_address + * ./occ files_frommail:address --remove mail_address + * ./occ files_frommail:address --password mail_address password + * + */ protected function configure() { parent::configure(); $this->setName('files_frommail:address') @@ -64,11 +73,18 @@ protected function configure() { ->addOption( 'password', 'p', InputOption::VALUE_NONE, 'add a password to protect a mail address' ) - ->addArgument('address', InputArgument::OPTIONAL, 'email address') + ->addArgument('address', InputArgument::OPTIONAL, 'mail address') ->addArgument('password', InputArgument::OPTIONAL, 'password'); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + * @throws Exception + */ protected function execute(InputInterface $input, OutputInterface $output) { try { diff --git a/lib/Controller/RemoteController.php b/lib/Controller/RemoteController.php index e2049b7..f22adb1 100644 --- a/lib/Controller/RemoteController.php +++ b/lib/Controller/RemoteController.php @@ -65,6 +65,8 @@ function __construct(IRequest $request, $userId, MailService $mailService, MiscS /** + * endpoint that will receive mail content from NextcloudMailCatcher.php + * * @NoAdminRequired * @NoCSRFRequired * diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php index d92f6cb..2ee0bff 100644 --- a/lib/Service/MailService.php +++ b/lib/Service/MailService.php @@ -38,6 +38,7 @@ use PhpMimeMailParser\Attachment; use PhpMimeMailParser\Parser; + class MailService { @@ -63,6 +64,15 @@ function __construct(ConfigService $configService, MiscService $miscService) { /** + * parse the mail content. + * + * will create a local text file containing the headers and the content of the mail for each one of + * the 'to' or 'cc' mail address correspond to a mail added using the + * "./occ files_frommail:address --add" + * + * Attachments will also be saved on the cloud in the path: + * "Mails sent to yourmail@example.net/From author@example.com/" + * * @param string $content * @param string $userId */ @@ -74,18 +84,20 @@ public function parseMail($content, $userId) { $data['date'] = date('Y-m-d H:i:s'); $data['userId'] = $userId; - $toAddresses = array_merge( - $mail->getAddresses('to'), - $mail->getAddresses('cc'), - $mail->getAddresses('bcc') - ); - + $done = []; + $toAddresses = array_merge($mail->getAddresses('to'), $mail->getAddresses('cc')); foreach ($toAddresses as $toAddress) { + $to = $toAddress['address']; + if (in_array($to, $done)) { + continue; + } + try { - $this->generateLocalContentFromMail($mail, $toAddress['address'], $data); + $this->generateLocalContentFromMail($mail, $to, $data); } catch (Exception $e) { - // we check next address } + + $done[] = $to; } } @@ -106,6 +118,7 @@ private function generateLocalContentFromMail(Parser $mail, $to, $data) { $this->verifyInfoAndPassword($text, $toInfo); + $this->count = 0; $folder = $this->getMailFolder($userId, $to, $from); $this->createLocalFile($folder, $date, 'mail-' . $subject . '.txt', $text); $this->createLocalFileFromAttachments($date, $folder, $mail->getAttachments());