Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This is a wrapper script to attach several files to an email in Thunderbird.
- # Written by Sergey "Shnatsel" Davidoff <[email protected]>
- # License: 3-clause BSD
- # Thunderbird is very picky about the file paths and will just hang in case it
- # doesn't like something.
- # If it does, I'm probably doing something slightly wrong here.
- #TODO: define a Gettext domain
- # Disable history substitution on "!" symbols so we can have them in strings
- set +H
- if [ -z "$1" ] || [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
- echo $"Usage: $0 /path/to/file [/path/to/another/file...]
- Relative paths are also supported, but files with comma in the name are NOT."
- exit 1 # so that calling without parameters is counted as a failure
- fi
- while [ -n "$1" ]; do
- # Check if the file exists; if not, complain and exclude the file.
- # Thunderbird will hang if given a nonexistent file.
- if [ -e "$1" ]; then
- if ! ( echo "$1" | grep -q ',' ); then
- FILES="$FILES,$1"
- else
- comma_files="$comma_files
- $1"
- fi
- else
- nonexistent_files="$nonexistent_files
- $1"
- fi
- shift
- done
- # Remove the commas in the beginning and end of file list,
- # otherwise Thunderbird will hang.
- FILES=${FILES%,}
- FILES=${FILES#,}
- # Error reporting
- if [ -n "$comma_files" ]; then
- ERRORS="$ERRORS
- "$"Thunderbird cannot handle files with commas in the name.
- These files were not attached: $comma_files"
- fi
- if [ -n "$nonexistent_files" ]; then
- ERRORS="$ERRORS
- "$"These files do not seem to exist and were ignored: $nonexistent_files"
- fi
- ERRORS=${ERRORS#'
- '} # Remove the \n in the beginning of the error list, it's prettier that way
- if [ -n "$FILES" ]; then
- if [ -n "$ERRORS" ]; then
- notify-send --icon=thunderbird $"Some files were not attached" "$ERRORS"
- fi
- # Finally execute Thunderbird and exit with its exit code
- thunderbird -compose "attachment='${FILES}'"
- else
- if [ -n "$ERRORS" ]; then
- notify-send --icon=thunderbird $"No files were attached!" "$ERRORS"
- fi
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement