summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/Mail/Message.php17
-rw-r--r--tests/lib/Mail/MessageTest.php43
2 files changed, 15 insertions, 45 deletions
diff --git a/lib/private/Mail/Message.php b/lib/private/Mail/Message.php
index d074befcae4..417b64d0f3a 100644
--- a/lib/private/Mail/Message.php
+++ b/lib/private/Mail/Message.php
@@ -307,18 +307,23 @@ class Message implements IMessage {
* Add the Auto-Submitted header to the email, preventing most automated
* responses to automated messages.
*
- * @param string $value (one of AutoSubmittedValue::NO, AutoSubmittedValue::AUTO_GENERATED, AutoSubmittedValue::AUTO_REPLIED)
+ * @param AutoSubmittedValue::* $value (one of AutoSubmittedValue::NO, AutoSubmittedValue::AUTO_GENERATED, AutoSubmittedValue::AUTO_REPLIED)
* @return $this
*/
public function setAutoSubmitted(string $value): IMessage {
$headers = $this->swiftMessage->getHeaders();
- if($headers->has('Auto-Submitted')) {
- $auto_submitted = $headers->get('Auto-Submitted');
- $auto_submitted->setValue($value);
- } else {
- $headers->addTextHeader('Auto-Submitted', $value);
+
+ if ($headers->has('Auto-Submitted')) {
+ // if the header already exsists, remove it.
+ // the value can be modified with some implementations
+ // of the interface \Swift_Mime_Header, however the
+ // interface doesn't, and this makes the static-code
+ // analysis unhappy.
+ $headers->remove('Auto-Submitted');
}
+ $headers->addTextHeader('Auto-Submitted', $value);
+
return $this;
}
diff --git a/tests/lib/Mail/MessageTest.php b/tests/lib/Mail/MessageTest.php
index aae25497876..cf9a48e29f2 100644
--- a/tests/lib/Mail/MessageTest.php
+++ b/tests/lib/Mail/MessageTest.php
@@ -8,7 +8,6 @@
namespace Test\Mail;
-use Egulias\EmailValidator\EmailValidator;
use OC\Mail\Message;
use OCP\Mail\AutoSubmittedValue;
use OCP\Mail\IEMailTemplate;
@@ -267,11 +266,9 @@ class MessageTest extends TestCase {
}
public function testSetAutoSubmitted1() {
-
$swiftMimeSimpleHeaderSet = $this->getMockBuilder('\Swift_Mime_SimpleHeaderSet')
->disableOriginalConstructor()
->getMock();
-
$swiftMessage = $this->getMockBuilder('\Swift_Message')
->disableOriginalConstructor()
->disableOriginalClone()
@@ -279,37 +276,25 @@ class MessageTest extends TestCase {
->disallowMockingUnknownTypes()
->getMock();
-
$swiftMessage->method('getHeaders')->willReturn($swiftMimeSimpleHeaderSet);
$swiftMimeSimpleHeaderSet->expects($this->once())
->method('has')
->with('Auto-Submitted');
-
$swiftMimeSimpleHeaderSet->expects($this->never())
- ->method('get');
-
+ ->method('remove');
$swiftMimeSimpleHeaderSet->expects($this->once())
->method('addTextHeader')
->with('Auto-Submitted', AutoSubmittedValue::AUTO_GENERATED);
$message = new Message($swiftMessage, false);
-
$message->setAutoSubmitted(AutoSubmittedValue::AUTO_GENERATED);
-
}
public function testSetAutoSubmitted2() {
-
- $swiftMimeHeader = $this->getMockBuilder('\Swift_Mime_Header')
- ->disableOriginalConstructor()
- ->addMethods(['setValue'])
- ->getMockForAbstractClass();
-
$swiftMimeSimpleHeaderSet = $this->getMockBuilder('\Swift_Mime_SimpleHeaderSet')
->disableOriginalConstructor()
->getMock();
-
$swiftMessage = $this->getMockBuilder('\Swift_Message')
->disableOriginalConstructor()
->disableOriginalClone()
@@ -317,38 +302,27 @@ class MessageTest extends TestCase {
->disallowMockingUnknownTypes()
->getMock();
-
$swiftMessage->method('getHeaders')->willReturn($swiftMimeSimpleHeaderSet);
- $swiftMimeSimpleHeaderSet->method('get')->with("Auto-Submitted")->willReturn($swiftMimeHeader);
-
$swiftMimeSimpleHeaderSet->expects($this->once())
->method('has')
->with('Auto-Submitted')
->willReturn(true);
-
$swiftMimeSimpleHeaderSet->expects($this->once())
- ->method('get');
-
- $swiftMimeSimpleHeaderSet->expects($this->never())
+ ->method('remove')
+ ->with('Auto-Submitted');
+ $swiftMimeSimpleHeaderSet->expects($this->once())
->method('addTextHeader')
->with('Auto-Submitted', AutoSubmittedValue::AUTO_GENERATED);
- $swiftMimeHeader->expects($this->once())
- ->method('setValue')
- ->with(AutoSubmittedValue::AUTO_GENERATED);
-
$message = new Message($swiftMessage, false);
-
$message->setAutoSubmitted(AutoSubmittedValue::AUTO_GENERATED);
}
public function testGetAutoSubmitted1() {
-
$swiftMimeSimpleHeaderSet = $this->getMockBuilder('\Swift_Mime_SimpleHeaderSet')
->disableOriginalConstructor()
->getMock();
-
$swiftMessage = $this->getMockBuilder('\Swift_Message')
->disableOriginalConstructor()
->disableOriginalClone()
@@ -356,30 +330,24 @@ class MessageTest extends TestCase {
->disallowMockingUnknownTypes()
->getMock();
-
$swiftMessage->method('getHeaders')->willReturn($swiftMimeSimpleHeaderSet);
$swiftMimeSimpleHeaderSet->expects($this->once())
->method('has')
->with('Auto-Submitted');
-
$swiftMimeSimpleHeaderSet->expects($this->never())
->method('get');
$message = new Message($swiftMessage, false);
-
$this->assertSame("no", $message->getAutoSubmitted());
}
public function testGetAutoSubmitted2() {
-
$swiftMimeHeader = $this->getMockBuilder('\Swift_Mime_Header')
->disableOriginalConstructor()
->getMockForAbstractClass();
-
$swiftMimeSimpleHeaderSet = $this->getMockBuilder('\Swift_Mime_SimpleHeaderSet')
->disableOriginalConstructor()
->getMock();
-
$swiftMessage = $this->getMockBuilder('\Swift_Message')
->disableOriginalConstructor()
->disableOriginalClone()
@@ -395,14 +363,11 @@ class MessageTest extends TestCase {
->method('has')
->with('Auto-Submitted')
->willReturn(true);
-
$swiftMimeSimpleHeaderSet->expects($this->once())
->method('get')
->willReturn($swiftMimeHeader);
$message = new Message($swiftMessage, false);
-
$this->assertSame(AutoSubmittedValue::AUTO_GENERATED, $message->getAutoSubmitted());
-
}
}