Changeset 1257 in ExiteCMS for modules/common/mail2forum/php-files/modules/mail2forum/m2f_smtp.php
- Timestamp:
- 02/10/08 16:01:38 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/common/mail2forum/php-files/modules/mail2forum/m2f_smtp.php
r1238 r1257 14 14 } 15 15 16 /*---------------------------------------------------+17 | Read the user configuration18 +----------------------------------------------------*/19 20 require "m2f_config.php";21 22 16 // find the webroot, so we can load the core functions 23 17 $webroot = ""; … … 26 20 if (strlen($webroot)>100) die('Unable to find the ExiteCMS document root!'); 27 21 } 22 require_once $webroot."includes/core_functions.php"; 28 23 29 24 // make sure the host is known 30 $_SERVER['HTTP_HOST'] = M2F_HOST; 31 32 require_once $webroot."includes/core_functions.php"; 25 $_SERVER['HTTP_HOST'] = $settings['m2f_host']; 33 26 34 27 locale_load("modules.mail2forum"); … … 49 42 function logentry($task="", $message="", $abort=false, $exitcode=0) { 50 43 51 global $processor ;52 53 $handle = fopen( M2F_LOGFILE.'/M2F_process.log', 'a');44 global $processor, $settings; 45 46 $handle = fopen($settings['m2f_logfile'].'/M2F_process.log', 'a'); 54 47 fwrite($handle, date("Ymd").";".date("His").";".$processor.";".$task.";".$message.chr(10)); 55 48 fclose($handle); … … 61 54 function logdebug($task="", $message="") { 62 55 63 global $processor ;64 65 $handle = fopen( M2F_LOGFILE.'/'.$processor.'.debug.log', 'a');56 global $processor, $settings; 57 58 $handle = fopen($settings['m2f_logfile'].'/'.$processor.'.debug.log', 'a'); 66 59 fwrite($handle, date("Ymd").";".date("His").";".$task.";".$message.chr(10)); 67 60 fclose($handle); … … 72 65 global $mail, $locale, $settings; 73 66 74 if ( M2F_SMTP_DEBUG) $mail->SMTPDebug = 2;67 if ($settings['m2f_smtp_debug']) $mail->SMTPDebug = 2; 75 68 76 69 if (file_exists(PATH_INCLUDES."languages/phpmailer.lang-".$settings['phpmailer_locale'].".php")) { … … 105 98 106 99 // log the start 107 if ( M2F_PROCESS_LOG) logentry('INIT', 'Program start');100 if ($settings['m2f_process_log']) logentry('INIT', 'Program start'); 108 101 109 102 // get the last modified timestamp of this module 110 103 $module_lastmod = filemtime('m2f_smtp.php'); 111 104 112 // get the last modified timestamp of the config file 113 $config_lastmod = filemtime('m2f_config.php'); 105 // get the last modified timestamp of the config 106 $data = dbarray(dbquery("SELECT MAX(cfg_timestamp) AS lastmod FROM ".$db_prefix."configuration WHERE cfg_name LIKE 'm2f_%'")); 107 $config_lastmod = $data['lastmod']; 114 108 115 109 // check if the Mail2Forum module is installed 116 110 $result = dbquery("SELECT * FROM ".$db_prefix."modules WHERE mod_title = '".$locale['m2f100']."'"); 117 111 if (dbrows($result) == 0) { 118 if ( M2F_PROCESS_LOG) logentry('INIT', $locale['m2f999'].' '.$locale['m2f110'], true, 1);119 die( 'Mail2Forum is not infused');112 if ($settings['m2f_process_log']) logentry('INIT', $locale['m2f999'].' NOT_INSTALLED', true, 1); 113 die($locale['m2f110']); 120 114 } 121 115 … … 131 125 $lastpoll = time(); 132 126 $result = dbquery("INSERT INTO ".$db_prefix."M2F_status (m2f_lastpoll) VALUES ('".$lastpoll."')"); 133 if ( M2F_PROCESS_LOG) logentry("INIT", sprintf($locale['m2f800'], $processor));127 if ($settings['m2f_process_log']) logentry("INIT", sprintf($locale['m2f800'], $processor)); 134 128 } else { 135 129 if ($data = dbarray($result)) { … … 138 132 die($processor.': LastPoll time is invalid. Use the admin module to correct this'); 139 133 } 140 if ((time() - $data['m2f_lastpoll']) > M2F_POLL_THRESHOLD) {134 if ((time() - $data['m2f_lastpoll']) > $settings['m2f_poll_threshold']) { 141 135 $result = dbquery("UPDATE ".$db_prefix."M2F_status SET m2f_lastpoll = 0"); 142 if ( M2F_PROCESS_LOG) logentry('INIT', $locale['m2f999'].' '.$locale['m2f801'], true, 1);143 die($processor.': More t han a week has passed since the last run! Use the admin module to correct this');136 if ($settings['m2f_process_log']) logentry('INIT', $locale['m2f999'].' '.$locale['m2f801'], true, 1); 137 die($processor.': More time has passed since the last run then the threshold allows! Use the admin module to correct this'); 144 138 } 145 139 $lastpoll = $data['m2f_lastpoll']+1; 146 140 } else { 147 if ( M2F_PROCESS_LOG) logentry('INIT', $locale['m2f999'].' '.$locale['m2f802'], true, 1);141 if ($settings['m2f_process_log']) logentry('INIT', $locale['m2f999'].' '.$locale['m2f802'], true, 1); 148 142 die('This should never happen'); 149 143 } … … 271 265 // Insert a marker in the log every hour to show we're still alive 272 266 if (isset($marker) && $marker <> date("H")) 273 if ( M2F_PROCESS_LOG) logentry("MARKER", "---");267 if ($settings['m2f_process_log']) logentry("MARKER", "---"); 274 268 $marker = date("H"); 275 269 … … 280 274 // get all posts in the selected interval 281 275 while($postrecord = dbarray($result)) { 282 if ( M2F_SMTP_DEBUG) logdebug('POSTRECORD', print_r($postrecord, true));276 if ($settings['m2f_smtp_debug']) logdebug('POSTRECORD', print_r($postrecord, true)); 283 277 284 278 $new_post = ($postrecord['post_datestamp'] >= $lastpoll && $postrecord['post_datestamp'] <= $polltime); 285 279 $edit_post = ($postrecord['post_edittime'] >= $lastpoll && $postrecord['post_edittime'] <= $polltime); 286 280 287 if ( M2F_SMTP_DEBUG) logdebug('POST_STATE', ($new_post?"ADD":"").($new_post&&$edit_post?"-":"").($edit_post?"EDIT":""));281 if ($settings['m2f_smtp_debug']) logdebug('POST_STATE', ($new_post?"ADD":"").($new_post&&$edit_post?"-":"").($edit_post?"EDIT":"")); 288 282 289 283 // if a new post was edited within one poll cycle, don't mark it as edited … … 293 287 $result2 = dbquery("SELECT m.m2f_email, f.forum_name FROM ".$db_prefix."M2F_forums m, ".$db_prefix."forums f WHERE m.m2f_active = '1' AND m.m2f_forumid = '".$postrecord['forum_id']."' AND m.m2f_forumid = f.forum_id"); 294 288 if (!$result2) { 295 if ( M2F_PROCESS_LOG) logentry('ERROR', $locale['m2f999'].' '.$locale['m2f803'].$postrecord['forum_id'], true, 1);289 if ($settings['m2f_process_log']) logentry('ERROR', $locale['m2f999'].' '.$locale['m2f803'].$postrecord['forum_id'], true, 1); 296 290 die($locale['m2f803']); 297 291 } else { 298 292 // get sender information 299 293 $sender = dbarray($result2); 300 if ( M2F_SMTP_DEBUG) logdebug('SENDER', print_r($sender, true));294 if ($settings['m2f_smtp_debug']) logdebug('SENDER', print_r($sender, true)); 301 295 302 296 // get all subscribed users for this forum … … 304 298 WHERE s.m2f_forumid = '".$postrecord['forum_id']."' AND s.m2f_subscribed = '1' AND u.user_status = 0 AND u.user_bad_email = 0 AND u.user_id = s.m2f_userid AND u.user_id = c.m2f_userid"); 305 299 while ($recipient = dbarray($result2)) { 306 if ( M2F_SMTP_DEBUG) logdebug('RECIPIENT', print_r($recipient, true));300 if ($settings['m2f_smtp_debug']) logdebug('RECIPIENT', print_r($recipient, true)); 307 301 308 302 // get the senders profile (need the email address and the email-hidden flag) … … 322 316 } 323 317 } 324 if ( M2F_SMTP_DEBUG) logdebug('POSTER', print_r($poster, true));318 if ($settings['m2f_smtp_debug']) logdebug('POSTER', print_r($poster, true)); 325 319 326 320 // check if the poster wants his email address hidden. If so, use the forum address as sender 327 if ( M2F_USE_FORUM_EMAIL|| $poster['user_hide_email'])321 if ($settings['m2f_use_forum_email'] || $poster['user_hide_email']) 328 322 $poster['user_email'] = $sender['m2f_email']; 329 323 … … 359 353 // although PHP-Fusion does not support multiple attachments, we do... ;-) 360 354 while ($attachment = dbarray($res_att)) { 361 if ( M2F_SMTP_DEBUG) logdebug('ATTACHMENT', print_r($attachment, true));355 if ($settings['m2f_smtp_debug']) logdebug('ATTACHMENT', print_r($attachment, true)); 362 356 $attachURL = $settings['siteurl']."getfile.php?type=a&file_id=".$attachment['attach_id']; 363 357 if ($recipient['m2f_html'] == 1) { … … 385 379 case 1: 386 380 // check the size of the attachments, don't send it out if it's to big 387 if (filesize(PATH_ATTACHMENTS.$attachment['attach_name']) < M2F_MAX_ATTACH_SIZE) {381 if (filesize(PATH_ATTACHMENTS.$attachment['attach_name']) < $settings['m2f_max_attach_size']) { 388 382 // attach the attachments to the email 389 383 $mail->AddAttachment(PATH_ATTACHMENTS.$attachment['attach_name']); … … 405 399 case 1: 406 400 // check the size of the attachments, don't send it out if it's to big 407 if (filesize(PATH_ATTACHMENTS.$attachment['attach_name']) < M2F_MAX_ATTACH_SIZE) {401 if (filesize(PATH_ATTACHMENTS.$attachment['attach_name']) < $settings['m2f_max_attach_size']) { 408 402 // attach the attachments to the email 409 403 $mail->AddAttachment(PATH_ATTACHMENTS.$attachment['attach_name']); … … 443 437 // send the post to the user 444 438 if(!$mail->Send()) { 445 if ( M2F_PROCESS_LOG) logentry('SEND', 'ERROR! From:'.$poster['user_email'].' To:'.$recipient['user_email'].' -> '.$mail->ErrorInfo);439 if ($settings['m2f_process_log']) logentry('SEND', 'ERROR! From:'.$poster['user_email'].' To:'.$recipient['user_email'].' -> '.$mail->ErrorInfo); 446 440 unset($mail); 447 441 $mail = new PHPMailer(); … … 449 443 } else { 450 444 $result4 = dbquery("UPDATE ".$db_prefix."M2F_forums SET m2f_sent = m2f_sent + 1 WHERE m2f_forumid = '".$postrecord['forum_id']."' "); 451 if ( M2F_PROCESS_LOG) logentry('SEND', 'From:'.$poster['user_email'].' To:'.$recipient['user_email'].' -> '.$subject);445 if ($settings['m2f_process_log']) logentry('SEND', 'From:'.$poster['user_email'].' To:'.$recipient['user_email'].' -> '.$subject); 452 446 } 453 447 … … 466 460 } 467 461 } else { 468 if ( M2F_PROCESS_LOG) logentry('POLL', 'no new posts');462 if ($settings['m2f_process_log']) logentry('POLL', 'no new posts'); 469 463 } 470 464 … … 475 469 clearstatcache(); 476 470 if (filemtime('m2f_smtp.php') != $module_lastmod) { 477 if ( M2F_PROCESS_LOG) logentry('EXIT', 'Restart due to module code update');471 if ($settings['m2f_process_log']) logentry('EXIT', 'Restart due to module code update'); 478 472 exit(99); 479 473 } 480 // if the config has been modified, exit so it can be reloaded 481 if (filemtime('m2f_config.php') != $config_lastmod) { 482 if (M2F_PROCESS_LOG) logentry('EXIT', 'Restart due to configuration change'); 474 // get the last modified timestamp of the config 475 $data = dbarray(dbquery("SELECT MAX(cfg_timestamp) AS lastmod FROM ".$db_prefix."configuration WHERE cfg_name LIKE 'm2f_%'")); 476 if ($data['lastmod'] != $config_lastmod) { 477 if ($settings['m2f_process_log']) logentry('EXIT', 'Restart due to a configuration change'); 483 478 exit(99); 484 479 } 485 480 486 481 // calculate the next interval. Log a warning if we can't process quick enough 487 $interval = $polltime + M2F_INTERVAL- time();482 $interval = $polltime + $settings['m2f_interval'] - time(); 488 483 if ($interval < 0) { 489 if ( M2F_PROCESS_LOG) logentry('SLEEP', $locale['m2f999'].' '.$locale['m2f804']);484 if ($settings['m2f_process_log']) logentry('SLEEP', $locale['m2f999'].' '.$locale['m2f804']); 490 485 } else { 491 486 sleep($interval); … … 496 491 if ($data = dbarray($result)) { 497 492 if ($data['m2f_abort'] == 1) { 498 if ( M2F_PROCESS_LOG) logentry('WAKE-UP', $locale['m2f999'].' '.$locale['m2f805'], true, 1);493 if ($settings['m2f_process_log']) logentry('WAKE-UP', $locale['m2f999'].' '.$locale['m2f805'], true, 1); 499 494 die($locale['m2f805']); 500 495 } 501 496 $lastpoll = $data['m2f_lastpoll']+1; 502 497 } else { 503 if ( M2F_PROCESS_LOG) logentry('WAKE-UP', $locale['m2f999'].' '.$locale['m2f802'], true, 1);498 if ($settings['m2f_process_log']) logentry('WAKE-UP', $locale['m2f999'].' '.$locale['m2f802'], true, 1); 504 499 die($locale['m2f802']); 505 500 }
Note: See TracChangeset
for help on using the changeset viewer.
