# HG changeset patch # User Tomas Zeman # Date 1383744881 -3600 # Node ID 3afc2ae852e508378ccbff928d6e73ac1beda68d # Parent 7cb1d50248a92597fceca601baf4dbae08273a9f# Parent 738979e906a1766db23142f9674d28ed695f6a75 branch merge diff -r 7cb1d50248a9 -r 3afc2ae852e5 config/.gitconfig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config/.gitconfig Wed Nov 06 14:34:41 2013 +0100 @@ -0,0 +1,42 @@ +[user] + email = tzeman@volny.cz + name = Tomas Zeman +[core] + excludesfile = /home/tzeman/.gitignore_global +[alias] + # define new alias as: git alias new_alias original_command + alias = "!sh -c '[ $# = 2 ] && git config --global alias.\"$1\" \"$2\" && exit 0 || echo \"usage: git alias \" >&2 && exit 1' -" + aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /' + st = status + ci = commit -v + br = branch + co = checkout + di = diff + df = diff + dc = diff --cached + lg = log -p + man = ls-files + sh = show + who = shortlog -s -- + # guilt related + qinit = !guilt init + qa = !guilt applied + qci = !cd .git/patches && git commit -av + qdi = !guilt diff + qfin = !guilt commit -v + qfo = !guilt fold + qgu = !guilt guard + qhe = !guilt header + qnew = !guilt new + qnex = !guilt next + qpo = !guilt pop + qpre = !guilt prev + qpu = !guilt push + qref = !guilt refresh + qrm = !guilt delete + qsel = !guilt select + qser = !guilt series + qst = !guilt status + qt = !guilt top + qu = !guilt unapplied + diff -r 7cb1d50248a9 -r 3afc2ae852e5 config/.gitignore_global --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config/.gitignore_global Wed Nov 06 14:34:41 2013 +0100 @@ -0,0 +1,11 @@ +# Mercurial +/.hg/* +*/.hg/* +.hgignore + +# vim +.*.s[a-w][a-z] +*.un~ +Session.vim +.netrwhist +*~ diff -r 7cb1d50248a9 -r 3afc2ae852e5 config/.hgenv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config/.hgenv Wed Nov 06 14:34:41 2013 +0100 @@ -0,0 +1,2 @@ +export EDITOR=vim +export HGEDITOR=hgeditor diff -r 7cb1d50248a9 -r 3afc2ae852e5 mailimage2mysql/LICENSE --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mailimage2mysql/LICENSE Wed Nov 06 14:34:41 2013 +0100 @@ -0,0 +1,24 @@ +Copyright (c) 2013, Tomas Zeman +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted providing that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + diff -r 7cb1d50248a9 -r 3afc2ae852e5 mailimage2mysql/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mailimage2mysql/README Wed Nov 06 14:34:41 2013 +0100 @@ -0,0 +1,15 @@ +Store image info (from email) to MySQL database. + +Operation: + + - parses/unpacks incoming mail (on stdin) + - all image attachments are stored in IMGFOLDER under unique name + - image/email metadata are stored in MySQL database (table IMGTABLE) + - adheres to qmail-command(8) interface + +Licensed under BSD-style license. + +Example setup: + + - put into your .qmail-images file: + | envdir env path/to/m2m || exit 100 diff -r 7cb1d50248a9 -r 3afc2ae852e5 mailimage2mysql/m2m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mailimage2mysql/m2m Wed Nov 06 14:34:41 2013 +0100 @@ -0,0 +1,57 @@ +#!/bin/bash -e +# +# (c) 2013, Tomas Zeman +# +# License: +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# + +mysql_cmd=${MYSQLCMD:-"mysql test"} +imgfolder=${IMGFOLDER:-"./images"} +imgtable=${IMGTABLE:-"images"} + +[ -d $imgfolder ] || mkdir -p $imgfolder + +mfile=`mktemp -t m2m.XXXXXX` +mdir=`mktemp -d -t m2m.XXXXXX` + +cleanup() +{ + rm -fr $mfile $mdir +} + +trap cleanup EXIT + +cat > $mfile + +munpack -q -C $mdir < $mfile > /dev/null + +mfrom=$(822field from < $mfile | sed -e 's/^ \+//') +mdate=$(822date < $mfile | head -2 | tail -1 | sed -e 's/ \++[0-9]\+$//') +mmsgid=$(822field message-id < $mfile | sed -e 's/^ \+//') + +process_images() +{ + pat="*.$1" + while IFS= read -d $'\0' -r f; do + mt=$(file -b --mime-type "$f") + if [ `expr match "$mt" "image/"` -gt 0 ]; then + on=$(basename "$f") + ext=$(echo "${on##*.}" | tr [A-Z] [a-z]) + fn="$(date '+%s.%N').$$.$ext" + ts=$(date '+%F %T') + cat "$f" > $imgfolder/$fn.tmp + mv $imgfolder/$fn.tmp $imgfolder/$fn + chmod 644 $imgfolder/$fn + printf "INSERT INTO $imgtable (file_name, orig_name, mime_type, mail_from, mail_date, mail_message_id, ts) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s');\n" "$fn" "$on" "$mt" "$mfrom" "$mdate" "$mmsgid" "$ts" | $mysql_cmd + fi + done < <(find $mdir -type f -name "$pat" -print0) +} + +process_images '[Jj][Pp][Gg]' +process_images '[Pp][Nn][Gg]' +process_images '[Tt][Ii][Ff][Ff]' + +exit 0 diff -r 7cb1d50248a9 -r 3afc2ae852e5 mailimage2mysql/schema.sql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mailimage2mysql/schema.sql Wed Nov 06 14:34:41 2013 +0100 @@ -0,0 +1,11 @@ +CREATE TABLE images ( + id bigint NOT NULL AUTO_INCREMENT, + file_name varchar(40) NOT NULL, + orig_name varchar(255) NOT NULL, + mime_type varchar(20), + mail_from varchar(255), + mail_date datetime, + mail_message_id varchar(255), + ts datetime NOT NULL, + PRIMARY KEY(id) +);