summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-06-01 12:15:26 -0700
committerJesse Morgan <jesse@jesterpm.net ; true>2011-06-01 12:15:26 -0700
commit9ad57b3d8d1000f17962bb0ba00a8958b2f141db (patch)
tree515f444d429b999516e530e5d35fcaac6424f1a9 /scripts
parenta070cbe9627fcc29ef2f91b8f7578080203e6ad1 (diff)
Added scripts, email addresses, other minor modifications
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/cleanup_old_posts.php30
-rw-r--r--scripts/forward_emails.php96
2 files changed, 126 insertions, 0 deletions
diff --git a/scripts/cleanup_old_posts.php b/scripts/cleanup_old_posts.php
new file mode 100755
index 0000000..6a3986a
--- /dev/null
+++ b/scripts/cleanup_old_posts.php
@@ -0,0 +1,30 @@
+#!/usr/bin/php
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once "../htdocs/src/base.inc.php";
+
+$pi = new PostIterator();
+
+$diff = $CONFIG['expiretime'] * 86400;
+
+$pi->filterCreated(0, time() - $diff);
+$pi->query();
+
+$count = 0;
+foreach ($pi as $post) {
+ $post->delete();
+ $count++;
+
+}
+
+// TODO: Add Logging?
+
+?>
diff --git a/scripts/forward_emails.php b/scripts/forward_emails.php
new file mode 100644
index 0000000..bd4846f
--- /dev/null
+++ b/scripts/forward_emails.php
@@ -0,0 +1,96 @@
+#!/usr/bin/php
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once "../htdocs/src/base.inc.php";
+
+// Read the email
+$fd = fopen("php://stdin", "r");
+$email = "";
+while (!feof($fd)) {
+ $email .= fread($fd, 1024);
+}
+fclose($fd);
+
+// Parse the email
+$headers = "";
+$to = "";
+$from = "";
+$subject = "";
+$message = "";
+
+$splitmsg = split("\n", $email);
+
+$inheaders = true;
+foreach ($splitmsg as $line) {
+ if ($inheaders) {
+ // This is a header
+ if ($line == '') {
+ $inheaders = false;
+
+ } else {
+ $header = split(':', $line, 2);
+
+ switch (strtolower(trim($header[0]))) {
+ case 'from':
+ $from = $header[1];
+ break;
+
+ case 'subject':
+ $subject = $header[1];
+ break;
+
+ case 'delivered-to':
+ $to = $header[1];
+ break;
+
+ default:
+ $headers .= "$line\n";
+ }
+ }
+
+ } else {
+ // Messsage line
+ $message .= "$line\n";
+ }
+}
+
+
+// Get the post id and post.
+preg_match("/posting-(.+)@.+/", $to, $identifiers);
+
+if (!isset($identifiers[1]) or !is_numeric($identifiers[1])) {
+ mailFailure("Invalid id");
+}
+
+$id = $identifiers[1];
+
+$post = Post::getById($id);
+
+if (!$post or $post->getStage() != 'approved') {
+ mailFailure('Invalid post');
+}
+
+// Valid Post... forward the message.
+$newsubject = "[" . $CONFIG['sitetitle'] . "] $subject";
+
+if (mail($post->getEmail(), $newsubject, $message, $headers)) {
+ exit 0;
+
+} else {
+ exit 2;
+}
+
+function mailFailure($message='') {
+ echo "5.1.1 $message\n";
+ exit 1;
+}
+
+?>