APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Extract Photos from Kerio Connect Contacts

I had a request to extract the images from Kerio Connect contacts. I'm not sure what the reason was, but it's simple enough to do, so why not?

Kero contacts are .eml files, but are actually Vcards internally. They contain the image as inline base64. You could convert the files to Vcard format (see Transferring from Kerio Connect to another mail server) and then google for ways to extract images from Vcards, but why go to the extra trouble?

Here's some jpg's extracted by this program:

Images from Kerio eml Contact files

Each jpg is named from the Full Name (FN) in the contact file. I tightened up spaces because I don't like file names with spaces, but that's not strictly necessary.

The script below assumes the "base64" program exists (it does on my Linux and Mac systems) and that it is sitting in a directory containing Kerio Contact .eml files, presumably copied from their real location. It creates the jpg's in the same directory, though that could be easily changed.

The Mac version runs without complaint. The Linux version spits "base64: invalid input" but does create the files - I have no clue why as of yet.

You could use a very similar script to extract from Vcards.

#!/usr/bin/perl
foreach (<*.eml>)  {
 $file=$_;
 $name="";
 @holding=();
 $reading=0;
 $last="";
 open(MSG, $_);
 while (<MSG>) {
  $name=$_ if /^FN:/;
  $reading++ if $last =~ /^Content-Id: </;
  $last=$_;
  if ($reading)  {
  push @holding, $_ if not /^--MIME--/;
  last if /^--MIME--/;
  }
 }
 chomp $name;chop $name; # files have dos line endings;
 $name=~s/^FN://;
 $name=~s/ //g;
 if (not $name) {
  print "No FN in $file\n";
  next;
 }
 $name=~s/$/.jpg/;
 print "$name \n" if $reading;
 if ($reading) {
   open(OUT,"|base64 -D -o $name") or print "Error on $file/n";;
   # That's Mac syntax.  On Linux systems, it's base64 -id >$name
   foreach(@holding) {
      print OUT $_;
   }
   close OUT;
   }
}
 


Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Extract Photos from Kerio Connect Contacts




Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Anthony Lawrence



Kerio Connect Mailserver

Kerio Samepage

Kerio Control Firewall

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





The best of us would rather be popular than right. (Mark Twain)

The successful construction of all machinery depends on the perfection of the tools employed; and whoever is a master in the arts of tool-making possesses the key to the construction of all machines... The contrivance and construction of tools must therefore ever stand at the head of the industrial arts. (Charles Babbage)







This post tagged: