Thunderbird: Paste Without Formatting

stop pasting tons of style garbage into your emails!

© 2012 by KV5R.

The Problem

When composing an HTML email in Thunderbird, “Paste” (Ctrl-V) pastes in a ton of style formatting, when something was copied from a web page or other formatted document. This is very annoying, since the incoming formatting code messes up the formatting of the email. Even worse, when copying from Chrome, the paste brings in a load of useless “apple-span-class” and “-webkit” crapola into the message’s HTML. All that extra bloat is unnecessary, unless you actually want to paste something with its source formatting into an email.

You should locate and install the “EditHtml” add-on so you can see (and edit or remove) the loads of excess HTML that paste operations bring in. It’s also handy to clean up messy emails before forwarding them.

Example

Here’s the HTML of a blank message:

<head></head>
<body bgcolor="#FFFFFF" text="#000000"><br></body>

Here’s the HTML of the same message after pasting in one tiny link copied from a web page in Google Chrome:

<head></head>
<body bgcolor="#FFFFFF" text="#000000">
 <a href="http://getsatisfaction.com/mozilla_messaging/people"
 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;
 padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;
 border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px;
 border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial;
 outline-width: initial; outline-style: none; outline-color: initial; font-weight: normal;
 font-style: normal; font-size: 13px; font-family: verdana; vertical-align: baseline;
 color: rgb(25, 81, 144); text-decoration: none; font-variant: normal; letter-spacing: normal;
 line-height: 15px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none;
 white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto;
 -webkit-text-stroke-width: 0px; background-color: rgb(88, 94, 98);
 ">the<span class="Apple-converted-space"> </span>
 <span class="notranslate" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px;
 margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;
 border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px;
 border-style: initial; border-color: initial; border-image: initial; outline-width: 0px;
 outline-style: initial; outline-color: initial; font-weight: inherit; font-style: inherit;
 font-size: 13px; font-family: inherit; vertical-align: baseline; ">Mozilla Messaging</span>
 <span class="Apple-converted-space"> </span> team</a>
 <span style="color: rgb(136, 136, 136); font-family: verdana; font-size: 13px; font-style: normal;
 font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 15px; orphans: 2;
 text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2;
 word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;
 background-color: rgb(88, 94, 98); display: inline !important; float: none; ">.</span>
</body>

That’s just a wee bit much, considering I didn’t want any of the web page’s formatting in my email, much less all that crap… And can you imagine how much extra crap that would be if I copied a large portion of a web page? EEK!

Okay, so you can use the “Paste Without Formatting” item on the Edit menu, but it’s inconvenient. Obviously, “Paste Without Formatting” should be the default paste operation. The Edit menu should then have a “Paste With Formatting” option. Looks to me like it’s just a matter of swapping two key assignments — Ctrl-V and Ctrl-Shift-V — or better yet, there should be a config entry to set the default type of paste function in Thunderbird’s settings.

How To Fix It

All one needs do is swap the key-bindings for Ctrl-V and Ctrl-Shift-V. This is done in two files within the file omni.ja, a large zipped file containing most of the Javascript and XML that runs Thunderbird. The one first is:

c:\Program Files (x86)\Mozilla Thunderbird\omni.ja\chrome\toolkit\content\global\platformHTMLBindings.xml

(On non-x64 Windows machines, remove the " (x86)" above)

  1. First, make a copy, in the same folder, of omni.ja, such as omni.ja.bak, just in case you mess it up.
  2. Rename omni.ja to omni.zip
  3. Unzip it into an empty folder such as C:\temp
  4. Navigate to C:\temp\chrome\toolkit\content\global\ and find platformHTMLBindings.xml
  5. Open it in a text editor
  6. Search for pasteNoFormatting and see these two lines:
  7. <handler event="keypress" key="v" command="cmd_paste" modifiers="accel"/>
    <handler event="keypress" key="v" command="cmd_pasteNoFormatting" modifiers="accel, shift"/>
    Drag and drop the ", shift" part up into the line above it, thus:
    <handler event="keypress" key="v" command="cmd_paste" modifiers="accel, shift"/>
    <handler event="keypress" key="v" command="cmd_pasteNoFormatting" modifiers="accel"/>
    Now you have swapped the commands associated with Ctrl-V and the Ctrl-Shift-V.
  8. Save the file and close the editor.
  9. Now locate and edit C:\temp\chrome\messenger\content\messenger\messengercompose\messengercompose.xul.
  10. Search for key_paste and see these three lines:
    <key id="key_paste" key="&pasteCmd.key;" modifiers="accel"/>
    <key id="pastequotationkb" key="&pasteAsQuotationCmd.key;"
         observes="cmd_pasteQuote" modifiers="accel, shift"/>
    <key id="pastenoformattingkb" key="&pasteNoFormattingCmd.key;"
         modifiers="accel, shift" observes="cmd_pasteNoFormatting"/>
  11. ...and move that comma and shift up into the modifiers in the “key_paste” line, thus:
    <key id="key_paste" key="&pasteCmd.key;" modifiers="accel, shift"/>
    <key id="pastequotationkb" key="&pasteAsQuotationCmd.key;"
         observes="cmd_pasteQuote" modifiers="accel, shift"/>
    <key id="pastenoformattingkb" key="&pasteNoFormattingCmd.key;"
         modifiers="accel" observes="cmd_pasteNoFormatting"/>
  12. Now you have swapped the Ctrl-V and the Ctrl-Shift-V on the Edit menu (it will not work unless you do so).
  13. Save the file and close the editor.
  14. Now Zip up the whole folder structure as omni.zip (make sure your zip does “recurse folders and store pathnames” or similar wording).
  15. Rename it to omni.ja
  16. Copy it over the old omni.ja in the Thunderbird install folder.
  17. Now nav to {youruserprofile}\AppData\Local\Thunderbird\Profiles\{whatever}.default\startupCache\startupCache.4.little (or similar) and DELETE it. If you don't, the old settings will still be cached.
  18. Now fire up Thunderbird and see if it works. Start a New message and look at the edit menu. The Paste and Paste Without Formatting keys should be reversed:
    Paste = Ctrl+Shift+V
    Paste Without Formatting = Ctrl-V
  19. Open a browser and select and copy something.
  20. Paste it into a new message with Ctrl-V. It should paste as plain text in the email’s default body font.
  21. Now try pasting it with the Edit menu commands. It should paste as the commands say: Paste will be with formatting.
  22. All done.

Notes

  1. This does not change the Shift-Insert paste key sequence. It only reverses Ctrl-V and Ctrl-Shift-V.
  2. Updating Thunderbird will revert your changes (you get a new omni.ja) and you have to do it all over again.
  3. Some file and zip managers (Total Commander, for example) will allow you to navigate within archives, edit a file therein, then repack it into the archive. This makes the above procedure much easier, since you don’t have to unpack and repack omni.ja.

I saw some chatter on the Mozilla Developer's Forum (I think it was there) about externalizing the key bindings to a user file, but we'll just have to wait to see if it's ever done.

I have my Logitech mouse programmed to Copy and Paste when the wheel is pressed left or right — the side buttons in the wheel simply send Ctrl-X and Ctrl-V into the keyboard buffer. After getting used too it, I find it is hugely helpful — you already have your hand on the mouse to select some text; you then just pull the wheel left, switch windows, then push the wheel right. Very handy!

So there ya go! One more little aggravation eliminated!

—kv5r

Leave a Reply

Your email address will not be published. Required fields are marked *