<commit_before><?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();
?>
<commit_msg>notes to self<commit_after><?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){

		# TO DO: check mime type

		$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();
?>

{'fraction_non_alphanumeric': 0.20110410094637224, 'fraction_numerical': 0.006309148264984227, 'mean_word_length': 3.878846153846154, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2450540', 'n_tokens_mistral': 1075, 'n_tokens_neox': 936, 'n_words': 195}