Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c25dfc
commit 4cce4a9
Showing
4 changed files
with
650 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
$root = dirname(dirname(__FILE__)); | ||
ini_set("include_path", "{$root}/www:{$root}/www/include"); | ||
|
||
include("include/init.php"); | ||
loadlib("flickr_photos_upload"); | ||
|
||
# THIS IS SO NOT FINISHED (20120209/straup) | ||
error_disabled(); | ||
|
||
# https://code.google.com/p/php-mime-mail-parser/ | ||
loadpear("MimeMailParser"); | ||
|
||
$parser = new MimeMailParser(); | ||
$parser->setStream(STDIN); | ||
|
||
$to = $parser->getHeader('to'); | ||
|
||
# TO DO: WRITE ME | ||
|
||
$user = users_get_by_magic_email($to); | ||
|
||
# $subject = $parser->getHeader('subject'); | ||
|
||
$attachments = $parser->getAttachments(); | ||
|
||
if (! count($attachments)){ | ||
echo "no attachments"; | ||
exit(); | ||
} | ||
|
||
$uploads = array(); | ||
$tmpdir = sys_get_temp_dir(); | ||
|
||
foreach ($attachments as $file){ | ||
|
||
$filename = $file->filename; | ||
$path = "{$tmpdir}/{$filename}"; | ||
|
||
$fh = fopen($path, "w"); | ||
|
||
if (! $fh){ | ||
echo "failed to open {$path}"; | ||
continue; | ||
} | ||
|
||
# TO DO: check buffer size | ||
|
||
while ($bytes = $attachment->read()){ | ||
fwrite($fh, $bytes); | ||
} | ||
|
||
fclose($fh); | ||
|
||
$uploads[] = $path; | ||
} | ||
|
||
foreach ($uploads as $path){ | ||
|
||
$args = array(); | ||
|
||
$rsp = flickr_photos_upload($user, $path, $args); | ||
|
||
# TO DO: check me... | ||
} | ||
|
||
foreach ($uploads as $path){ | ||
unlink($path); | ||
} | ||
|
||
exit(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
/** | ||
* Model of an Attachment | ||
*/ | ||
class MimeMailParser_attachment { | ||
|
||
/** | ||
* @var $filename Filename | ||
*/ | ||
public $filename; | ||
/** | ||
* @var $content_type Mime Type | ||
*/ | ||
public $content_type; | ||
/** | ||
* @var $content File Content | ||
*/ | ||
private $content; | ||
/** | ||
* @var $extension Filename extension | ||
*/ | ||
private $extension; | ||
/** | ||
* @var $content_disposition Content-Disposition (attachment or inline) | ||
*/ | ||
public $content_disposition; | ||
/** | ||
* @var $headers An Array of the attachment headers | ||
*/ | ||
public $headers; | ||
|
||
private $stream; | ||
|
||
public function __construct($filename, $content_type, $stream, $content_disposition = 'attachment', $headers = array()) { | ||
$this->filename = $filename; | ||
$this->content_type = $content_type; | ||
$this->stream = $stream; | ||
$this->content = null; | ||
$this->content_disposition = $content_disposition; | ||
$this->headers = $headers; | ||
} | ||
|
||
/** | ||
* retrieve the attachment filename | ||
* @return String | ||
*/ | ||
public function getFilename() { | ||
return $this->filename; | ||
} | ||
|
||
/** | ||
* Retrieve the Attachment Content-Type | ||
* @return String | ||
*/ | ||
public function getContentType() { | ||
return $this->content_type; | ||
} | ||
|
||
/** | ||
* Retrieve the Attachment Content-Disposition | ||
* @return String | ||
*/ | ||
public function getContentDisposition() { | ||
return $this->content_disposition; | ||
} | ||
|
||
/** | ||
* Retrieve the Attachment Headers | ||
* @return String | ||
*/ | ||
public function getHeaders() { | ||
return $this->headers; | ||
} | ||
|
||
/** | ||
* Retrieve the file extension | ||
* @return String | ||
*/ | ||
public function getFileExtension() { | ||
if (!$this->extension) { | ||
$ext = substr(strrchr($this->filename, '.'), 1); | ||
if ($ext == 'gz') { | ||
// special case, tar.gz | ||
// todo: other special cases? | ||
$ext = preg_match("/\.tar\.gz$/i", $ext) ? 'tar.gz' : 'gz'; | ||
} | ||
$this->extension = $ext; | ||
} | ||
return $this->extension; | ||
} | ||
|
||
/** | ||
* Read the contents a few bytes at a time until completed | ||
* Once read to completion, it always returns false | ||
* @return String | ||
* @param $bytes Int[optional] | ||
*/ | ||
public function read($bytes = 2082) { | ||
return feof($this->stream) ? false : fread($this->stream, $bytes); | ||
} | ||
|
||
/** | ||
* Retrieve the file content in one go | ||
* Once you retreive the content you cannot use MimeMailParser_attachment::read() | ||
* @return String | ||
*/ | ||
public function getContent() { | ||
if ($this->content === null) { | ||
fseek($this->stream, 0); | ||
while(($buf = $this->read()) !== false) { | ||
$this->content .= $buf; | ||
} | ||
} | ||
return $this->content; | ||
} | ||
|
||
/** | ||
* Allow the properties | ||
* MimeMailParser_attachment::$name, | ||
* MimeMailParser_attachment::$extension | ||
* to be retrieved as public properties | ||
* @param $name Object | ||
*/ | ||
public function __get($name) { | ||
if ($name == 'content') { | ||
return $this->getContent(); | ||
} else if ($name == 'extension') { | ||
return $this->getFileExtension(); | ||
} | ||
return null; | ||
} | ||
|
||
} | ||
|
||
?> |
Oops, something went wrong.