2727namespace OC \Mail ;
2828
2929use OCP \Mail \IAttachment ;
30+ use Symfony \Component \Mime \Email ;
3031
3132/**
3233 * Class Attachment
3536 * @since 13.0.0
3637 */
3738class Attachment implements IAttachment {
38- /** @var \Swift_Mime_Attachment */
39- protected $ swiftAttachment ;
39+ private ?string $ body ;
40+ private ?string $ name ;
41+ private ?string $ contentType ;
42+ private ?string $ path ;
4043
41- public function __construct (\Swift_Mime_Attachment $ attachment ) {
42- $ this ->swiftAttachment = $ attachment ;
44+ public function __construct (
45+ ?string $ body ,
46+ ?string $ name ,
47+ ?string $ contentType ,
48+ ?string $ path = null
49+ ) {
50+ $ this ->body = $ body ;
51+ $ this ->name = $ name ;
52+ $ this ->contentType = $ contentType ;
53+ $ this ->path = $ path ;
4354 }
4455
4556 /**
@@ -48,7 +59,7 @@ public function __construct(\Swift_Mime_Attachment $attachment) {
4859 * @since 13.0.0
4960 */
5061 public function setFilename (string $ filename ): IAttachment {
51- $ this ->swiftAttachment -> setFilename ( $ filename) ;
62+ $ this ->name = $ filename ;
5263 return $ this ;
5364 }
5465
@@ -58,7 +69,7 @@ public function setFilename(string $filename): IAttachment {
5869 * @since 13.0.0
5970 */
6071 public function setContentType (string $ contentType ): IAttachment {
61- $ this ->swiftAttachment -> setContentType ( $ contentType) ;
72+ $ this ->contentType = $ contentType ;
6273 return $ this ;
6374 }
6475
@@ -68,14 +79,15 @@ public function setContentType(string $contentType): IAttachment {
6879 * @since 13.0.0
6980 */
7081 public function setBody (string $ body ): IAttachment {
71- $ this ->swiftAttachment -> setBody ( $ body) ;
82+ $ this ->body = $ body ;
7283 return $ this ;
7384 }
7485
75- /**
76- * @return \Swift_Mime_Attachment
77- */
78- public function getSwiftAttachment (): \Swift_Mime_Attachment {
79- return $ this ->swiftAttachment ;
86+ public function attach (Email $ symfonyEmail ): void {
87+ if ($ this ->path !== null ) {
88+ $ symfonyEmail ->attachFromPath ($ this ->path , $ this ->name , $ this ->contentType );
89+ } else {
90+ $ symfonyEmail ->attach ($ this ->body , $ this ->name , $ this ->contentType );
91+ }
8092 }
8193}
0 commit comments