#! /bin/zsh test-replace-url () { local url url='http://user.it.uu.se/~embe8573/articles/latex/everest.pdf (Bakom Everest)' local -a match mbegin mend if [[ $url = (#b)http://(*)\ \((*)\) ]]; then print "$match[2]" fi } bup () { zup local dir=$(pwd) cd ~/Mail/blogomatic/ mail-to-html <-> # todo: remove change of dir cd $dir } mail-to-html () { local -a files files=($@) local category date language local blogomatic_path=~/public_html/blogomatic local dir blogomatic_dir final_path local subject subject_dropped subject_lower subject_lower_dashed subject_lower_dashed_washed subject_final local text text_quoted text_quoted_1 text_quoted_2 text_quoted_3 for f in $files; do category=$(/bin/grep -e '^Subject: ' $f | cut -d\ -f 3) dir=${category:l} blogomatic_dir=$blogomatic_path/$dir mkdir -p $blogomatic_dir subject=$(/bin/grep -e '^Subject: ' $f | cut -d\ -f 4-) subject_dropped=${subject//\'/} subject_lower=${subject_dropped:l} subject_lower_dashed=${subject_lower//[-.\/?,:;() ]##/-} subject_lower_dashed_washed=${subject_lower_dashed//c++/cpp} subject_final=${subject_lower_dashed_washed%-} final_path=$blogomatic_dir/$subject_final.html if [[ -f $final_path ]]; then newest=$(\ls -1t $f $final_path | head -n 1) [[ $newest = $final_path ]] && continue fi date=$(/bin/grep -e '^Date: ' $f | cut -d\ -f 2-) text=$(sed -n '/^$/,/^-- $/p' $f | head -n -1 | tail -n +2) text_quoted=${text//&/&} text_quoted_1=${text_quoted//<} text_quoted_2=${text_quoted_1//>/>} text_quoted_3=${text_quoted_2/'\n'/\n} /bin/egrep -q '^Content-Language: sv' $f [ $? = '0' ] && language='sv' || language='en' echo \ "\n" \ "\n" \ "
\n" \ " \n" \ " \n" \ " \n" \ "$date
\n" \ "$text_quoted_3\n" \ "
Back to Blogomatic.
" \ " \n" \ "" > $final_path echo "done: $final_path" done }