Search code examples
emailtwittermimepostfix-mtaprocmail

take email photo and send it to twitter


An email arrives on the mail server with a foto attached (a motion warning from a security camera, for example) and I would like to forward that foto to a twitter account via a DM. I think I have all the tools necessary to do this, but I haven't gotten them all together.

  1. postfix
  2. oysttyer
  3. procmail
  4. ImageMagick
  5. dovecot (can add sieve/pigeonhole)
  6. root access to install anything else

Currently I am able to send a text message saying "there was a motion warning with a photo, please check email" but that is suboptimal.

The solution I am thinking is best (though I am open o anything) is to figure out how to extract the image from the email and save it to a http accessible location on the server, then link to that location in the DM. However, I am open to any other ideas.


Solution

  • OK, I have a working (if terrible) solution.

    First, using ripmime I pipe the message to ripmime from within procmail. This produces a bunch of garbage files, along with an image file that I want. I proud these files in a web folder, and then I run a cron task to test the URL to the image and delete the garbage files.

    #!/bin/bash
    
    BASE="/usr/local/www/photodrop/"
    PHOTO=`find $BASE -cmin -2 -type f -name="*.jpg" -exec basename {} \;`
    
    URL="http://www.example.com/photodrop/$PHOTO"
    echo $URL
    
    oysttyer -runcommand="/dm @[user] $URL"
    

    In procmail, I simply pipe the message to ripmime

    :0
    | ripmime -i - -v -d /usr/local/www/photodrop/
    

    I looked at several other mime packages (munpack for one) but they didn't like accepting piped messages and munpack specifically required a path to a file, so that was no good. So, this works. Barely.

    For security, I remove the images (actually, I move them) after 5 minutes.