Skip to content

Commit

Permalink
Merge pull request #26 from tikoflano/fix/17
Browse files Browse the repository at this point in the history
Changed filename id format
  • Loading branch information
ArtificialOwl authored Jun 25, 2019
2 parents f040bbf + ad099f8 commit e77583c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
\.idea/

vendor/
/nbproject/private/
project.*
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,10 @@ You can choose to secure the mails and ask for a password:
Doing so, only mails containing '**:your_password**' in their content will be saved.

### Changing the generated filename id

By default the generated files start with an identifier in the format *'Y-m-d H:i:s'*. This identifier can be changed using

> ./occ config:app:set --value <NEW FORMAT> files_frommail filename_id
The `<NEW FORMAT>` value is a string using PHP [`date()`](https://www.php.net/manual/en/function.date.php) format.
4 changes: 3 additions & 1 deletion lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
class ConfigService {

const FROMMAIL_ADDRESSES = 'frommail_addresses';
const FROMMAIL_FILENAMEID = 'filename_id';

private $defaults = [
self::FROMMAIL_ADDRESSES => ''
self::FROMMAIL_ADDRESSES => '',
self::FROMMAIL_FILENAMEID => 'Y-m-d H:i:s',
];

/** @var string */
Expand Down
10 changes: 5 additions & 5 deletions lib/Service/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function parseMail($content, $userId) {
$mail->setText($content);

$data = $this->parseMailHeaders($mail);
$data['date'] = date('Y-m-d H:i:s');
$data['id'] = date($this->configService->getAppValue(ConfigService::FROMMAIL_FILENAMEID));
$data['userId'] = $userId;

$done = [];
Expand Down Expand Up @@ -114,14 +114,14 @@ private function generateLocalContentFromMail(Parser $mail, $to, $data) {
$subject = $data['subject'];
$from = $data['from'];
$userId = $data['userId'];
$date = $data['date'];
$id = $data['id'];

$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());
$this->createLocalFile($folder, $id, 'mail-' . $subject . '.txt', $text);
$this->createLocalFileFromAttachments($id, $folder, $mail->getAttachments());
}


Expand Down Expand Up @@ -352,4 +352,4 @@ private function saveMailAddresses($addresses) {
}


}
}

0 comments on commit e77583c

Please sign in to comment.