Skip to content

Commit

Permalink
some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl committed Oct 29, 2017
1 parent ac6cdf2 commit f5ece72
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
3 changes: 3 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<admin>https://github.com/daita/files_frommail/wiki</admin>
</documentation>
<category>tools</category>
<category>files</category>
<category>social</category>

<website>https://github.com/daita/files_frommail</website>
<bugs>https://github.com/daita/files_frommail/issues</bugs>
<repository>https://github.com/daita/files_frommail.git</repository>
Expand Down
18 changes: 17 additions & 1 deletion lib/Command/Addresses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions lib/Controller/RemoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ function __construct(IRequest $request, $userId, MailService $mailService, MiscS


/**
* endpoint that will receive mail content from NextcloudMailCatcher.php
*
* @NoAdminRequired
* @NoCSRFRequired
*
Expand Down
29 changes: 21 additions & 8 deletions lib/Service/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use PhpMimeMailParser\Attachment;
use PhpMimeMailParser\Parser;


class MailService {


Expand All @@ -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 [email protected]/From [email protected]/"
*
* @param string $content
* @param string $userId
*/
Expand All @@ -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;
}
}

Expand All @@ -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());
Expand Down

0 comments on commit f5ece72

Please sign in to comment.