Advertisement
metalx1000

get all pdf attachments from mail box file mbox

Feb 10th, 2015
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.75 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. dir="attachments"
  4. pw="password"
  5.  
  6. echo "Reading Mailbox File..."
  7. csplit --digits=2  --quiet -k --prefix=outfile Gmail.mbox "/--/+1" "{*}"
  8.  
  9. echo "Creating Attachment Folder..."
  10. mkdir $dir
  11.  
  12. echo "Finding all pdf files..."
  13. grep -l 'application/pdf; name="11OCCHIPI' out*|\
  14.   while read file
  15.   do
  16.     mv $file $dir
  17.   done
  18.  
  19. echo "Removing Temp files..."
  20. rm outfile*
  21. cd $dir
  22.  
  23. echo "Converting Files..."
  24. for i in outfile*
  25. do
  26.   echo "$i"
  27.   awk -v nr="$(wc -l < $i)" 'NR>8 && NR<(nr-1)' $i > $i.b64
  28.   dos2unix $i.b64
  29.   base64 -d $i.b64 > $i.pdf
  30.   pdftops -upw $pw $i.pdf
  31.   ps2pdf $i.ps
  32.   pdftotext $i.pdf
  33.   name=$(grep '/20' $i.txt|head -n 1|tr '/' '_')
  34.   mv $i.pdf $name.pdf
  35.   echo $name.pdf
  36.   rm $i.ps
  37.   rm $i.b64
  38.   rm $i
  39. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement