From b806d9fd6266af5bc24796c908864419ad2cdf9f Mon Sep 17 00:00:00 2001 From: dugite-code Date: Wed, 15 Aug 2018 15:33:33 +0800 Subject: [PATCH] Add strict Content Type check option Performance was affected by attempting to scan attachments in order to catch all variations --- scr/chrome/content/lookout.js | 50 ++++++++++++++------------ scr/chrome/content/options.xul | 2 ++ scr/chrome/locale/en-US/prefwindow.dtd | 2 ++ scr/defaults/preferences/lookout.js | 1 + 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/scr/chrome/content/lookout.js b/scr/chrome/content/lookout.js index b7ce5a2..94da947 100644 --- a/scr/chrome/content/lookout.js +++ b/scr/chrome/content/lookout.js @@ -609,30 +609,36 @@ var lookout_lib = { for( index in currentAttachments ) { var attachment = currentAttachments[index]; lookout.log_msg( attachment.toSource(), 8 ); - // we only decode tnef files -// if( (/^application\/ms-tnef/i).test( attachment.contentType ) ) { -{ + var scanfile = true; + + // Use strict content type matching to improve performance as a togglable option + if( lookout.get_bool_pref( "strict_contenttype" ) ){ + var scanfile = (/^application\/ms-tnef/i).test( attachment.contentType ) + lookout.log_msg( "LookOut: Content Type: '" + attachment.contentType + "'", 7 ); + } + if(scanfile){ + lookout.log_msg( "LookOut: found tnef", 7 ); - // open the attachment and look inside - var stream_listener = new LookoutStreamListener(); - stream_listener.attachment = attachment; - stream_listener.mAttUrl = attachment.url; - if( attachment.uri ) - stream_listener.mMsgUri = attachment.uri; - else - stream_listener.mMsgUri = attachment.messageUri; - stream_listener.mMsgHdr = lookout_lib.msg_hdr_for_current_msg( stream_listener.mMsgUri ); - if( ! stream_listener.mMsgHdr ) - lookout.log_msg( "LookOut: no message header for this service", 5 ); - stream_listener.action_type = LOOKOUT_ACTION_SCAN; - - var mms = messenger2.messageServiceFromURI( stream_listener.mMsgUri ) - .QueryInterface( Components.interfaces.nsIMsgMessageService ); - var attname = attachment.name ? attachment.name : attachment.displayName; - mms.openAttachment( attachment.contentType, attname, - attachment.url, stream_listener.mMsgUri, stream_listener, - null, null ); + // open the attachment and look inside + var stream_listener = new LookoutStreamListener(); + stream_listener.attachment = attachment; + stream_listener.mAttUrl = attachment.url; + if( attachment.uri ) + stream_listener.mMsgUri = attachment.uri; + else + stream_listener.mMsgUri = attachment.messageUri; + stream_listener.mMsgHdr = lookout_lib.msg_hdr_for_current_msg( stream_listener.mMsgUri ); + if( ! stream_listener.mMsgHdr ) + lookout.log_msg( "LookOut: no message header for this service", 5 ); + stream_listener.action_type = LOOKOUT_ACTION_SCAN; + + var mms = messenger2.messageServiceFromURI( stream_listener.mMsgUri ) + .QueryInterface( Components.interfaces.nsIMsgMessageService ); + var attname = attachment.name ? attachment.name : attachment.displayName; + mms.openAttachment( attachment.contentType, attname, + attachment.url, stream_listener.mMsgUri, stream_listener, + null, null ); } } }, diff --git a/scr/chrome/content/options.xul b/scr/chrome/content/options.xul index 2ed9899..666726f 100644 --- a/scr/chrome/content/options.xul +++ b/scr/chrome/content/options.xul @@ -44,9 +44,11 @@ + + diff --git a/scr/chrome/locale/en-US/prefwindow.dtd b/scr/chrome/locale/en-US/prefwindow.dtd index 7336289..d6ecb93 100644 --- a/scr/chrome/locale/en-US/prefwindow.dtd +++ b/scr/chrome/locale/en-US/prefwindow.dtd @@ -6,4 +6,6 @@ + + diff --git a/scr/defaults/preferences/lookout.js b/scr/defaults/preferences/lookout.js index 02b64cb..ea9169e 100644 --- a/scr/defaults/preferences/lookout.js +++ b/scr/defaults/preferences/lookout.js @@ -1,6 +1,7 @@ pref( "extensions.lookout.attach_raw_mapi", false ); pref( "extensions.lookout.direct_to_calendar", false ); pref( "extensions.lookout.disable_filename_character_set", false ); +pref( "extensions.lookout.strict_contenttype", true ); pref( "extensions.lookout.body_part_prefix", "body_part_" ); // See http://kb.mozillazine.org/Localize_extension_descriptions pref("extensions.lookout@aron.rubin.description", "chrome://lookout/locale/lookout.properties");