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

Extract Photos from Kerio Connect Contacts


Some material is very old and may be incorrect today

© December 2015 Anthony Lawrence

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;
   }
}
 

If you found something useful today, please consider a small donation.



Got something to add? Send me email.





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

Printer Friendly Version

->
-> Extract Photos from Kerio Connect Contacts


Inexpensive and informative Apple related e-books:

Take Control of iCloud, Fifth Edition

Take Control of the Mac Command Line with Terminal, Second Edition

Take Control of High Sierra

iOS 8: A Take Control Crash Course

iOS 10: A Take Control Crash Course





More Articles by © Anthony Lawrence





Printer Friendly Version

Have you tried Searching this site?

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


Printer Friendly Version





Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. ((Edsger W. Dijkstra)




Linux posts

Troubleshooting posts


This post tagged:

Kerio Connect

Kerio

Kerio Info

Kerio Pricing

Kerio RSS Feed

Mail

Perl

Scripting



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode