Skip to content

Commit b348ea2

Browse files
committed
making architecture more reasonable
1 parent 4000252 commit b348ea2

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

MailLibrary/Mail.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ public function getAttachments()
193193
return $this->structure->getAttachments();
194194
}
195195

196+
/**
197+
* @return \greeny\MailLibrary\MimePart[]
198+
*/
199+
public function getMimeParts()
200+
{
201+
$this->structure !== NULL || $this->initializeStructure();
202+
return $this->structure->getMimeParts();
203+
}
204+
196205
/**
197206
* @return array
198207
*/
@@ -257,8 +266,11 @@ protected function initializeStructure()
257266
$this->structure = $this->connection->getDriver()->getStructure($this->id, $this->mailbox);
258267
}
259268

260-
/** @internal */
261-
public function getStructure(): IStructure {
269+
/**
270+
* @internal
271+
* @return IStructure
272+
*/
273+
public function getStructure() {
262274
$this->structure !== NULL || $this->initializeStructure();
263275
return $this->structure;
264276
}

MailLibrary/Structures/IStructure.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ function getTextBody();
2929
*/
3030
function getAttachments();
3131

32-
/** @return MimePart[] */
33-
public function getParts(): array;
34-
}
32+
/**
33+
* @return MimePart[]
34+
*/
35+
function getMimeParts();
36+
}

MailLibrary/Structures/ImapStructure.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public function __construct(ImapDriver $driver, $structure, $mailId, Mailbox $ma
9393

9494
/**
9595
* @return array
96+
* @internal use only with caution, format can change without warning
9697
*/
9798
public function getRawStructure()
9899
{
@@ -115,9 +116,9 @@ public function getHtmlBody()
115116
if($this->htmlBody === NULL) {
116117
$this->driver->switchMailbox($this->mailbox->getName());
117118
return $this->htmlBody = $this->driver->getBody($this->id, $this->htmlBodyIds);
118-
} else {
119-
return $this->htmlBody;
120119
}
120+
121+
return $this->htmlBody;
121122
}
122123

123124
/**
@@ -128,9 +129,9 @@ public function getTextBody()
128129
if($this->textBody === NULL) {
129130
$this->driver->switchMailbox($this->mailbox->getName());
130131
return $this->textBody = $this->driver->getBody($this->id, $this->textBodyIds);
131-
} else {
132-
return $this->textBody;
133132
}
133+
134+
return $this->textBody;
134135
}
135136

136137
/**
@@ -148,13 +149,21 @@ public function getAttachments()
148149
return $this->attachments;
149150
}
150151

151-
/** @return MimePart[] */
152-
public function getParts(): array
152+
/**
153+
* @return MimePart[]
154+
*/
155+
public function getMimeParts()
153156
{
154157
$this->driver->switchMailbox($this->mailbox->getName());
155158
return $this->messageParts;
156159
}
157160

161+
/** @deprecated use getMimeParts() instead */
162+
public function getParts() {
163+
\trigger_error(\E_USER_DEPRECATED, 'use getMimeParts() instead');
164+
return $this->getMimeParts();
165+
}
166+
158167
protected function addStructurePart($structure, $partId)
159168
{
160169
$type = $structure->type;
@@ -173,12 +182,15 @@ protected function addStructurePart($structure, $partId)
173182
}
174183
}
175184

185+
/** @noinspection NestedTernaryOperatorInspection Yep, will fix this when we switch to PHP7 level; see ?? operator */
176186
$this->messageParts[] = new MimePart(
177187
$this->driver,
178188
$this->id,
179189
$partId,
180190
self::$typeTable[$type]. '/' . $subtype,
181-
$parameters['filename'] ?? $parameters['name'] ?? '',
191+
(empty($parameters['filename']) ? $parameters['filename'] : (
192+
empty($parameters['name']) ? $parameters['name'] : ''
193+
)),
182194
$encoding
183195
);
184196

0 commit comments

Comments
 (0)