Skip to content

Commit 3a2217d

Browse files
committed
cs whitespace
1 parent e486843 commit 3a2217d

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

src/Mail/DkimSigner.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function __construct(array $options, array $signHeaders = self::DEFAULT_S
5050
if (!extension_loaded('openssl')) {
5151
throw new Nette\NotSupportedException('DkimSigner requires PHP extension openssl which is not loaded.');
5252
}
53+
5354
$this->domain = $options['domain'] ?? '';
5455
$this->selector = $options['selector'] ?? '';
5556
$this->privateKey = $options['privateKey'] ?? '';
@@ -70,6 +71,7 @@ public function generateSignedMessage(Message $message): string
7071

7172
return rtrim($header, "\r\n") . "\r\n" . $this->getSignature($message, $header, $this->normalizeNewLines($body)) . "\r\n\r\n" . $body;
7273
}
74+
7375
throw new SignException('Malformed email');
7476
}
7577

@@ -136,11 +138,14 @@ protected function sign(string $value): string
136138
if (PHP_VERSION_ID < 80000) {
137139
openssl_pkey_free($privateKey);
138140
}
141+
139142
return base64_encode($signature);
140143
}
144+
141145
if (PHP_VERSION_ID < 80000) {
142146
openssl_pkey_free($privateKey);
143147
}
148+
144149
return '';
145150
}
146151

src/Mail/Message.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function __construct()
4848
foreach (static::$defaultHeaders as $name => $value) {
4949
$this->setHeader($name, $value);
5050
}
51+
5152
$this->setHeader('Date', date('r'));
5253
}
5354

@@ -149,6 +150,7 @@ private function formatEmail(string $email, string $name = null): array
149150
$name = $tmp;
150151
}
151152
}
153+
152154
return [$email => $name];
153155
}
154156

@@ -219,6 +221,7 @@ public function setHtmlBody(string $html, string $basePath = null)
219221
if (!isset($cids[$file])) {
220222
$cids[$file] = substr($this->addEmbeddedFile($file)->getHeader('Content-ID'), 1, -1);
221223
}
224+
222225
$html = substr_replace(
223226
$html,
224227
"{$m[1][0]}{$m[2][0]}cid:{$cids[$file]}",
@@ -307,9 +310,11 @@ private function createAttachment(
307310
$content = Nette\Utils\FileSystem::read($file);
308311
$file = Strings::fixEncoding(basename($file));
309312
}
313+
310314
if (!$contentType) {
311315
$contentType = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $content);
312316
}
317+
313318
if (!strcasecmp($contentType, 'message/rfc822')) { // not allowed for attached files
314319
$contentType = 'application/octet-stream';
315320
} elseif (!strcasecmp($contentType, 'image/svg')) { // Troublesome for some mailers...
@@ -365,6 +370,7 @@ public function build()
365370
$tmp->addPart($value);
366371
}
367372
}
373+
368374
$alt->setContentType('text/html', 'UTF-8')
369375
->setEncoding(preg_match('#[^\n]{990}#', $mail->htmlBody)
370376
? self::ENCODING_QUOTED_PRINTABLE

src/Mail/MimePart.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public function setHeader(string $name, $value, bool $append = false)
6363
if (!$append) {
6464
unset($this->headers[$name]);
6565
}
66-
6766
} elseif (is_array($value)) { // email
6867
$tmp = &$this->headers[$name];
6968
if (!$append || !is_array($tmp)) {
@@ -78,17 +77,19 @@ public function setHeader(string $name, $value, bool $append = false)
7877
} elseif (preg_match('#[\r\n]#', $recipient)) {
7978
throw new Nette\InvalidArgumentException('Name must not contain line separator.');
8079
}
80+
8181
Nette\Utils\Validators::assert($email, 'email', "header '$name'");
8282
$tmp[$email] = $recipient;
8383
}
84-
8584
} else {
8685
$value = (string) $value;
8786
if (!Strings::checkEncoding($value)) {
8887
throw new Nette\InvalidArgumentException('Header is not valid UTF-8 string.');
8988
}
89+
9090
$this->headers[$name] = preg_replace('#[\r\n]+#', ' ', $value);
9191
}
92+
9293
return $this;
9394
}
9495

@@ -131,8 +132,10 @@ public function getEncodedHeader(string $name): ?string
131132
$s .= self::encodeSequence($name, $offset, self::SEQUENCE_WORD);
132133
$email = " <$email>";
133134
}
135+
134136
$s .= self::append($email . ',', $offset);
135137
}
138+
136139
return ltrim(substr($s, 0, -1)); // last comma
137140

138141
} elseif (preg_match('#^(\S+; (?:file)?name=)"(.*)"$#D', $this->headers[$name], $m)) { // Content-Disposition
@@ -230,8 +233,10 @@ public function getEncodedMessage(): string
230233
if ($this->parts && $name === 'Content-Type') {
231234
$output .= ';' . self::EOL . "\tboundary=\"$boundary\"";
232235
}
236+
233237
$output .= self::EOL;
234238
}
239+
235240
$output .= self::EOL;
236241

237242
$body = $this->body;
@@ -264,9 +269,11 @@ public function getEncodedMessage(): string
264269
if (substr($output, -strlen(self::EOL)) !== self::EOL) {
265270
$output .= self::EOL;
266271
}
272+
267273
foreach ($this->parts as $part) {
268274
$output .= '--' . $boundary . self::EOL . $part->getEncodedMessage() . self::EOL;
269275
}
276+
270277
$output .= '--' . $boundary . '--';
271278
}
272279

@@ -289,6 +296,7 @@ private static function encodeSequence(string $s, int &$offset = 0, int $type =
289296
if ($type && preg_match('#[^ a-zA-Z0-9!\#$%&\'*+/?^_`{|}~-]#', $s)) { // RFC 2822 atext except =
290297
return self::append('"' . addcslashes($s, '"\\') . '"', $offset);
291298
}
299+
292300
return self::append($s, $offset);
293301
}
294302

@@ -309,6 +317,7 @@ private static function encodeSequence(string $s, int &$offset = 0, int $type =
309317
if ($type === self::SEQUENCE_VALUE) {
310318
$s = '"' . $s . '"';
311319
}
320+
312321
$s = str_replace("\n ", "\n\t", $s);
313322
return $o . $s;
314323
}
@@ -320,6 +329,7 @@ private static function append(string $s, int &$offset = 0): string
320329
$offset = 1;
321330
$s = self::EOL . "\t" . $s;
322331
}
332+
323333
$offset += strlen($s);
324334
return $s;
325335
}

src/Mail/SendmailMailer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function send(Message $mail): void
4343
if (!function_exists('mail')) {
4444
throw new SendException('Unable to send email: mail() has been disabled.');
4545
}
46+
4647
$tmp = clone $mail;
4748
$tmp->setHeader('Subject', null);
4849
$tmp->setHeader('To', null);
@@ -61,6 +62,7 @@ public function send(Message $mail): void
6162
if ($this->commandArgs) {
6263
$args[] = $this->commandArgs;
6364
}
65+
6466
$res = Nette\Utils\Callback::invokeSafe('mail', $args, function (string $message) use (&$info): void {
6567
$info = ": $message";
6668
});

src/Mail/SmtpMailer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function __construct(array $options = [])
6464
$this->host = ini_get('SMTP');
6565
$this->port = (int) ini_get('smtp_port');
6666
}
67+
6768
$this->username = $options['username'] ?? '';
6869
$this->password = $options['password'] ?? '';
6970
$this->secure = $options['secure'] ?? '';
@@ -76,6 +77,7 @@ public function __construct(array $options = [])
7677
if (!$this->port) {
7778
$this->port = $this->secure === 'ssl' ? 465 : 25;
7879
}
80+
7981
$this->persistent = !empty($options['persistent']);
8082
if (isset($options['clientHost'])) {
8183
$this->clientHost = $options['clientHost'];
@@ -141,6 +143,7 @@ public function send(Message $mail): void
141143
if ($this->connection) {
142144
$this->disconnect();
143145
}
146+
144147
throw $e;
145148
}
146149
}
@@ -162,6 +165,7 @@ protected function connect(): void
162165
if (!$this->connection) {
163166
throw new SmtpException($error ?: error_get_last()['message'], $errno);
164167
}
168+
165169
stream_set_timeout($this->connection, $this->timeout, 0);
166170
$this->read(); // greeting
167171

@@ -175,12 +179,12 @@ protected function connect(): void
175179
)) {
176180
throw new SmtpException('Unable to connect via TLS.');
177181
}
182+
178183
$this->write("EHLO $this->clientHost");
179184
$ehloResponse = $this->read();
180185
if ((int) $ehloResponse !== 250) {
181186
throw new SmtpException('SMTP server did not accept EHLO with error: ' . trim($ehloResponse));
182187
}
183-
184188
} else {
185189
$this->write("EHLO $this->clientHost");
186190
$ehloResponse = $this->read();
@@ -247,6 +251,7 @@ protected function read(): string
247251
break;
248252
}
249253
}
254+
250255
return $s;
251256
}
252257
}

0 commit comments

Comments
 (0)