Attachment.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Mail\Provider;
  8. /**
  9. * Mail Attachment Object
  10. *
  11. * This object is used to define the parameters of a mail attachment
  12. *
  13. * @since 30.0.0
  14. *
  15. */
  16. class Attachment implements \OCP\Mail\Provider\IAttachment {
  17. /**
  18. * initialize the mail attachment object
  19. *
  20. * @since 30.0.0
  21. *
  22. * @param string|null $contents binary contents of file
  23. * @param string|null $name file name (e.g example.txt)
  24. * @param string|null $type mime type (e.g. text/plain)
  25. * @param bool $embedded embedded status of the attachment, default is false
  26. */
  27. public function __construct(
  28. protected ?string $contents,
  29. protected ?string $name,
  30. protected ?string $type,
  31. protected bool $embedded = false
  32. ) {
  33. }
  34. /**
  35. * sets the attachment file name
  36. *
  37. * @since 30.0.0
  38. *
  39. * @param string $value file name (e.g example.txt)
  40. *
  41. * @return self return this object for command chaining
  42. */
  43. public function setName(string $value): self {
  44. $this->name = $value;
  45. return $this;
  46. }
  47. /**
  48. * gets the attachment file name
  49. *
  50. * @since 30.0.0
  51. *
  52. * @return string | null returns the attachment file name or null if not set
  53. */
  54. public function getName(): string|null {
  55. return $this->name;
  56. }
  57. /**
  58. * sets the attachment mime type
  59. *
  60. * @since 30.0.0
  61. *
  62. * @param string $value mime type (e.g. text/plain)
  63. *
  64. * @return self return this object for command chaining
  65. */
  66. public function setType(string $value): self {
  67. $this->type = $value;
  68. return $this;
  69. }
  70. /**
  71. * gets the attachment mime type
  72. *
  73. * @since 30.0.0
  74. *
  75. * @return string | null returns the attachment mime type or null if not set
  76. */
  77. public function getType(): string|null {
  78. return $this->type;
  79. }
  80. /**
  81. * sets the attachment contents (actual data)
  82. *
  83. * @since 30.0.0
  84. *
  85. * @param string $value binary contents of file
  86. *
  87. * @return self return this object for command chaining
  88. */
  89. public function setContents(string $value): self {
  90. $this->contents = $value;
  91. return $this;
  92. }
  93. /**
  94. * gets the attachment contents (actual data)
  95. *
  96. * @since 30.0.0
  97. *
  98. * @return string | null returns the attachment contents or null if not set
  99. */
  100. public function getContents(): string|null {
  101. return $this->contents;
  102. }
  103. /**
  104. * sets the embedded status of the attachment
  105. *
  106. * @since 30.0.0
  107. *
  108. * @param bool $value true - embedded / false - not embedded
  109. *
  110. * @return self return this object for command chaining
  111. */
  112. public function setEmbedded(bool $value): self {
  113. $this->embedded = $value;
  114. return $this;
  115. }
  116. /**
  117. * gets the embedded status of the attachment
  118. *
  119. * @since 30.0.0
  120. *
  121. * @return bool embedded status of the attachment
  122. */
  123. public function getEmbedded(): bool {
  124. return $this->embedded;
  125. }
  126. }