Icedove image liees

De Cliss XXI
Sauter à la navigation Sauter à la recherche
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Principe

Par défaut Thunderbird/Icedove inclu les images sous forme d'attachement MIME. Par exemple un copié/collé d'une page web avec des images va finir dans thunderbird sous forme d'attachement MIME.

La plupart du temps, ce comportement est souhaitable par exemple si l'adresse de l'image est locale:

file:///home/plouf/Images/toto.png

Néanmoins si c'est un copié/collé d'un site web ou les adresses des images sont de toute façon accessible, et que la page comporte beaucoup d'images, ce comportement va généré un courriel assez lourd alors qu'il serait tout à fait possible de n'avoir qu'un lien sur les images.


Thunderbird cherche un attribut "moz-do-not-send" pour savoir s'il doit envoyé l'image sous forme de lien ou d'attachement MIME. Par exemple:

<img src="http://img.no.lan/plouf.png">

image attachée sous forme MIME

<img src="http://img.no.lan/plouf.png" moz-do-not-send="true">

image sous forme de lien

Il suffit donc de modifier le code html de la page web pour que thunderbird respecte les lien. Ceci est possible avec javascript/jQuery:

jQuery('img').attr('moz-do-not-send', true);

Pratique

En utilisant la technique des bookmarklet, il est possible simplifier l'usage de ce script:

créer un nouveau marque page dont la cible est:

javascript:jQuery('img').attr('moz-do-not-send',true);

Si jQuery n'existe pas sur la page on peut le charger et envoyer la modif en utilisant http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet/ comme base. Ce qui se justifie si le traitement par jQuery est vraiment plus simple.

Sinon en javascript pur:

javascript:imgs=document.getElementsByTagName('img');for(var%20idx=0;idx<imgs.length;idx++)imgs[idx].setAttribute('moz-do-not-send','true');

par exemple [javascript:imgs=document.getElementsByTagName('img');for(var%20idx=0;idx<imgs.length;idx++)imgs[idx].setAttribute('moz-do-not-send','true'); Linkify]

Annexe

En partant de jQuerify:

javascript:(function(){var%20el=document.createElement(%22div%22),b=document.getElementsByTagName(%22body%22)[0],otherlib=!1,msg=%22%22;el.style.position=%22fixed%22,el.style.height=%2232px%22,el.style.width=%22220px%22,el.style.marginLeft=%22-110px%22,el.style.top=%220%22,el.style.left=%2250%25%22,el.style.padding=%225px%2010px%22,el.style.zIndex=1001,el.style.fontSize=%2212px%22,el.style.color=%22#222%22,el.style.backgroundColor=%22#f99%22;function%20showMsg(){var%20txt=document.createTextNode(msg);el.appendChild(txt),b.appendChild(el),window.setTimeout(function(){txt=null,typeof%20jQuery==%22undefined%22?b.removeChild(el):(jQuery(el).fadeOut(%22slow%22,function(){jQuery(this).remove()}),otherlib&&(window.$jq=jQuery.noConflict()))},2500);jQuery('img').attr('moz-do-not-send',true);}if(typeof%20jQuery!=%22undefined%22)return%20msg=%22This%20page%20already%20using%20jQuery%20v%22+jQuery.fn.jquery,showMsg();typeof%20$==%22function%22&&(otherlib=!0);function%20getScript(url,success){var%20script=document.createElement(%22script%22);script.src=url;var%20head=document.getElementsByTagName(%22head%22)[0],done=!1;script.onload=script.onreadystatechange=function(){!done&&(!this.readyState||this.readyState==%22loaded%22||this.readyState==%22complete%22)&&(done=!0,success(),script.onload=script.onreadystatechange=null,head.removeChild(script))},head.appendChild(script)}getScript(%22http://code.jquery.com/jquery.min.js%22,function(){return%20typeof%20jQuery==%22undefined%22?msg=%22Sorry,%20but%20jQuery%20was%20not%20able%20to%20load%22:(msg=%22This%20page%20is%20now%20jQuerified%20with%20v%22+jQuery.fn.jquery,otherlib&&(msg+=%22%20and%20noConflict().%20Use%20$jq(),%20not%20$().%22)),showMsg()})})();

La modif se trouve à la fin de la fonction showMsg() qui est la dernière appelée - une manière d'être sûr que jQuery est chargé ou existe sur la page

Le code "normal":

javascript: (function() {
  var el = document.createElement("div"),
    b = document.getElementsByTagName("body")[0],
    otherlib = !1,
    msg = "";
  el.style.position = "fixed", el.style.height = "32px", el.style.width = "220px", el.style.marginLeft = "-110px", el.style.top = "0", el.style.left = "50%", el.style.padding = "5px 10px", el.style.zIndex = 1001, el.style.fontSize = "12px", el.style.color = "#222", el.style.backgroundColor = "#f99";

  function showMsg() {
    var txt = document.createTextNode(msg);
    el.appendChild(txt), b.appendChild(el), window.setTimeout(function() {
      txt = null, typeof jQuery == "undefined" ? b.removeChild(el) : (jQuery(el).fadeOut("slow", function() {
        jQuery(this).remove()
      }), otherlib && (window.$jq = jQuery.noConflict()))
    }, 2500);
    jQuery('img').attr('moz-do-not-send',true);
  }
  if (typeof jQuery != "undefined") return msg = "This page already using jQuery v" + jQuery.fn.jquery, showMsg();
  typeof $ == "function" && (otherlib = !0);

  function getScript(url, success) {
    var script = document.createElement("script");
    script.src = url;
    var head = document.getElementsByTagName("head")[0],
      done = !1;
    script.onload = script.onreadystatechange = function() {
      !done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") && (done = !0, success(), script.onload = script.onreadystatechange = null, head.removeChild(script))
    }, head.appendChild(script)
  }
  getScript("http://code.jquery.com/jquery.min.js", function() {
    return typeof jQuery == "undefined" ? msg = "Sorry, but jQuery was not able to load" : (msg = "This page is now jQuerified with v" + jQuery.fn.jquery, otherlib && (msg += " and noConflict(). Use $jq(), not $().")), showMsg()
  })
})();