Merge pull request #4309 from nextcloud/remove-unused-code
Removes unused code for link share emails
This commit is contained in:
commit
b5d31e4e65
|
@ -1,13 +0,0 @@
|
||||||
<?php
|
|
||||||
print_unescaped($l->t("Hey there,\n\njust letting you know that %s shared %s with you.\nView it: %s\n\n", array($_['user_displayname'], $_['filename'], $_['link'])));
|
|
||||||
if ( isset($_['expiration']) ) {
|
|
||||||
print_unescaped($l->t("The share will expire on %s.", array($_['expiration'])));
|
|
||||||
print_unescaped("\n\n");
|
|
||||||
}
|
|
||||||
// TRANSLATORS term at the end of a mail
|
|
||||||
p($l->t("Cheers!"));
|
|
||||||
?>
|
|
||||||
|
|
||||||
--
|
|
||||||
<?php p($theme->getName() . ' - ' . $theme->getSlogan()); ?>
|
|
||||||
<?php print_unescaped("\n".$theme->getBaseUrl());
|
|
|
@ -1,38 +0,0 @@
|
||||||
<table cellspacing="0" cellpadding="0" border="0" width="100%">
|
|
||||||
<tr><td>
|
|
||||||
<table cellspacing="0" cellpadding="0" border="0" width="600px">
|
|
||||||
<tr>
|
|
||||||
<td colspan="2" bgcolor="<?php p($theme->getColorPrimary());?>">
|
|
||||||
<img src="<?php p(\OC::$server->getURLGenerator()->getAbsoluteURL(image_path('', 'logo-mail.png'))); ?>" alt="<?php p($theme->getName()); ?>"/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr><td colspan="2"> </td></tr>
|
|
||||||
<tr>
|
|
||||||
<td width="20px"> </td>
|
|
||||||
<td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">
|
|
||||||
<?php
|
|
||||||
print_unescaped($l->t('Hey there,<br><br>just letting you know that %s shared <strong>%s</strong> with you.<br><a href="%s">View it!</a><br><br>', array($_['user_displayname'], $_['filename'], $_['link'])));
|
|
||||||
if ( isset($_['expiration']) ) {
|
|
||||||
p($l->t("The share will expire on %s.", array($_['expiration'])));
|
|
||||||
print_unescaped('<br><br>');
|
|
||||||
}
|
|
||||||
// TRANSLATORS term at the end of a mail
|
|
||||||
p($l->t('Cheers!'));
|
|
||||||
?>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr><td colspan="2"> </td></tr>
|
|
||||||
<tr>
|
|
||||||
<td width="20px"> </td>
|
|
||||||
<td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">--<br>
|
|
||||||
<?php p($theme->getName()); ?> -
|
|
||||||
<?php p($theme->getSlogan()); ?>
|
|
||||||
<br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl());?></a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td colspan="2"> </td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</td></tr>
|
|
||||||
</table>
|
|
|
@ -86,72 +86,4 @@ class MailNotifications {
|
||||||
$this->replyTo = $this->user->getEMailAddress();
|
$this->replyTo = $this->user->getEMailAddress();
|
||||||
$this->senderDisplayName = $this->user->getDisplayName();
|
$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];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,130 +84,6 @@ class MailNotificationsTest extends \Test\TestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
* @param string $subject
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue