readmail.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Freemail v1.1 with SL patch
  4. *
  5. * @package freemail
  6. * @copyright Copyright (c) 2008 Serafim Panov
  7. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  8. * @author Serafim Panov
  9. * @contributor: Paul G. Preibisch - aka Fire centaur in Second Life
  10. * @contributor: Edmund Edgar
  11. *
  12. */
  13. if (isset($argv)) {
  14. define('CLI_SCRIPT', true);
  15. }
  16. require_once "../init.php";
  17. if (!defined('SLOODLE_FREEMAIL_ACTIVATE') || !SLOODLE_FREEMAIL_ACTIVATE) {
  18. die("Freemail is turned off. Enable SLOODLE_FREEMAIL_ACTIVATE in sloodle_config to turn it on.");
  19. }
  20. // Class for handling an imap message connection, and fetching and parsing emails one by one.
  21. require_once 'lib/freemail_imap_message_handler.php';
  22. // The following are base classes, but with static methods to load inherited classes.
  23. // We'll need an email_processor to parse our email - for example if it looks like a Second Life snapshot, we'll want one of those.
  24. require_once 'lib/freemail_email_processor.php';
  25. // It will then need to find something to do with the email, like import it into the blog.
  26. require_once 'lib/freemail_moodle_importer.php';
  27. $verbose = in_array("-v", $argv);
  28. $daemon = in_array("-d", $argv);
  29. $nodelete = in_array("-n", $argv); // Useful when testing.
  30. if ($nodelete && $daemon) {
  31. echo "Refusing to run in daemon mode with nodelete specified, as this will spam you into oblivion.\n";
  32. exit;
  33. }
  34. if ($daemon) {
  35. while ($handler = sloodle_freemail_email_processor::read_mail($CFG, $verbose, $daemon, $handler, false)) {
  36. sloodle_freemail_email_processor::verbose_output($verbose, "Handling run done, sleeping");
  37. sleep(2);
  38. }
  39. } else {
  40. sloodle_freemail_email_processor::read_mail($CFG, $verbose, $daemon, null, $nodelete);
  41. }
  42. exit;