Right click -> attach to email (KDE)

This forum is dedicated to new ideas, suggestions and proposals.

Right click -> attach to email (KDE)

Postby stephenliberty » Feb 18th, '12, 00:38

Hi,

One of the functionalities that was demanded of me prior to switching systems over to Linux was the "right click -> attach to email" that existed in Windows. I'm not sure the exact command, but basically it was incredibly easy to send a file to someone via email. After all, why should you have to go hunting for a file in both the file manager and in the email application? Windows (or whatever) would also resize any attached images so that they were 'email worthy' instead of being 3 megs a piece and since the business this was written for is heavy into sending photos back and forth, this was a necessity. So, I wrote up a rather primitive but effective script to do so. The script 'belongs' to me, but as far as I'm concerned, anyone can have it.

Instructions on use:
Put the following in /usr/share/kde4/services/ServiceMenus/thunderbird_attachment.desktop
Code: Select all
[Desktop Entry]
Type=Service
Actions=attachToEmail
Encoding=UTF-8
ServiceTypes=KonqPopupMenu/Plugin
MimeType=all/all;
ExcludeServiceTypes=application/x-iso

[Desktop Action attachToEmail]
Exec=/opt/thunderbird_extra/compress_and_send.sh %F
Name=Attach to Thunderbird Mail
Icon=/usr/share/icons/mozilla-thunderbird.png


Put the following in /opt/thunderbird_extra/compress_and_send.sh
Code: Select all
#!/bin/bash

SAVE_IFS=$IFS

folder=`mktemp -d`

declare files=()
IFS="
"
fileList=("$@")

for i in "${fileList[@]}"; do
  thefile=$i
  type=`mimetype $i`
  type=`echo $type | grep -oE "([^: ]+)$"`
  echo "$thefile $type"
  case $type in
    "inode/directory")
      for mi in `ls -1 "$thefile"`; do
        fileList+=("$thefile/$mi")
      done
      ;;
  esac
done

for i in "${fileList[@]}"; do
  thefile=$i
  type=`mimetype $i`
  type=`echo $type | grep -oE "([^: ]+)$"`
  echo "$thefile $type"
  filepath=''
  case $type in
    "image/jpeg")
      filename=${thefile##*/}
      filepath="$folder/$filename"
      `convert -scale 640x480 "$thefile" "$filepath"`
      filename=$(echo "$filename" | sed -e 's/%/%25/g' -e 's/ /%20/g' -e 's/!/%21/g' -e 's/"/%22/g' -e 's/#/%23/g' -e 's/\$/%24/g' -e 's/\&/%26/g' -e 's/'\''/%27/g' -e 's/(/%28/g' -e 's/)/%29/g' -e 's/\*/%2a/g' -e 's/+/%2b/g' -e 's/,/%2c/g' -e 's/-/%2d/g' -e 's/\./%2e/g' -e 's/\//%2f/g' -e 's/:/%3a/g' -e 's/;/%3b/g' -e 's//%3e/g' -e 's/?/%3f/g' -e 's/@/%40/g' -e 's/\[/%5b/g' -e 's/\\/%5c/g' -e 's/\]/%5d/g' -e 's/\^/%5e/g' -e 's/_/%5f/g' -e 's/`/%60/g' -e 's/{/%7b/g' -e 's/|/%7c/g' -e 's/}/%7d/g' -e 's/~/%7e/g')
      filepath="$folder/$filename"
      ;;
    "inode/directory" | "application/x-sqlite3")
      ;;
    *)
      filepath="$thefile"
      ;;
  esac
  if [ "$filepath" != "" ]; then
          files+=("file://$filepath")
  fi
done



IFS=","
filesJoined="${files[*]}"
IFS=$SAVE_IFS
thunderbird -compose "attachment=`echo $filesJoined | xxd -plain | tr -d '\n' | sed 's/\(..\)/%\1/g'`"


Make sure that compress_and_send.sh is executable.
Close out of all dolphin windows and then open up a window. You should be able to 'right click' and then go to 'Actions' and then 'Attach to thunderbird mail'.
If the mageia folks would like to clean this up and wrap it in somehow, that'd be awesome. I think it only requires 'convert' from the imagemagik library/program/what-have-you.
Last edited by stephenliberty on Feb 23rd, '12, 00:32, edited 1 time in total.
stephenliberty
 
Posts: 10
Joined: Nov 1st, '11, 01:01

Re: Right click -> attach to email (KDE)

Postby doktor5000 » Feb 18th, '12, 17:22

This is actually an area where linux is still lacking, such small convenience features. I've reported a similar
feature request for KDE years ago, which would actually be really easy to implement and needs no coding,
still nothing happened :( https://bugs.kde.org/show_bug.cgi?id=205572

Maybe we can integrate your script somehow into Mageia ...
FWIW, if i've looked correctly, the script is only for sending pictures, correct? Maybe we should start
with a general-purpose context menu for all types of files, and then refine it into recognizing what type of file you want to attach
and to take appropriate action (compress, or convert/resize or whatever)
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18042
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Right click -> attach to email (KDE)

Postby stephenliberty » Feb 18th, '12, 20:05

Actually, it attaches anything. It just so happened that images were the only type that required any real work. Look for the 'case $type in' part - you've got image/jpeg and then the default case (which just attaches the file as is).

And yeah, there are a lot of little things like that which, if fixed/improved/added would help it compete a bit more on the desktop. The kde 'find a service' thing doesn't help an average user.
stephenliberty
 
Posts: 10
Joined: Nov 1st, '11, 01:01


Return to Ideas and suggestions

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron