Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add mailparse nonsense to install script; first basic pass of upload …

…by email thing works!
  • Loading branch information...
commit fbeb62238d5e29f1f24342537eeb1315d7006482 1 parent 519fbf1
straup authored
Showing with 25 additions and 8 deletions.
  1. +22 −8 bin/upload_by_email.php
  2. +3 −0  ubuntu/install.sh
View
30 bin/upload_by_email.php
@@ -7,7 +7,6 @@
loadlib("flickr_photos_upload");
# THIS IS SO NOT FINISHED (20120209/straup)
- error_disabled();
# https://code.google.com/p/php-mime-mail-parser/
loadpear("MimeMailParser");
@@ -16,7 +15,7 @@
$parser->setStream(STDIN);
$to = $parser->getHeader('to');
-
+
# TO DO: WRITE ME
$user = users_get_by_magic_email($to);
@@ -31,14 +30,18 @@
}
$uploads = array();
+
$tmpdir = sys_get_temp_dir();
+ $pid = getmypid();
- foreach ($attachments as $file){
+ foreach ($attachments as $att){
- # TO DO: check mime type
+ if (! preg_match("/^image\//", $att->content_type)){
+ continue;
+ }
- $filename = $file->filename;
- $path = "{$tmpdir}/{$filename}";
+ $filename = $att->filename;
+ $path = "{$tmpdir}/{$pid}-{$filename}";
$fh = fopen($path, "w");
@@ -49,7 +52,7 @@
# TO DO: check buffer size
- while ($bytes = $attachment->read()){
+ while ($bytes = $att->read()){
fwrite($fh, $bytes);
}
@@ -58,13 +61,24 @@
$uploads[] = $path;
}
+ if (! count($uploads)){
+ echo "no valid uploads";
+ exit();
+ }
+
foreach ($uploads as $path){
$args = array();
$rsp = flickr_photos_upload($user, $path, $args);
- # TO DO: check me...
+ # THROW AN ERROR ?
+
+ if (! $rsp['ok']){
+
+ echo "failed to upload '{$path}' : {$rsp['error']}";
+ continue;
+ }
}
foreach ($uploads as $path){
View
3  ubuntu/install.sh
@@ -27,5 +27,8 @@ ${INSTALL} php5-mysql
${INSTALL} php5-curl
${INSTALL} php5-mcrypt
+/usr/bin/pecl install mailparse
+echo 'extension=mailparse.so' > /etc/php5/apache2/conf.d/mailparse.ini
+
ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/
/etc/init.d/apache2 restart
Please sign in to comment.
Something went wrong with that request. Please try again.