Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions core/templates/altmail.php

This file was deleted.

38 changes: 0 additions & 38 deletions core/templates/mail.php

This file was deleted.

68 changes: 0 additions & 68 deletions lib/private/Share/MailNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,72 +86,4 @@ public function __construct(IUser $user,
$this->replyTo = $this->user->getEMailAddress();
$this->senderDisplayName = $this->user->getDisplayName();
}

/**
* inform recipient about public link share
*
* @param string $recipient recipient email address
* @param string $filename the shared file
* @param string $link the public link
* @param int $expiration expiration date (timestamp)
* @return string[] $result of failed recipients
*/
public function sendLinkShareMail($recipient, $filename, $link, $expiration) {
$subject = (string)$this->l->t('%s shared »%s« with you', [$this->senderDisplayName, $filename]);
list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration);

$recipient = str_replace([', ', '; ', ',', ';', ' '], ',', $recipient);
$recipients = explode(',', $recipient);
try {
$message = $this->mailer->createMessage();
$message->setSubject($subject);
$message->setTo($recipients);
$message->setHtmlBody($htmlBody);
$message->setPlainBody($textBody);
$message->setFrom([
Util::getDefaultEmailAddress('sharing-noreply') =>
(string)$this->l->t('%s via %s', [
$this->senderDisplayName,
$this->defaults->getName()
]),
]);
if(!is_null($this->replyTo)) {
$message->setReplyTo([$this->replyTo]);
}

return $this->mailer->send($message);
} catch (\Exception $e) {
$this->logger->error("Can't send mail with public link to $recipient: ".$e->getMessage(), ['app' => 'sharing']);
return [$recipient];
}
}

/**
* create mail body for plain text and html mail
*
* @param string $filename the shared file
* @param string $link link to the shared file
* @param int $expiration expiration date (timestamp)
* @param string $prefix prefix of mail template files
* @return array an array of the html mail body and the plain text mail body
*/
private function createMailBody($filename, $link, $expiration, $prefix = '') {
$formattedDate = $expiration ? $this->l->l('date', $expiration) : null;

$html = new \OC_Template('core', $prefix . 'mail', '');
$html->assign ('link', $link);
$html->assign ('user_displayname', $this->senderDisplayName);
$html->assign ('filename', $filename);
$html->assign('expiration', $formattedDate);
$htmlMail = $html->fetchPage();

$plainText = new \OC_Template('core', $prefix . 'altmail', '');
$plainText->assign ('link', $link);
$plainText->assign ('user_displayname', $this->senderDisplayName);
$plainText->assign ('filename', $filename);
$plainText->assign('expiration', $formattedDate);
$plainTextMail = $plainText->fetchPage();

return [$htmlMail, $plainTextMail];
}
}
124 changes: 0 additions & 124 deletions tests/lib/Share/MailNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,130 +84,6 @@ public function setUp() {

}

public function testSendLinkShareMailWithoutReplyTo() {
$message = $this->getMockBuilder('\OC\Mail\Message')
->disableOriginalConstructor()->getMock();

$message
->expects($this->once())
->method('setSubject')
->with('TestUser shared »MyFile« with you');
$message
->expects($this->once())
->method('setTo')
->with(['lukas@owncloud.com']);
$message
->expects($this->once())
->method('setHtmlBody');
$message
->expects($this->once())
->method('setPlainBody');
$message
->expects($this->once())
->method('setFrom')
->with([\OCP\Util::getDefaultEmailAddress('sharing-noreply') => 'TestUser via UnitTestCloud']);

$this->mailer
->expects($this->once())
->method('createMessage')
->will($this->returnValue($message));
$this->mailer
->expects($this->once())
->method('send')
->with($message)
->will($this->returnValue([]));

$mailNotifications = new MailNotifications(
$this->user,
$this->l10n,
$this->mailer,
$this->logger,
$this->defaults,
$this->urlGenerator
);

$this->assertSame([], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
}

public function dataSendLinkShareMailWithReplyTo() {
return [
['lukas@owncloud.com', ['lukas@owncloud.com']],
['lukas@owncloud.com nickvergessen@owncloud.com', ['lukas@owncloud.com', 'nickvergessen@owncloud.com']],
['lukas@owncloud.com,nickvergessen@owncloud.com', ['lukas@owncloud.com', 'nickvergessen@owncloud.com']],
['lukas@owncloud.com, nickvergessen@owncloud.com', ['lukas@owncloud.com', 'nickvergessen@owncloud.com']],
['lukas@owncloud.com;nickvergessen@owncloud.com', ['lukas@owncloud.com', 'nickvergessen@owncloud.com']],
['lukas@owncloud.com; nickvergessen@owncloud.com', ['lukas@owncloud.com', 'nickvergessen@owncloud.com']],
];
}

/**
* @dataProvider dataSendLinkShareMailWithReplyTo
* @param string $to
* @param array $expectedTo
*/
public function testSendLinkShareMailWithReplyTo($to, array $expectedTo) {
$message = $this->getMockBuilder('\OC\Mail\Message')
->disableOriginalConstructor()->getMock();

$message
->expects($this->once())
->method('setSubject')
->with('TestUser shared »MyFile« with you');
$message
->expects($this->once())
->method('setTo')
->with($expectedTo);
$message
->expects($this->once())
->method('setHtmlBody');
$message
->expects($this->once())
->method('setPlainBody');
$message
->expects($this->once())
->method('setFrom')
->with([\OCP\Util::getDefaultEmailAddress('sharing-noreply') => 'TestUser via UnitTestCloud']);
$message
->expects($this->once())
->method('setReplyTo')
->with(['sharer@owncloud.com']);

$this->mailer
->expects($this->once())
->method('createMessage')
->will($this->returnValue($message));
$this->mailer
->expects($this->once())
->method('send')
->with($message)
->will($this->returnValue([]));

$mailNotifications = new MailNotifications(
$this->user,
$this->l10n,
$this->mailer,
$this->logger,
$this->defaults,
$this->urlGenerator
);
$this->assertSame([], $mailNotifications->sendLinkShareMail($to, 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
}

public function testSendLinkShareMailException() {
$this->setupMailerMock('TestUser shared »MyFile« with you', ['lukas@owncloud.com']);

$mailNotifications = new MailNotifications(
$this->user,
$this->l10n,
$this->mailer,
$this->logger,
$this->defaults,
$this->urlGenerator
);

$this->assertSame(['lukas@owncloud.com'], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
}

/**
* @param string $subject
*/
Expand Down