Skip to content

Commit

Permalink
0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl committed Jul 4, 2019
1 parent e77583c commit ce02caf
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cert_dir=$(HOME)/.nextcloud/certificates
codecov_token_dir=$(HOME)/.nextcloud/codecov_token
github_account=nextcloud
branch=master
version+=0.2.0
version+=0.3.0

all: appstore

Expand Down
5 changes: 2 additions & 3 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
]]>
</description>
<version>0.2.0</version>
<version>0.3.0</version>
<licence>agpl</licence>
<author>Maxence Lange</author>
<namespace>Files_FromMail</namespace>
Expand All @@ -20,15 +20,14 @@
</documentation>
<category>tools</category>
<category>files</category>
<category>social</category>

<website>https://github.com/nextcloud/files_frommail</website>
<bugs>https://github.com/nextcloud/files_frommail/issues</bugs>
<repository>https://github.com/nextcloud/files_frommail.git</repository>
<screenshot>https://raw.githubusercontent.com/nextcloud/files_frommail/master/screenshots/v0.1.0.png</screenshot>

<dependencies>
<nextcloud min-version="12" max-version="16"/>
<nextcloud min-version="15" max-version="17"/>
</dependencies>

<commands>
Expand Down
4 changes: 1 addition & 3 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

return [
'routes' => [
['name' => 'Remote#getContent', 'url' => '/remote/', 'verb' => 'PUT']
['name' => 'Remote#getContent', 'url' => '/remote', 'verb' => 'PUT']
]
];


4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"name": "nextcloud/files_frommail",
"description": "Files From Mail",
"minimum-stability": "stable",
"license": "proprietary",
"license": "agpl",
"authors": [
{
"name": "Maxence Lange",
"email": "[email protected]"
}
],
"require": {
"php-mime-mail-parser/php-mime-mail-parser": "2.9.2"
"php-mime-mail-parser/php-mime-mail-parser": "3.0.4"
}
}
21 changes: 10 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions lib/Command/Addresses.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@

use Exception;
use OC\Core\Command\Base;
use OCA\Files_FromMail\Exceptions\AddressAlreadyExistException;
use OCA\Files_FromMail\Exceptions\FakeException;
use OCA\Files_FromMail\Exceptions\InvalidAddressException;
use OCA\Files_FromMail\Exceptions\MissingArgumentException;
use OCA\Files_FromMail\Exceptions\UnknownAddressException;
use OCA\Files_FromMail\Service\MailService;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -131,6 +134,9 @@ private function listMailAddresses(InputInterface $input, OutputInterface $outpu
* @param InputInterface $input
*
* @throws FakeException
* @throws MissingArgumentException
* @throws AddressAlreadyExistException
* @throws InvalidAddressException
*/
private function addMailAddress(InputInterface $input) {
if ($input->getOption('add') !== true) {
Expand All @@ -148,6 +154,8 @@ private function addMailAddress(InputInterface $input) {
* @param InputInterface $input
*
* @throws FakeException
* @throws MissingArgumentException
* @throws UnknownAddressException
*/
private function removeMailAddress(InputInterface $input) {
if ($input->getOption('remove') !== true) {
Expand All @@ -166,6 +174,8 @@ private function removeMailAddress(InputInterface $input) {
* @param OutputInterface $output
*
* @throws FakeException
* @throws MissingArgumentException
* @throws UnknownAddressException
*/
private function setMailAddressPassword(InputInterface $input, OutputInterface $output) {
if ($input->getOption('password') !== true) {
Expand All @@ -186,6 +196,12 @@ private function setMailAddressPassword(InputInterface $input, OutputInterface $
}


/**
* @param InputInterface $input
*
* @return string|string[]|null
* @throws MissingArgumentException
*/
private function checkMailAddress(InputInterface $input) {
$mail = $input->getArgument('address');
if ($mail === null) {
Expand Down
21 changes: 16 additions & 5 deletions lib/Controller/RemoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace OCA\Files_FromMail\Controller;

use Exception;
use OCA\Files_FromMail\AppInfo\Application;
use OCA\Files_FromMail\Service\MailService;
use OCA\Files_FromMail\Service\MiscService;
Expand Down Expand Up @@ -54,7 +55,8 @@ class RemoteController extends Controller {
* @param MailService $mailService
* @param MiscService $miscService
*/
function __construct(IRequest $request, $userId, MailService $mailService, MiscService $miscService
function __construct(
IRequest $request, $userId, MailService $mailService, MiscService $miscService
) {
parent::__construct(Application::APP_NAME, $request);
$this->userId = $userId;
Expand All @@ -75,11 +77,20 @@ function __construct(IRequest $request, $userId, MailService $mailService, MiscS
* @return DataResponse
*/
public function getContent($content) {
$content = base64_decode(rawurldecode($content));
$this->mailService->parseMail($content, $this->userId);

return new DataResponse(['ok'], Http::STATUS_CREATED);
try {
if ($content !== 'null') {
$content = base64_decode(rawurldecode($content));
$this->mailService->parseMail($content, $this->userId);
}

return new DataResponse(['ok'], Http::STATUS_CREATED);
} catch (Exception $e) {
$this->miscService->log('issue while getContent() : ' . $e->getMessage());

return new DataResponse(['error' => $e->getMessage()], Http::STATUS_CREATED);
}
}


}
}
64 changes: 51 additions & 13 deletions lib/NextcloudMailCatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

class NextcloudMailCatcher {


/** @var string */
private $content;

Expand All @@ -50,15 +51,12 @@ class NextcloudMailCatcher {
* @param array $config
*/
public function __construct($config) {

$nextcloud = $config['nextcloud'];
if (substr($nextcloud, -1) === '/') {
$config['nextcloud'] = substr($nextcloud, 0, -1);
}


$this->config = $config;
$this->debug('Catching a new mail');
}


Expand Down Expand Up @@ -89,9 +87,7 @@ public function sendToNextcloud() {

$content = rawurlencode(base64_encode($this->getContent()));

$curl = $this->generateAuthedCurl(
$this->config['nextcloud'] . '/index.php/apps/files_frommail/remote/'
);
$curl = $this->generateAuthedCurl();
$this->fillCurlWithContent($curl, 'content=' . $content);

$result = curl_exec($curl);
Expand All @@ -100,6 +96,32 @@ public function sendToNextcloud() {
}


/**
*
*/
public function test() {
$this->config['debug'] = true;
$this->debug('testing!');

$pwd = $this->config['password'];
if (substr($pwd, 5, 1) !== '-') {
$this->debug('');
$this->debug('Error: password have to be a generated token');
$this->debug(
'Generate a token on the webclient: Settings / Security / Devices & session'
);
exit();
}

$curl = $this->generateAuthedCurl();
$this->fillCurlWithContent($curl, 'content=null');

$result = curl_exec($curl);

$this->debugCurl($curl, $result);
}


/**
* @param resource $curl
* @param string|array $result
Expand All @@ -123,6 +145,11 @@ private function debugCurl($curl, $result) {
}


/**
* @param $curl
*
* @throws Exception
*/
private function debugCurlResponseCode($curl) {

$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
Expand All @@ -147,13 +174,13 @@ private function debugCurlResponseCode($curl) {


/**
* @param $url
*
* @return resource
*/
private function generateAuthedCurl($url) {
private function generateAuthedCurl() {

$url = $this->config['nextcloud'] . '/index.php/apps/files_frommail/remote';
$curl = curl_init($url);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt(
Expand All @@ -162,7 +189,8 @@ private function generateAuthedCurl($url) {
);

$this->debug(
'Generate curl request to ' . $url . ' with username \'' . $this->config['username'] . '\''
'Generate curl request to ' . $url . ' with username \'' . $this->config['username']
. '\''
);

return $curl;
Expand Down Expand Up @@ -200,20 +228,30 @@ private function debug($string) {
return;
}

$log = '/tmp/' . basename(__FILE__, '.php') . '.log';
file_put_contents($log, date('Y-m-d H:i:s') . ' ' . $string . "\n", FILE_APPEND);
echo $string . "\n";
// $log = '/tmp/' . basename(__FILE__, '.php') . '.log';
// file_put_contents($log, date('Y-m-d H:i:s') . ' ' . $string . "\n", FILE_APPEND);
}

}


$mailCatcher = new NextcloudMailCatcher($config);

if (sizeof($argv) === 2 && $argv[1] === 'test') {
$mailCatcher->test();

return;
}

echo 'Catching a new mail';

$content = '';
$fd = fopen('php://stdin', 'r');
while (!feof($fd)) {
$content .= fread($fd, 1024);
}

$mailCatcher = new NextcloudMailCatcher($config);
$mailCatcher->setContent($content);
$mailCatcher->sendToNextcloud();

Expand Down
Loading

0 comments on commit ce02caf

Please sign in to comment.