package com.fsck.k9.message.html;


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.safety.Cleaner;
import org.jsoup.safety.Whitelist;


public class HtmlSanitizer {
    private final HeadCleaner headCleaner;
    private final Cleaner cleaner;

    HtmlSanitizer() {
        Whitelist whitelist = Whitelist.relaxed()
                .addTags("font", "hr", "ins", "del")
                .addAttributes("table", "align", "bgcolor", "border", "cellpadding", "cellspacing", "width")
                .addAttributes(":all", "class", "style", "id")
                .addProtocols("img", "src", "http", "https", "cid", "data");

        cleaner = new Cleaner(whitelist);
        headCleaner = new HeadCleaner();
    }

    public Document sanitize(String html) {
        Document dirtyDocument = Jsoup.parse(html);
        Document cleanedDocument = cleaner.clean(dirtyDocument);
        headCleaner.clean(dirtyDocument, cleanedDocument);
        return cleanedDocument;
    }
}

@@ -498,16 +498,465 @@
 width%22)%0A
+                .addAttributes(%22tr%22, %22align%22, %22bgcolor%22, %22valign%22)%0A                .addAttributes(%22th%22,%0A                        %22align%22, %22bgcolor%22, %22colspan%22, %22headers%22, %22height%22, %22nowrap%22, %22rowspan%22, %22scope%22, %22sorted%22,%0A                        %22valign%22, %22width%22)%0A                .addAttributes(%22td%22,%0A                        %22align%22, %22bgcolor%22, %22colspan%22, %22headers%22, %22height%22, %22nowrap%22, %22rowspan%22, %22scope%22, %22valign%22,%0A                        %22width%22)%0A
         

Add more table elements attributes to whitelist