Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

6 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/bin/bash
  2. #
  3. # Author: Eric Gebhart
  4. #
  5. # Purpose: To be called by mutt as indicated by .mailcap to handle mail attachments.
  6. #
  7. # Function: Copy the given file to a temporary directory so mutt
  8. # Won't delete it before it is read by the application.
  9. #
  10. # Along the way, discern the file type or use the type
  11. # That is given.
  12. #
  13. # Finally use 'open' or 'open -a' if the third argument is
  14. # given.
  15. #
  16. #
  17. # Arguments:
  18. #
  19. # $1 is the file
  20. # $2 is the type - for those times when file magic isn't enough.
  21. # I frequently get html mail that has no extension
  22. # and file can't figure out what it is.
  23. #
  24. # Set to '-' if you don't want the type to be discerned.
  25. # Many applications can sniff out the type on their own.
  26. # And they do a better job of it too.
  27. #
  28. # Open Office and MS Office for example.
  29. #
  30. # $3 is open with. as in open -a 'open with this .app' foo.xls
  31. #
  32. # Examples: These are typical .mailcap entries which use this program.
  33. #
  34. # Image/JPEG; /Users/vdanen/.mutt/view_attachment %s
  35. # Image/PNG; /Users/vdanen/.mutt/view_attachment %s
  36. # Image/GIF; /Users/vdanen/.mutt/view_attachment %s
  37. #
  38. # Application/PDF; /Users/vdanen/.mutt/view_attachment %s
  39. #
  40. # #This HTML example passes the type because file doesn't always work and
  41. # #there aren't always extensions.
  42. #
  43. # text/html; /Users/vdanen/.mutt/view_attachment %s html
  44. #
  45. # # If your Start OpenOffice.org.app is spelled with a space like this one, <--
  46. # # then you'll need to precede the space with a \ . I found that too painful
  47. # # and renamed it with an _.
  48. #
  49. # Application/vnd.ms-excel; /Users/vdanen/.mutt/view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/Start_OpenOffice.org.app'
  50. # Application/msword; /Users/vdanen/.mutt/view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/Start_OpenOffice.org.app'
  51. #
  52. #
  53. # Debugging: If you have problems set debug to 'yes'. That will cause a debug file
  54. # be written to /tmp/mutt_attach/debug so you can see what is going on.
  55. #
  56. # See Also: The man pages for open, file, basename
  57. #
  58. # the tmp directory to use.
  59. tmpdir="$HOME/.tmp/mutt_attach"
  60. # the name of the debug file if debugging is turned on.
  61. debug_file=$tmpdir/debug
  62. # debug. yes or no.
  63. #debug="no"
  64. debug="yes"
  65. type=$2
  66. open_with=$3
  67. # make sure the tmpdir exists.
  68. mkdir -p $tmpdir
  69. # clean it out. Remove this if you want the directory
  70. # to accumulate attachment files.
  71. rm -f $tmpdir/*
  72. # Mutt puts everything in /tmp by default.
  73. # This gets the basic filename from the full pathname.
  74. filename=`basename $1`
  75. # get rid of the extenson and save the name for later.
  76. file=`echo $filename | cut -d"." -f1`
  77. if [ $debug = "yes" ]; then
  78. echo "1:" $1 " 2:" $2 " 3:" $3 > $debug_file
  79. echo "Filename:"$filename >> $debug_file
  80. echo "File:"$file >> $debug_file
  81. echo "===========================" >> $debug_file
  82. fi
  83. # if the type is empty then try to figure it out.
  84. if [ -z $type ]; then
  85. file $1
  86. type=`file -bi $1 | cut -d"/" -f2`
  87. fi
  88. # if the type is '-' then we don't want to mess with type.
  89. # Otherwise we are rebuilding the name. Either from the
  90. # type that was passed in or from the type we discerned.
  91. if [ $type = "-" ]; then
  92. newfile=$filename
  93. else
  94. newfile=$file.$type
  95. fi
  96. newfile=$tmpdir/$newfile
  97. # Copy the file to our new spot so mutt can't delete it
  98. # before the app has a chance to view it.
  99. cp $1 $newfile
  100. if [ $debug = "yes" ]; then
  101. echo "File:" $file "TYPE:" $type >> $debug_file
  102. echo "Newfile:" $newfile >> $debug_file
  103. echo "Open With:" $open_with >> $debug_file
  104. fi
  105. # If there's no 'open with' then we can let preview do it's thing.
  106. # Otherwise we've been told what to use. So do an open -a.
  107. if [ -z $open_with ]; then
  108. open $newfile
  109. else
  110. open -a "$open_with" $newfile
  111. fi