Skip to content

Commit f5ece72

Browse files
committed
some comments
1 parent ac6cdf2 commit f5ece72

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

appinfo/info.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<admin>https://github.com/daita/files_frommail/wiki</admin>
1919
</documentation>
2020
<category>tools</category>
21+
<category>files</category>
22+
<category>social</category>
23+
2124
<website>https://github.com/daita/files_frommail</website>
2225
<bugs>https://github.com/daita/files_frommail/issues</bugs>
2326
<repository>https://github.com/daita/files_frommail.git</repository>

lib/Command/Addresses.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ public function __construct(MailService $mailService) {
5454
}
5555

5656

57+
/**
58+
* ./occ files_frommail:address to manage the mail address to get caught by the app.
59+
*
60+
* ./occ files_frommail:address --list
61+
* ./occ files_frommail:address --add mail_address
62+
* ./occ files_frommail:address --remove mail_address
63+
* ./occ files_frommail:address --password mail_address password
64+
*
65+
*/
5766
protected function configure() {
5867
parent::configure();
5968
$this->setName('files_frommail:address')
@@ -64,11 +73,18 @@ protected function configure() {
6473
->addOption(
6574
'password', 'p', InputOption::VALUE_NONE, 'add a password to protect a mail address'
6675
)
67-
->addArgument('address', InputArgument::OPTIONAL, 'email address')
76+
->addArgument('address', InputArgument::OPTIONAL, 'mail address')
6877
->addArgument('password', InputArgument::OPTIONAL, 'password');
6978
}
7079

7180

81+
/**
82+
* @param InputInterface $input
83+
* @param OutputInterface $output
84+
*
85+
* @return int|null|void
86+
* @throws Exception
87+
*/
7288
protected function execute(InputInterface $input, OutputInterface $output) {
7389

7490
try {

lib/Controller/RemoteController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ function __construct(IRequest $request, $userId, MailService $mailService, MiscS
6565

6666

6767
/**
68+
* endpoint that will receive mail content from NextcloudMailCatcher.php
69+
*
6870
* @NoAdminRequired
6971
* @NoCSRFRequired
7072
*

lib/Service/MailService.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use PhpMimeMailParser\Attachment;
3939
use PhpMimeMailParser\Parser;
4040

41+
4142
class MailService {
4243

4344

@@ -63,6 +64,15 @@ function __construct(ConfigService $configService, MiscService $miscService) {
6364

6465

6566
/**
67+
* parse the mail content.
68+
*
69+
* will create a local text file containing the headers and the content of the mail for each one of
70+
* the 'to' or 'cc' mail address correspond to a mail added using the
71+
* "./occ files_frommail:address --add"
72+
*
73+
* Attachments will also be saved on the cloud in the path:
74+
* "Mails sent to yourmail@example.net/From author@example.com/"
75+
*
6676
* @param string $content
6777
* @param string $userId
6878
*/
@@ -74,18 +84,20 @@ public function parseMail($content, $userId) {
7484
$data['date'] = date('Y-m-d H:i:s');
7585
$data['userId'] = $userId;
7686

77-
$toAddresses = array_merge(
78-
$mail->getAddresses('to'),
79-
$mail->getAddresses('cc'),
80-
$mail->getAddresses('bcc')
81-
);
82-
87+
$done = [];
88+
$toAddresses = array_merge($mail->getAddresses('to'), $mail->getAddresses('cc'));
8389
foreach ($toAddresses as $toAddress) {
90+
$to = $toAddress['address'];
91+
if (in_array($to, $done)) {
92+
continue;
93+
}
94+
8495
try {
85-
$this->generateLocalContentFromMail($mail, $toAddress['address'], $data);
96+
$this->generateLocalContentFromMail($mail, $to, $data);
8697
} catch (Exception $e) {
87-
// we check next address
8898
}
99+
100+
$done[] = $to;
89101
}
90102
}
91103

@@ -106,6 +118,7 @@ private function generateLocalContentFromMail(Parser $mail, $to, $data) {
106118

107119
$this->verifyInfoAndPassword($text, $toInfo);
108120

121+
$this->count = 0;
109122
$folder = $this->getMailFolder($userId, $to, $from);
110123
$this->createLocalFile($folder, $date, 'mail-' . $subject . '.txt', $text);
111124
$this->createLocalFileFromAttachments($date, $folder, $mail->getAttachments());

0 commit comments

Comments
 (0)