◄ Older Entries | RSS

Pull Attachments from Incoming Mail with Perl

0


For a new project I've been working on, I needed to pull the image attachments from all incoming mail, store them separately. I couldn't find any snippets online for this so I had to create my own. Here's what I came up with. As always, it's a bit rough but is a good start.

 
#!/usr/local/bin/perl -I/home/*/perl/usr/lib/perl5/site_perl/5.8.8
use strict;
use DBI;
use MIME::Parser;
 
my $dbhost = 'localhost';
my $dblogin = '';
my $dbpass = '';
my $dbname = '';
 
# upload dir
my $out_dir = "/home/uploads";
 
# allowed filetypes
my %type_ok = (
   'image/jpeg' => 1,
   'image/gif' => 1,
   'image/bmp' => 1,
   'image/png' => 1
);
 
# init
	open STDOUT, '>/dev/null' or die "$!";
	open STDERR, '>/dev/null' or die "$!";
	my $parser = new MIME::Parser;
	$parser->output_dir($out_dir);
 
# read incoming message
	my $entity = $parser->read(\*STDIN);
	my $num_parts = $entity->parts;
 
# get userid from headers
	my $to = $entity->head->get('To');
#	open (FL, ">/home/1.html");print FL "$subject"; close FL;
 
# loop through attachments and move needed images to upload dir
	if ($num_parts > 0) {
		my $dbh = DBI->connect("DBI:mysql:database=$dbname;host=$dbhost", $dblogin, $dbpass) || die $DBI::errstr;
		for (my $i = 0; $i < $num_parts; $i++) {
		        my $part = $entity->parts($i);
		        my $type = lc $part->mime_type;
		        my $bh = $part->bodyhandle;
			next unless $bh;
			my $filename = $bh->path;
			if ($type_ok{$type}) {
#				print "$filename - OK\n";
# generate new filename and move into upload dir
				my ($ext) = $filename=~/.+\.(.+)$/;
				($to) = $to=~/^(.*?)\@/;
				my $time = time;
				print "time: $time\n";
				my $uid = $time . int(rand(9999));
				print "uid: $uid\n";
				my $newf = "$to-$uid.$ext";
				print "newf: $newf\n";
# move from temp to uploads dir
				system ("mv $filename ${out_dir}/".$newf);
 
# insert into mysql
				my $result = $dbh->prepare("insert images (user, time, image_name) values (?, ?, ?)") or die "Couldn't prepare: $DBI::errstr";
				$result->execute($to, $time, $newf) or die "Couldn't execute: $DBI::errstr";
 
			} else {
# remove non-needed attachments
				my $status = system("rm $filename");
			}
		}
		system("cd $out_dir && rm *.txt *.html > /dev/null");
	}
 

I'm not dead, I've just been busy. If you make an additions to the above, feel free to share it or email me.

Read More


The Vendor Client relationship in real world situations

0


YouTube Preview Image

Read More


More Flood Pictures

4


I've finally had some time to actually look through the pictures and videos I took on the first few days. No video will ever be uploaded, but here are some pictures.


Two days after the flood and it was still much higher than usual


My side yard with one of my buildings pushed against the neighbor's house


Back(ish) yard


What remains of building #1 and misc trash


Building number #1 and backyard


Backyard/fence and ~3 feet of sand/mud


Backyard and uprooted tree


Backyard


Some flowers I had planted just a few days prior. Hadn't even moved them up front yet...


Backyard


Front porch. The water somehow managed to pull the carpet/rug up. It was glued pretty well.


My foot, front sidewalk.


Road in front of the house.


Backyard


Trash out for the National Guard to pick up


Floors are buckling, hooving.


The dryer vent o' mud lol

Read More


Flooded

11


My house was flooded on Friday night/Saturday morning (around 3am). Nothing much else to say so here are some pictures.


More pictures located here: http://hellokevin.com/flood.

Read More


Facebook: Pirate Edition

0


My friend Aken (@cryode, Cryode.com) pointed this out.

Full screenshots:
http://hellokevin.com/files/upload/fb_profile.png
http://hellokevin.com/files/upload/fb_profile2.png

To change yours, scroll to the bottom of Facebook, click English (US) to bring up the language menu, and select "English (Pirate)"

Read More


YouTube Math

3


YouTube Preview Image

"Cute, fuzzy...let's show it to a friend!"

At this moment, that video has just a dash over 8 million views. That's not really any news for a youtube video. Hell, Avril Lavigne's video for "Girlfriend" has over 118 million views (Most Popular YouTube Videos, Alltime).

Back to the kitten video -- I was in my own little world, staring and smiling at the playful lil kittens pouncing around when it hit me: "How many other slobs are blobbing in front of their computers doing the same exact thing?" So, I did some quick math.
8 million views for a video that is roughly 1.5 minutes.
That's 12,000,000 minutes of wasted time. That's 200,000 hours gone. 8,333 days of human life lost. That's 22.8 YEARS of life that can never be lived again. I'm only 21 years old, these cute little kittens, no more than a month or so old, have consumed more human life that I have lived.

Avril Lavgine's crappy video, at 3:48 in length and 118,768,725 views, has consumed a whopping 27,079,269,300 seconds; 451,321,155 minutes ; 7,522,019 hours ; 313,417 days; 858.67 YEARS of life. Someone *please* correct my math if I have made a mistake. This is just hard for me to believe. I had never really stopped to think about how much time is wasted.

Read More


Getting some press

1


My latest project, SecretTweet.com, has been getting noticed by a few major names in the world of news.

LA Times:
http://latimesblogs.latimes.com/jacketcopy/2009/02/like-postsecret.html

New York Times:
http://bits.blogs.nytimes.com/2009/02/27/anonymous-confessions-go-online-with-secrettweet/

And it was on Fox News, too:
YouTube Preview Image

Read More


NYC and Misc Photos

0


Huntington was recently hit with some fairly harsh snow and I snapped a few photos predawn -- wanted to get pictures before sidewalks were salted and such.

snow-3
snow-3
snow-3

And I just returned from NYC. I didn't take as many pictures as I had planned -- too busy having fun and hanging out with people. I plan on going back sometime soon so maybe I'll get some more interesting "touristy" photos then. Here are a few photos of some museums and galleries that I visited (and a few random snapshots). If you were with me or hung out with me at night, I have some photos if you're interested...I'm not posting them online (don't want to embarrass anyone or myself LOL...good times, good times).

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

nyc-9

Read More


Ceramics Part Two

1


Here are the two remaining pieces.  I rushed while taking these pics.  The first piece is my favorite.  It has faults all over it but it helps the character.  I put a cone 10 glaze on it but it was only fired to cone 6.  I started to refire it but I liked it the more I looked at it -- left somewhat of a grunge effect.

Read More


Ceramics

0


EDIT: Just realized there's one more piece that I didn't take any photos of. Will include photos of it when I get the other pieces back.

Today was the final critique in ceramics.  There are still two or three of my pieces that weren't fully cooled from firing so I won't be able to bring those home until Monday, probably.  I wasn't sure how to take photos of this stuff so I just threw up two pieces of mat board and dusted off my camera.  Results aren't too bad.

Overall, I'm very satisfied with how everything came out (excluding the three remaining pieces which I haven't seen since I glazed them a few days ago).  Working with clay is, by no means, as simple as it looks or sounds.  I took the class thinking it would be an easy way to fill a requirement...rude awakening LOL.  Click to enlarge.

Read More


◄ Older Entries | RSS