]> git.mxchange.org Git - friendica.git/blob - include/enotify.php
Merge remote-tracking branch 'upstream/master'
[friendica.git] / include / enotify.php
1 <?php
2
3 require_once('include/email.php');
4
5 function notification($params) {
6
7         logger('notification: entry', LOGGER_DEBUG);
8
9         $a = get_app();
10
11         // from here on everything is in the recipients language
12
13         push_lang($params['language']);
14
15
16         $banner = t('Friendica Notification');
17         $product = FRIENDICA_PLATFORM;
18         $siteurl = $a->get_baseurl(true);
19         $thanks = t('Thank You,');
20         $sitename = $a->config['sitename'];
21         $site_admin = sprintf( t('%s Administrator'), $sitename);
22
23         $sender_name = $product;
24         $hostname = $a->get_hostname();
25         if(strpos($hostname,':'))
26                 $hostname = substr($hostname,0,strpos($hostname,':'));
27
28         $sender_email = t('noreply') . '@' . $hostname;
29         $additional_mail_header = "";
30
31         $additional_mail_header .= "Precedence: list\n";
32         $additional_mail_header .= "X-Friendica-Host: ".$hostname."\n";
33         $additional_mail_header .= "X-Friendica-Platform: ".FRIENDICA_PLATFORM."\n";
34         $additional_mail_header .= "X-Friendica-Version: ".FRIENDICA_VERSION."\n";
35         $additional_mail_header .= "List-ID: <notification.".$hostname.">\n";
36         $additional_mail_header .= "List-Archive: <".$a->get_baseurl()."/notifications/system>\n";
37
38         if(array_key_exists('item',$params)) {
39                 $title = $params['item']['title'];
40                 $body = $params['item']['body'];
41         }
42         else {
43                 $title = $body = '';
44         }
45
46         // e.g. "your post", "David's photo", etc.
47         $possess_desc = t('%s <!item_type!>');
48
49         if($params['type'] == NOTIFY_MAIL) {
50
51                 $subject =      sprintf( t('[Friendica:Notify] New mail received at %s'),$sitename);
52
53                 $preamble = sprintf( t('%1$s sent you a new private message at %2$s.'),$params['source_name'],$sitename);
54                 $epreamble = sprintf( t('%1$s sent you %2$s.'),'[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]', '[url=$itemlink]' . t('a private message') . '[/url]');
55                 $sitelink = t('Please visit %s to view and/or reply to your private messages.');
56                 $tsitelink = sprintf( $sitelink, $siteurl . '/message/' . $params['item']['id'] );
57                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '/message/' . $params['item']['id'] . '">' . $sitename . '</a>');
58                 $itemlink = $siteurl . '/message/' . $params['item']['id'];
59         }
60
61         if($params['type'] == NOTIFY_COMMENT) {
62 //              logger("notification: params = " . print_r($params, true), LOGGER_DEBUG);
63
64                 $parent_id = $params['parent'];
65
66                 $p = q("SELECT `ignored` FROM `thread` WHERE `iid` = %d AND `uid` = %d LIMIT 1",
67                         intval($parent_id),
68                         intval($params['uid'])
69                 );
70                 if ($p AND count($p) AND ($p[0]["ignored"])) {
71                         logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG);
72                         return;
73                 }
74
75                 // Check to see if there was already a tag notify or comment notify for this post.
76                 // If so don't create a second notification
77
78                 $p = null;
79                 $p = q("select id from notify where (type = %d or type = %d or type = %d) and link = '%s' and uid = %d limit 1",
80                         intval(NOTIFY_TAGSELF),
81                         intval(NOTIFY_COMMENT),
82                         intval(NOTIFY_SHARE),
83                         dbesc($params['link']),
84                         intval($params['uid'])
85                 );
86                 if($p and count($p)) {
87                         pop_lang();
88                         return;
89                 }
90
91
92                 // if it's a post figure out who's post it is.
93
94                 $p = null;
95
96                 if($params['otype'] === 'item' && $parent_id) {
97                         $p = q("select * from item where id = %d and uid = %d limit 1",
98                                 intval($parent_id),
99                                 intval($params['uid'])
100                         );
101                 }
102
103                 $item_post_type = item_post_type($p[0]);
104                 //$possess_desc = str_replace('<!item_type!>',$possess_desc);
105
106                 // "a post"
107                 $dest_str = sprintf(t('%1$s commented on [url=%2$s]a %3$s[/url]'),
108                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
109                                                                 $itemlink,
110                                                                 $item_post_type);
111
112                 // "George Bull's post"
113                 if($p)
114                         $dest_str = sprintf(t('%1$s commented on [url=%2$s]%3$s\'s %4$s[/url]'),
115                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
116                                                 $itemlink,
117                                                 $p[0]['author-name'],
118                                                 $item_post_type);
119
120                 // "your post"
121                 if($p[0]['owner-name'] == $p[0]['author-name'] && $p[0]['wall'])
122                         $dest_str = sprintf(t('%1$s commented on [url=%2$s]your %3$s[/url]'),
123                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
124                                                                 $itemlink,
125                                                                 $item_post_type);
126
127                 // Some mail softwares relies on subject field for threading.
128                 // So, we cannot have different subjects for notifications of the same thread.
129                 // Before this we have the name of the replier on the subject rendering
130                 // differents subjects for messages on the same thread.
131
132                 $subject = sprintf( t('[Friendica:Notify] Comment to conversation #%1$d by %2$s'), $parent_id, $params['source_name']);
133                 $preamble = sprintf( t('%s commented on an item/conversation you have been following.'), $params['source_name']);
134                 $epreamble = $dest_str;
135
136                 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
137                 $tsitelink = sprintf( $sitelink, $siteurl );
138                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
139                 $itemlink =  $params['link'];
140         }
141
142         if($params['type'] == NOTIFY_WALL) {
143                 $subject = sprintf( t('[Friendica:Notify] %s posted to your profile wall') , $params['source_name']);
144
145                 $preamble = sprintf( t('%1$s posted to your profile wall at %2$s') , $params['source_name'], $sitename);
146
147                 $epreamble = sprintf( t('%1$s posted to [url=%2$s]your wall[/url]') ,
148                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
149                                                                 $params['link']);
150
151                 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
152                 $tsitelink = sprintf( $sitelink, $siteurl );
153                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
154                 $itemlink =  $params['link'];
155         }
156
157         if($params['type'] == NOTIFY_TAGSELF) {
158                 $subject =      sprintf( t('[Friendica:Notify] %s tagged you') , $params['source_name']);
159                 $preamble = sprintf( t('%1$s tagged you at %2$s') , $params['source_name'], $sitename);
160                 $epreamble = sprintf( t('%1$s [url=%2$s]tagged you[/url].') ,
161                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
162                                                                 $params['link']);
163
164                 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
165                 $tsitelink = sprintf( $sitelink, $siteurl );
166                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
167                 $itemlink =  $params['link'];
168         }
169
170         if($params['type'] == NOTIFY_SHARE) {
171                 $subject =      sprintf( t('[Friendica:Notify] %s shared a new post') , $params['source_name']);
172                 $preamble = sprintf( t('%1$s shared a new post at %2$s') , $params['source_name'], $sitename);
173                 $epreamble = sprintf( t('%1$s [url=%2$s]shared a post[/url].') ,
174                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
175                                                                 $params['link']);
176
177                 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
178                 $tsitelink = sprintf( $sitelink, $siteurl );
179                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
180                 $itemlink =  $params['link'];
181         }
182
183         if($params['type'] == NOTIFY_POKE) {
184
185                 $subject =      sprintf( t('[Friendica:Notify] %1$s poked you') , $params['source_name']);
186                 $preamble = sprintf( t('%1$s poked you at %2$s') , $params['source_name'], $sitename);
187                 $epreamble = sprintf( t('%1$s [url=%2$s]poked you[/url].') ,
188                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
189                                                                 $params['link']);
190
191                 $subject = str_replace('poked', t($params['activity']), $subject);
192                 $preamble = str_replace('poked', t($params['activity']), $preamble);
193                 $epreamble = str_replace('poked', t($params['activity']), $epreamble);
194
195                 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
196                 $tsitelink = sprintf( $sitelink, $siteurl );
197                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
198                 $itemlink =  $params['link'];
199         }
200
201         if($params['type'] == NOTIFY_TAGSHARE) {
202                 $subject =      sprintf( t('[Friendica:Notify] %s tagged your post') , $params['source_name']);
203                 $preamble = sprintf( t('%1$s tagged your post at %2$s') , $params['source_name'], $sitename);
204                 $epreamble = sprintf( t('%1$s tagged [url=%2$s]your post[/url]') ,
205                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
206                                                                 $itemlink);
207
208                 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
209                 $tsitelink = sprintf( $sitelink, $siteurl );
210                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
211                 $itemlink =  $params['link'];
212         }
213
214         if($params['type'] == NOTIFY_INTRO) {
215                 $subject = sprintf( t('[Friendica:Notify] Introduction received'));
216                 $preamble = sprintf( t('You\'ve received an introduction from \'%1$s\' at %2$s'), $params['source_name'], $sitename);
217                 $epreamble = sprintf( t('You\'ve received [url=%1$s]an introduction[/url] from %2$s.'),
218                                                                 $itemlink,
219                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
220                 $body = sprintf( t('You may visit their profile at %s'),$params['source_link']);
221
222                 $sitelink = t('Please visit %s to approve or reject the introduction.');
223                 $tsitelink = sprintf( $sitelink, $siteurl );
224                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
225                 $itemlink =  $params['link'];
226         }
227
228         if($params['type'] == NOTIFY_SUGGEST) {
229                 $subject = sprintf( t('[Friendica:Notify] Friend suggestion received'));
230                 $preamble = sprintf( t('You\'ve received a friend suggestion from \'%1$s\' at %2$s'), $params['source_name'], $sitename);
231                 $epreamble = sprintf( t('You\'ve received [url=%1$s]a friend suggestion[/url] for %2$s from %3$s.'),
232                                                                         $itemlink,
233                                                                         '[url=' . $params['item']['url'] . ']' . $params['item']['name'] . '[/url]',
234                                                                         '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
235
236                 $body = t('Name:') . ' ' . $params['item']['name'] . "\n";
237                 $body .= t('Photo:') . ' ' . $params['item']['photo'] . "\n";
238                 $body .= sprintf( t('You may visit their profile at %s'),$params['item']['url']);
239
240                 $sitelink = t('Please visit %s to approve or reject the suggestion.');
241                 $tsitelink = sprintf( $sitelink, $siteurl );
242                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
243                 $itemlink =  $params['link'];
244         }
245
246         if($params['type'] == NOTIFY_CONFIRM) {
247         }
248
249         if($params['type'] == NOTIFY_SYSTEM) {
250
251         }
252
253         $h = array(
254                 'params'    => $params,
255                 'subject'   => $subject,
256                 'preamble'  => $preamble,
257                 'epreamble' => $epreamble,
258                 'body'      => $body,
259                 'sitelink'  => $sitelink,
260                 'tsitelink' => $tsitelink,
261                 'hsitelink' => $hsitelink,
262                 'itemlink'  => $itemlink
263         );
264
265         call_hooks('enotify',$h);
266
267         $subject   = $h['subject'];
268         $preamble  = $h['preamble'];
269         $epreamble = $h['epreamble'];
270         $body      = $h['body'];
271         $sitelink  = $h['sitelink'];
272         $tsitelink = $h['tsitelink'];
273         $hsitelink = $h['hsitelink'];
274         $itemlink  = $h['itemlink'];
275
276
277         require_once('include/html2bbcode.php');
278
279         do {
280                 $dups = false;
281                 $hash = random_string();
282         $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1",
283                         dbesc($hash));
284                 if(count($r))
285                         $dups = true;
286         } while($dups == true);
287
288
289         $datarray = array();
290         $datarray['hash']  = $hash;
291         $datarray['name']  = $params['source_name'];
292         $datarray['url']   = $params['source_link'];
293         $datarray['photo'] = $params['source_photo'];
294         $datarray['date']  = datetime_convert();
295         $datarray['uid']   = $params['uid'];
296         $datarray['link']  = $itemlink;
297         $datarray['parent'] = $parent_id;
298         $datarray['type']  = $params['type'];
299         $datarray['verb']  = $params['verb'];
300         $datarray['otype'] = $params['otype'];
301         $datarray['abort'] = false;
302
303         call_hooks('enotify_store', $datarray);
304
305         if($datarray['abort']) {
306                 pop_lang();
307                 return;
308         }
309
310         // create notification entry in DB
311
312         $r = q("insert into notify (hash,name,url,photo,date,uid,link,parent,type,verb,otype)
313                 values('%s','%s','%s','%s','%s',%d,'%s',%d,%d,'%s','%s')",
314                 dbesc($datarray['hash']),
315                 dbesc($datarray['name']),
316                 dbesc($datarray['url']),
317                 dbesc($datarray['photo']),
318                 dbesc($datarray['date']),
319                 intval($datarray['uid']),
320                 dbesc($datarray['link']),
321                 intval($datarray['parent']),
322                 intval($datarray['type']),
323                 dbesc($datarray['verb']),
324                 dbesc($datarray['otype'])
325         );
326
327         $r = q("select id from notify where hash = '%s' and uid = %d limit 1",
328                 dbesc($hash),
329                 intval($params['uid'])
330         );
331         if($r)
332                 $notify_id = $r[0]['id'];
333         else {
334                 pop_lang();
335                 return;
336         }
337
338         // we seem to have a lot of duplicate comment notifications due to race conditions, mostly from forums
339         // After we've stored everything, look again to see if there are any duplicates and if so remove them
340
341         $p = null;
342         $p = q("select id from notify where ( type = %d or type = %d ) and link = '%s' and uid = %d order by id",
343                 intval(NOTIFY_TAGSELF),
344                 intval(NOTIFY_COMMENT),
345                 dbesc($params['link']),
346                 intval($params['uid'])
347         );
348         if($p && (count($p) > 1)) {
349                 for ($d = 1; $d < count($p); $d ++) {
350                         q("delete from notify where id = %d",
351                                 intval($p[$d]['id'])
352                         );
353                 }
354
355                 // only continue on if we stored the first one
356
357                 if($notify_id != $p[0]['id']) {
358                         pop_lang();
359                         return;
360                 }
361         }
362
363
364
365
366
367
368
369
370         $itemlink = $a->get_baseurl() . '/notify/view/' . $notify_id;
371         $msg = replace_macros($epreamble,array('$itemlink' => $itemlink));
372         $r = q("update notify set msg = '%s' where id = %d and uid = %d",
373                 dbesc($msg),
374                 intval($notify_id),
375                 intval($params['uid'])
376         );
377
378
379         // send email notification if notification preferences permit
380
381         require_once('include/bbcode.php');
382         if((intval($params['notify_flags']) & intval($params['type'])) || $params['type'] == NOTIFY_SYSTEM) {
383
384                 logger('notification: sending notification email');
385
386                 if (isset($params['parent']) AND (intval($params['parent']) != 0)) {
387                         $id_for_parent = $params['parent']."@".$hostname;
388
389                         // Is this the first email notification for this parent item and user?
390
391                         $r = q("select `id` from `notify-threads` where `master-parent-item` = %d and `receiver-uid` = %d limit 1",
392                                 intval($params['parent']),
393                                 intval($params['uid']) );
394
395                         // If so, create the record of it and use a message-id smtp header.
396
397                         if(!$r) {
398                                 logger("notify_id:".intval($notify_id).", parent: ".intval($params['parent'])."uid: ".intval($params['uid']), LOGGER_DEBUG);
399                                 $r = q("insert into `notify-threads` (`notify-id`, `master-parent-item`, `receiver-uid`, `parent-item`)
400                                         values(%d,%d,%d,%d)",
401                                         intval($notify_id),
402                                         intval($params['parent']),
403                                         intval($params['uid']),
404                                         0 );
405
406                                 $additional_mail_header .= "Message-ID: <${id_for_parent}>\n";
407                                 $log_msg = "include/enotify: No previous notification found for this parent:\n" .
408                                                 "  parent: ${params['parent']}\n" . "  uid   : ${params['uid']}\n";
409                                 logger($log_msg, LOGGER_DEBUG);
410                         } else {
411                                 // If not, just "follow" the thread.
412                                 $additional_mail_header .= "References: <${id_for_parent}>\nIn-Reply-To: <${id_for_parent}>\n";
413                                 logger("include/enotify: There's already a notification for this parent:\n" . print_r($r, true), LOGGER_DEBUG);
414                         }
415                 }
416
417
418                 $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
419                         $body))),ENT_QUOTES,'UTF-8'));
420                 $htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"),
421                         "<br />\n",$body))),ENT_QUOTES,'UTF-8');
422
423                 $datarray = array();
424                 $datarray['banner'] = $banner;
425                 $datarray['product'] = $product;
426                 $datarray['preamble'] = $preamble;
427                 $datarray['sitename'] = $sitename;
428                 $datarray['siteurl'] = $siteurl;
429                 $datarray['type'] = $params['type'];
430                 $datarray['parent'] = $params['parent'];
431                 $datarray['source_name'] = $params['source_name'];
432                 $datarray['source_link'] = $params['source_link'];
433                 $datarray['source_photo'] = $params['source_photo'];
434                 $datarray['uid'] = $params['uid'];
435                 $datarray['username'] = $params['to_name'];
436                 $datarray['hsitelink'] = $hsitelink;
437                 $datarray['tsitelink'] = $tsitelink;
438                 $datarray['hitemlink'] = '<a href="' . $itemlink . '">' . $itemlink . '</a>';
439                 $datarray['titemlink'] = $itemlink;
440                 $datarray['thanks'] = $thanks;
441                 $datarray['site_admin'] = $site_admin;
442                 $datarray['title'] = stripslashes($title);
443                 $datarray['htmlversion'] = $htmlversion;
444                 $datarray['textversion'] = $textversion;
445                 $datarray['subject'] = $subject;
446                 $datarray['headers'] = $additional_mail_header;
447
448                 call_hooks('enotify_mail', $datarray);
449
450                 // check whether sending post content in email notifications is allowed
451                 $content_allowed = !get_config('system','enotify_no_content');
452
453                 // load the template for private message notifications
454                 $tpl = get_markup_template('email_notify_html.tpl');
455                 $email_html_body = replace_macros($tpl,array(
456                         '$banner'       => $datarray['banner'],
457                         '$product'      => $datarray['product'],
458                         '$preamble'     => $datarray['preamble'],
459                         '$sitename'     => $datarray['sitename'],
460                         '$siteurl'      => $datarray['siteurl'],
461                         '$source_name'  => $datarray['source_name'],
462                         '$source_link'  => $datarray['source_link'],
463                         '$source_photo' => $datarray['source_photo'],
464                         '$username'     => $datarray['to_name'],
465                         '$hsitelink'    => $datarray['hsitelink'],
466                         '$hitemlink'    => $datarray['hitemlink'],
467                         '$thanks'       => $datarray['thanks'],
468                         '$site_admin'   => $datarray['site_admin'],
469                         '$title'                => $datarray['title'],
470                         '$htmlversion'  => $datarray['htmlversion'],
471                         '$content_allowed'      => $content_allowed,
472                 ));
473
474                 // load the template for private message notifications
475                 $tpl = get_markup_template('email_notify_text.tpl');
476                 $email_text_body = replace_macros($tpl,array(
477                         '$banner'       => $datarray['banner'],
478                         '$product'      => $datarray['product'],
479                         '$preamble'     => $datarray['preamble'],
480                         '$sitename'     => $datarray['sitename'],
481                         '$siteurl'      => $datarray['siteurl'],
482                         '$source_name'  => $datarray['source_name'],
483                         '$source_link'  => $datarray['source_link'],
484                         '$source_photo' => $datarray['source_photo'],
485                         '$username'     => $datarray['to_name'],
486                         '$tsitelink'    => $datarray['tsitelink'],
487                         '$titemlink'    => $datarray['titemlink'],
488                         '$thanks'       => $datarray['thanks'],
489                         '$site_admin'   => $datarray['site_admin'],
490                         '$title'                => $datarray['title'],
491                         '$textversion'  => $datarray['textversion'],
492                         '$content_allowed'      => $content_allowed,
493                 ));
494
495 //              logger('text: ' . $email_text_body);
496
497                 // use the EmailNotification library to send the message
498
499                 enotify::send(array(
500                         'fromName' => $sender_name,
501                         'fromEmail' => $sender_email,
502                         'replyTo' => $sender_email,
503                         'toEmail' => $params['to_email'],
504                         'messageSubject' => $datarray['subject'],
505                         'htmlVersion' => $email_html_body,
506                         'textVersion' => $email_text_body,
507                         'additionalMailHeader' => $datarray['headers'],
508                 ));
509         }
510
511         pop_lang();
512
513 }
514
515 require_once('include/email.php');
516
517 class enotify {
518         /**
519          * Send a multipart/alternative message with Text and HTML versions
520          *
521          * @param fromName                      name of the sender
522          * @param fromEmail                     email fo the sender
523          * @param replyTo                       replyTo address to direct responses
524          * @param toEmail                       destination email address
525          * @param messageSubject        subject of the message
526          * @param htmlVersion           html version of the message
527          * @param textVersion           text only version of the message
528          * @param additionalMailHeader  additions to the smtp mail header
529          */
530         static public function send($params) {
531
532                 $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8');
533                 $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8');
534
535                 // generate a mime boundary
536                 $mimeBoundary   =rand(0,9)."-"
537                                 .rand(10000000000,9999999999)."-"
538                                 .rand(10000000000,9999999999)."=:"
539                                 .rand(10000,99999);
540
541                 // generate a multipart/alternative message header
542                 $messageHeader =
543                         $params['additionalMailHeader'] .
544                         "From: $fromName <{$params['fromEmail']}>\n" .
545                         "Reply-To: $fromName <{$params['replyTo']}>\n" .
546                         "MIME-Version: 1.0\n" .
547                         "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
548
549                 // assemble the final multipart message body with the text and html types included
550                 $textBody       =       chunk_split(base64_encode($params['textVersion']));
551                 $htmlBody       =       chunk_split(base64_encode($params['htmlVersion']));
552                 $multipartMessageBody =
553                         "--" . $mimeBoundary . "\n" .                                   // plain text section
554                         "Content-Type: text/plain; charset=UTF-8\n" .
555                         "Content-Transfer-Encoding: base64\n\n" .
556                         $textBody . "\n" .
557                         "--" . $mimeBoundary . "\n" .                                   // text/html section
558                         "Content-Type: text/html; charset=UTF-8\n" .
559                         "Content-Transfer-Encoding: base64\n\n" .
560                         $htmlBody . "\n" .
561                         "--" . $mimeBoundary . "--\n";                                  // message ending
562
563                 // send the message
564                 $res = mail(
565                         $params['toEmail'],                                                                             // send to address
566                         $messageSubject,                                                                // subject
567                         $multipartMessageBody,                                                  // message body
568                         $messageHeader                                                                  // message headers
569                 );
570                 logger("notification: enotify::send header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG);
571                 logger("notification: enotify::send returns " . $res, LOGGER_DEBUG);
572         }
573 }
574 ?>