File: select-email.php

package info (click to toggle)
adminer 5.4.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,828 kB
  • sloc: php: 28,768; javascript: 1,188; xml: 107; makefile: 48; sh: 3
file content (461 lines) | stat: -rw-r--r-- 17,913 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
<?php

/** Allow sending e-mails to addresses in table
* @link https://www.adminer.org/plugins/#use
* @author Jakub Vrana, https://www.vrana.cz/
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerSelectEmail extends Adminer\Plugin {

	function selectEmailPrint($emailFields, $columns) {
		if ($emailFields) {
			Adminer\print_fieldset("email", $this->lang('E-mail'), $_POST["email_append"]);
			echo "<div>";
			echo Adminer\script("qsl('div').onkeydown = partialArg(bodyKeydown, 'email');");
			echo Adminer\script("function emailFileChange() { const el = this.cloneNode(true); this.onchange = null; el.onchange = emailFileChange; el.value = ''; this.parentNode.appendChild(el); }");
			echo "<p>" . $this->lang('From') . ": <input name='email_from' value='" . Adminer\h($_POST ? $_POST["email_from"] : $_COOKIE["adminer_email"]) . "'>\n";
			echo $this->lang('Subject') . ": <input name='email_subject' value='" . Adminer\h($_POST["email_subject"]) . "'>\n";
			echo "<p><textarea name='email_message' rows='15' cols='75'>" . Adminer\h($_POST["email_message"] . ($_POST["email_append"] ? '{$' . "$_POST[email_addition]}" : "")) . "</textarea>\n";
			echo "<p>" . Adminer\script("qsl('p').onkeydown = partialArg(bodyKeydown, 'email_append');", "") . Adminer\html_select("email_addition", $columns, $_POST["email_addition"])
				. " <input type='submit' name='email_append' value='" . Adminer\lang('Insert') . "'>\n"; //! JavaScript
			echo "<p>" . $this->lang('Attachments') . ": <input type='file' name='email_files[]'>" . Adminer\script("qsl('input').onchange = emailFileChange;");
			echo "<p>" . (count($emailFields) == 1 ? Adminer\input_hidden("email_field", key($emailFields)) : Adminer\html_select("email_field", $emailFields));
			echo "<input type='submit' name='email' value='" . $this->lang('Send') . "'>" . Adminer\confirm();
			echo "</div>\n";
			echo "</div></fieldset>\n";
			return true;
		}
	}

	function selectEmailProcess($where, $foreignKeys) {
		if ($_POST["email_append"]) {
			return true;
		}
		if ($_POST["email"]) {
			$sent = 0;
			if ($_POST["all"] || $_POST["check"]) {
				$field = Adminer\idf_escape($_POST["email_field"]);
				$subject = $_POST["email_subject"];
				$message = $_POST["email_message"];
				preg_match_all('~\{\$([a-z0-9_]+)\}~i', "$subject.$message", $matches); // allows {$name} in subject or message
				$rows = Adminer\get_rows(
					"SELECT DISTINCT $field" . ($matches[1] ? ", " . implode(", ", array_map('Adminer\idf_escape', array_unique($matches[1]))) : "") . " FROM " . Adminer\table($_GET["select"])
					. " WHERE $field IS NOT NULL AND $field != ''"
					. ($where ? " AND " . implode(" AND ", $where) : "")
					. ($_POST["all"] ? "" : " AND ((" . implode(") OR (", array_map('Adminer\where_check', (array) $_POST["check"])) . "))")
				);
				$fields = Adminer\fields($_GET["select"]);
				foreach (Adminer\adminer()->rowDescriptions($rows, $foreignKeys) as $row) {
					$replace = array('{\\' => '{'); // allow literal {$name}
					foreach ($matches[1] as $val) {
						$replace['{$' . "$val}"] = Adminer\adminer()->editVal($row[$val], $fields[$val]);
					}
					$email = $row[$_POST["email_field"]];
					if (Adminer\is_mail($email) && $this->sendMail($email, strtr($subject, $replace), strtr($message, $replace), $_POST["email_from"], $_FILES["email_files"])) {
						$sent++;
					}
				}
			}
			Adminer\cookie("adminer_email", $_POST["email_from"]);
			Adminer\redirect(Adminer\remove_from_uri(), $this->lang('%d e-mail(s) have been sent.', $sent));
		}
		return false;
	}

	/** Encode e-mail header in UTF-8 */
	private function emailHeader($header) {
		// iconv_mime_encode requires iconv, imap_8bit requires IMAP extension
		return "=?UTF-8?B?" . base64_encode($header) . "?="; //! split long lines
	}

	/** Send e-mail in UTF-8
	* @param array{error?:list<int>, type?:list<string>, name?:list<string>, tmp_name?:list<string>} $files
	*/
	private function sendMail($email, $subject, $message, $from = "", array $files = array()) {
		$eol = PHP_EOL;
		$message = str_replace("\n", $eol, wordwrap(str_replace("\r", "", "$message\n")));
		$boundary = uniqid("boundary");
		$attachments = "";
		foreach ((array) $files["error"] as $key => $val) {
			if (!$val) {
				$attachments .= "--$boundary$eol"
					. "Content-Type: " . str_replace("\n", "", $files["type"][$key]) . $eol
					. "Content-Disposition: attachment; filename=\"" . preg_replace('~["\n]~', '', $files["name"][$key]) . "\"$eol"
					. "Content-Transfer-Encoding: base64$eol$eol"
					. chunk_split(base64_encode(file_get_contents($files["tmp_name"][$key])), 76, $eol) . $eol
				;
			}
		}
		$beginning = "";
		$headers = "Content-Type: text/plain; charset=utf-8$eol" . "Content-Transfer-Encoding: 8bit";
		if ($attachments) {
			$attachments .= "--$boundary--$eol";
			$beginning = "--$boundary$eol$headers$eol$eol";
			$headers = "Content-Type: multipart/mixed; boundary=\"$boundary\"";
		}
		$headers .= $eol . "MIME-Version: 1.0$eol" . "X-Mailer: Adminer Editor"
			. ($from ? $eol . "From: " . str_replace("\n", "", $from) : "") //! should escape display name
		;
		return mail($email, $this->emailHeader($subject), $beginning . $message . $attachments, $headers);
	}

	protected $translations = array(
		'ar' => array(
			'E-mail' => 'البريد الإلكتروني',
			'From' => 'من',
			'Subject' => 'الموضوع',
			'Send' => 'إرسال',
			'%d e-mail(s) have been sent.' => 'تم إرسال %d رسالة.',
			'Attachments' => 'ملفات مرفقة',
		),
		'bg' => array(
			'E-mail' => 'E-mail',
			'From' => 'От',
			'Subject' => 'Тема',
			'Attachments' => 'Прикачени',
			'Send' => 'Изпращане',
			'%d e-mail(s) have been sent.' => array('%d писмо беше изпратено.', '%d писма бяха изпратени.'),
		),
		'bn' => array(
			'E-mail' => '​​ই-মেইল',
			'From' => 'থেকে',
			'Subject' => 'বিষয়',
			'Send' => 'পাঠান',
			'%d e-mail(s) have been sent.' => array('%d ইমেইল(গুলি) পাঠানো হয়েছে।', '%d ইমেইল(গুলি) পাঠানো হয়েছে।'),
			'Attachments' => 'সংযুক্তিগুলো',
		),
		'bs' => array(
			'E-mail' => 'El. pošta',
			'From' => 'Od',
			'Subject' => 'Naslov',
			'Attachments' => 'Prilozi',
			'Send' => 'Pošalji',
			'%d e-mail(s) have been sent.' => array('%d poruka el. pošte je poslata.', '%d poruke el. pošte su poslate.', '%d poruka el. pošte je poslato.'),
		),
		'ca' => array(
			'E-mail' => 'Correu electrònic',
			'From' => 'De',
			'Subject' => 'Assumpte',
			'Send' => 'Envia',
			'%d e-mail(s) have been sent.' => array('S\'ha enviat %d correu electrònic.', 'S\'han enviat %d correus electrònics.'),
			'Attachments' => 'Adjuncions',
		),
		'cs' => array(
			'' => 'Umožňuje posílat e-maily na adresy v tabulce',
			'E-mail' => 'E-mail',
			'From' => 'Odesílatel',
			'Subject' => 'Předmět',
			'Attachments' => 'Přílohy',
			'Send' => 'Odeslat',
			'%d e-mail(s) have been sent.' => array('Byl odeslán %d e-mail.', 'Byly odeslány %d e-maily.', 'Bylo odesláno %d e-mailů.'),
		),
		'da' => array(
			'E-mail' => 'E-mail',
			'From' => 'Fra',
			'Subject' => 'Titel',
			'Attachments' => 'Vedhæft',
			'Send' => 'Send',
			'%d e-mail(s) have been sent.' => array('%d email sendt.', '%d emails sendt.'),
		),
		'de' => array(
			'E-mail' => 'E-Mail',
			'From' => 'Von',
			'Subject' => 'Betreff',
			'Send' => 'Abschicken',
			'%d e-mail(s) have been sent.' => array('%d E-Mail abgeschickt.', '%d E-Mails abgeschickt.'),
			'Attachments' => 'Anhänge',
		),
		'el' => array(
			'E-mail' => 'E-mail',
			'From' => 'Από',
			'Subject' => 'Θέμα',
			'Attachments' => 'Συνημμένα',
			'Send' => 'Αποστολή',
			'%d e-mail(s) have been sent.' => array('%d e-mail απεστάλη.', '%d e-mail απεστάλησαν.'),
		),
		'en' => array(
			'%d e-mail(s) have been sent.' => array('%d e-mail has been sent.', '%d e-mails have been sent.'),
		),
		'es' => array(
			'E-mail' => 'Email',
			'From' => 'De',
			'Subject' => 'Asunto',
			'Send' => 'Enviar',
			'%d e-mail(s) have been sent.' => array('%d email enviado.', '%d emails enviados.'),
			'Attachments' => 'Adjuntos',
		),
		'et' => array(
			'E-mail' => 'E-post',
			'From' => 'Kellelt',
			'Subject' => 'Pealkiri',
			'Send' => 'Saada',
			'%d e-mail(s) have been sent.' => 'Saadetud kirju: %d.',
			'Attachments' => 'Manused',
		),
		'fa' => array(
			'E-mail' => 'پست الکترونیک',
			'From' => 'فرستنده',
			'Subject' => 'موضوع',
			'Attachments' => 'پیوست ها',
			'Send' => 'ارسال',
			'%d e-mail(s) have been sent.' => array('%d ایمیل ارسال شد.', '%d ایمیل ارسال شد.'),
		),
		'fi' => array(
			'E-mail' => 'S-posti',
			'From' => 'Lähettäjä',
			'Subject' => 'Aihe',
			'Attachments' => 'Liitteet',
			'Send' => 'Lähetä',
			'%d e-mail(s) have been sent.' => array('% sähköpostiviestiä lähetetty.', '% sähköpostiviestiä lähetetty.'),
		),
		'fr' => array(
			'E-mail' => 'Courriel',
			'From' => 'De',
			'Subject' => 'Sujet',
			'Send' => 'Envoyer',
			'%d e-mail(s) have been sent.' => array('%d message a été envoyé.', '%d messages ont été envoyés.'),
			'Attachments' => 'Pièces jointes',
		),
		'gl' => array(
			'E-mail' => 'Email',
			'From' => 'De',
			'Subject' => 'Asunto',
			'Send' => 'Enviar',
			'%d e-mail(s) have been sent.' => array('%d email enviado.', '%d emails enviados.'),
			'Attachments' => 'Adxuntos',
		),
		'he' => array(
			'E-mail' => 'דוא"ל',
			'From' => 'מ:',
			'Subject' => 'נושא',
			'Send' => 'שלח',
			'%d e-mail(s) have been sent.' => '%d הודעות דוא"ל נשלחו',
			'Attachments' => 'קבצים מצורפים',
		),
		'hu' => array(
			'E-mail' => 'E-mail',
			'From' => 'Feladó',
			'Subject' => 'Tárgy',
			'Send' => 'Küldés',
			'%d e-mail(s) have been sent.' => array('%d e-mail elküldve.', '%d e-mail elküldve.', '%d e-mail elküldve.'),
			'Attachments' => 'Csatolmány',
		),
		'id' => array(
			'E-mail' => 'Surel',
			'From' => 'Dari',
			'Subject' => 'Judul',
			'Attachments' => 'Lampiran',
			'Send' => 'Kirim',
			'%d e-mail(s) have been sent.' => '%d surel berhasil dikirim.',
		),
		'it' => array(
			'E-mail' => 'E-mail',
			'From' => 'Da',
			'Subject' => 'Oggetto',
			'Send' => 'Invia',
			'%d e-mail(s) have been sent.' => array('%d e-mail inviata.', '%d e-mail inviate.'),
			'Attachments' => 'Allegati',
		),
		'ja' => array(
			'' => 'テーブルに含まれるアドレスにメールを送信',
			'E-mail' => 'メール',
			'From' => '差出人',
			'Subject' => '題名',
			'Send' => '送信',
			'%d e-mail(s) have been sent.' => '%d メールを送信しました。',
			'Attachments' => '添付ファイル',
		),
		'ka' => array(
			'E-mail' => 'ელ. ფოსტა',
			'From' => 'ავტორი:',
			'Subject' => 'თემა',
			'Send' => 'გაგზავნა',
			'%d e-mail(s) have been sent.' => 'გაიგზავნა %d წერილი.',
			'Attachments' => 'მიმაგრებული ფაილები',
		),
		'ko' => array(
			'%d e-mail(s) have been sent.' => '%d개 메일을 보냈습니다.',
			'Attachments' => '첨부 파일',
			'E-mail' => '메일',
			'From' => '보낸 사람',
			'Send' => '보내기',
			'Subject' => '제목',
		),
		'lt' => array(
			'E-mail' => 'El. paštas',
			'From' => 'Nuo',
			'Subject' => 'Antraštė',
			'Attachments' => 'Priedai',
			'Send' => 'Siųsti',
			'%d e-mail(s) have been sent.' => array('Išsiųstas %d laiškas.', 'Išsiųsti %d laiškai.', 'Išsiųsta %d laiškų.'),
		),
		'lv' => array(
			'E-mail' => 'Epasts',
			'From' => 'No',
			'Subject' => 'Tēma',
			'Send' => 'Sūtīt',
			'%d e-mail(s) have been sent.' => array('Nosūtīts %d epasts.', 'Nosūtīti %d epasti.', 'Nosūtīti %d epasti.'),
			'Attachments' => 'Pielikumi',
		),
		'ms' => array(
			'E-mail' => 'Emel',
			'From' => 'Dari',
			'Subject' => 'Subjek',
			'Attachments' => 'Lampiran',
			'Send' => 'Hantar',
			'%d e-mail(s) have been sent.' => '%d emel telah dihantar.',
		),
		'nl' => array(
			'E-mail' => 'E-mail',
			'From' => 'Van',
			'Subject' => 'Onderwerp',
			'Send' => 'Verzenden',
			'%d e-mail(s) have been sent.' => array('%d e-mail verzonden.', '%d e-mails verzonden.'),
			'Attachments' => 'Bijlagen',
		),
		'no' => array(
			'E-mail' => 'E-post',
			'From' => 'Fra',
			'Subject' => 'Tittel',
			'Attachments' => 'Vedlegg',
			'Send' => 'Send',
			'%d e-mail(s) have been sent.' => array('%d epost sendt.', '%d eposter sendt.'),
		),
		'pl' => array(
			'E-mail' => 'E-mail',
			'From' => 'Nadawca',
			'Subject' => 'Temat',
			'Attachments' => 'Załączniki',
			'Send' => 'Wyślij',
			'%d e-mail(s) have been sent.' => array('Wysłano %d e-mail.', 'Wysłano %d e-maile.', 'Wysłano %d e-maili.'),
		),
		'pt-br' => array(
			'E-mail' => 'E-mail',
			'From' => 'De',
			'Subject' => 'Assunto',
			'Send' => 'Enviar',
			'%d e-mail(s) have been sent.' => array('%d email foi enviado.', '%d emails foram enviados.'),
			'Attachments' => 'Anexos',
		),
		'pt' => array(
			'E-mail' => 'E-mail',
			'From' => 'De',
			'Subject' => 'Assunto',
			'Send' => 'Enviar',
			'%d e-mail(s) have been sent.' => array('%d email enviado.', '%d emails enviados.'),
			'Attachments' => 'Anexos',
		),
		'ro' => array(
			'E-mail' => 'Poșta electronică',
			'From' => 'De la',
			'Subject' => 'Pentru',
			'Send' => 'Trimite',
			'%d e-mail(s) have been sent.' => array('A fost trimis %d mail.', 'Au fost trimise %d mail-uri.'),
			'Attachments' => 'Fișiere atașate',
		),
		'ru' => array(
			'E-mail' => 'Эл. почта',
			'From' => 'От',
			'Subject' => 'Тема',
			'Send' => 'Послать',
			'%d e-mail(s) have been sent.' => array('Было отправлено %d письмо.', 'Было отправлено %d письма.', 'Было отправлено %d писем.'),
			'Attachments' => 'Прикреплённые файлы',
		),
		'sk' => array(
			'E-mail' => 'E-mail',
			'From' => 'Odosielateľ',
			'Subject' => 'Predmet',
			'Send' => 'Odoslať',
			'%d e-mail(s) have been sent.' => array('Bol odoslaný %d e-mail.', 'Boli odoslané %d e-maily.', 'Bolo odoslaných %d e-mailov.'),
			'Attachments' => 'Prílohy',
		),
		'sl' => array(
			'E-mail' => 'E-mail',
			'From' => 'Od',
			'Subject' => 'Zadeva',
			'Attachments' => 'Priponke',
			'Send' => 'Pošlji',
			'%d e-mail(s) have been sent.' => array('Poslan je %d e-mail.', 'Poslana sta %d e-maila.', 'Poslani so %d e-maili.', 'Poslanih je %d e-mailov.'),
		),
		'sr' => array(
			'E-mail' => 'Ел. пошта',
			'From' => 'Од',
			'Subject' => 'Наслов',
			'Attachments' => 'Прилози',
			'Send' => 'Пошаљи',
			'%d e-mail(s) have been sent.' => array('%d порука ел. поште је послата.', '%d поруке ел. поште су послате.', '%d порука ел. поште је послато.'),
		),
		'sv' => array(
			'E-mail' => 'Email',
			'From' => 'Från',
			'Subject' => 'Ämne',
			'Attachments' => 'Bilagor',
			'Send' => 'Skicka',
			'%d e-mail(s) have been sent.' => array('%d email har blivit skickat.', '%d email har blivit skickade.'),
		),
		'ta' => array(
			'E-mail' => 'மின்ன‌ஞ்ச‌ல்',
			'From' => 'அனுப்புனர்',
			'Subject' => 'பொருள்',
			'Send' => 'அனுப்பு',
			'%d e-mail(s) have been sent.' => array('%d மின்ன‌ஞ்ச‌ல் அனுப்ப‌ப‌ட்ட‌து.', '%d மின்ன‌ஞ்ச‌ல்க‌ள் அனுப்ப‌ப்ப‌ட்ட‌ன‌.'),
			'Attachments' => 'இணைப்புக‌ள்',
		),
		'th' => array(
			'E-mail' => 'อีเมล์',
			'From' => 'จาก',
			'Subject' => 'หัวข้อ',
			'Send' => 'ส่ง',
			'%d e-mail(s) have been sent.' => 'มี %d อีเมล์ ถูกส่งออกแล้ว.',
			'Attachments' => 'ไฟล์แนบ',
		),
		'tr' => array(
			'E-mail' => 'E-posta',
			'From' => 'Gönderen',
			'Subject' => 'Konu',
			'Attachments' => 'Ekler',
			'Send' => 'Gönder',
			'%d e-mail(s) have been sent.' => array('%d e-posta gönderildi.', '%d adet e-posta gönderildi.'),
		),
		'uk' => array(
			'E-mail' => 'E-mail',
			'From' => 'Від',
			'Subject' => 'Заголовок',
			'Attachments' => 'Додатки',
			'Send' => 'Надіслати',
			'%d e-mail(s) have been sent.' => array('Було надіслано %d повідомлення.', 'Було надіслано %d повідомлення.', 'Було надіслано %d повідомлень.'),
		),
		'uz' => array(
			'E-mail' => 'E-pochta',
			'From' => 'Kimdan',
			'Subject' => 'Mavzu',
			'Attachments' => 'Ilovalar',
			'Send' => 'Yuborish',
			'%d e-mail(s) have been sent.' => array('%d e-pochta yuborildi.', '%d e-pochtalar yuborildi.'),
		),
		'vi' => array(
			'E-mail' => 'Địa chỉ email',
			'From' => 'Người gửi',
			'Subject' => 'Chủ đề',
			'Attachments' => 'Đính kèm',
			'Send' => 'Gửi',
			'%d e-mail(s) have been sent.' => '%d thư đã gửi.',
		),
		'zh-tw' => array(
			'E-mail' => '電子郵件',
			'From' => '來自',
			'Subject' => '主旨',
			'Attachments' => '附件',
			'Send' => '寄出',
			'%d e-mail(s) have been sent.' => '已寄出 %d 封郵件。',
		),
		'zh' => array(
			'E-mail' => '电子邮件',
			'From' => '来自',
			'Subject' => '主题',
			'Attachments' => '附件',
			'Send' => '发送',
			'%d e-mail(s) have been sent.' => '%d 封邮件已发送。'),
	);
}