Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

thunderbird -compose "attachment='$HOME/test test.txt'" works. thunderbird -compose "attachment='$HOME/test, test.txt'" does not work and gives a file does not exist error message.

This must be because of the way Thunderbird handles command line arguments; e.g.,

thunderbird -compose "to='name@mail.com',attachment='~/file.txt'"

The compose arguments are separated by , and that must be why having a , in the file name breaks things. I cannot, however, think of a way to "escape" commas in the file name.

Note:

  • In Thunderbird 3+, using the protocol file:// is not required any more.

Both

thunderbird -compose "attachment='$HOME/test test.txt'"

and

thunderbird -compose "attachment='file://$HOME/test test.txt'"

work.

Neither

thunderbird -compose "attachment='$HOME/test, test.txt'"

nor

thunderbird -compose "attachment='file://$HOME/test, test.txt'"

works.

share|improve this question
1  
At a guess I would suggest trying to escape \, or url encode %2C it. –  Etan Reisner Jul 31 '13 at 1:24
    
Escaping comma (\,) does not work; it gives the same file does not exist error. The characters , and % are both legitimate in the file name so I don't think URL encoding is an option because test,test and test%2Ctest are both legitimate file names. –  Omid Jul 31 '13 at 1:41
2  
While true test%2Ctest would become test%252Ctest when url encoded. It is worth trying it (it might need the explicit file:// prefix to work I suppose but I don't know). –  Etan Reisner Jul 31 '13 at 1:45
    
Sounds like a bug in the wrapper script. –  Ignacio Vazquez-Abrams Jul 31 '13 at 3:13

1 Answer 1

up vote 0 down vote accepted

Using the idea of URL encoding the file names suggested by @Etan Reisner (in a comment to my question above), I hacked a solution which I record here for the benefit of others in the community. In the snippet below, ${filename} is the full file name (including path) to be attached.

#!/bin/bash

# "A safe way to URL encode is to encode every single byte, even
# those that would've been allowed." This is done by first
# converting every byte to its 2-byte hex code using `hexdump' and
# then adding the prefix `%' to each 2-byte hex code pair using
# `sed'.
#
# Attribution: https://stackoverflow.com/a/7506695

filenameurlencoded=$(echo -ne "${filename}" | \
hexdump -v -e '/1 "%02x"' | \
sed 's/\(..\)/%\1/g')

filenamenopath="$(basename ${filename})"
emailsubject="${filenamenopath}"
emailbody="\"${filenamenopath}\" is attached."
emailattachment="file:///${filenameurlencoded}"

# Syntax of -compose command line option: double-quotes enclose
# full comma-separated list of arguments passed to -compose,
# whereas single quotes are used to group items for the same
# argument.
#
# Attribution: http://kb.mozillazine.org/Command_line_arguments_(Thunderbird)

thunderbird -compose "subject='${emailsubject}',body='${emailbody}',attachment='${emailattachment}'"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.