Bug 1176936 - Event extraction broken with single locale Lightning. r=philipp
authorMerike Sell <merike.sell@eesti.ee>
Wed, 22 Jul 2015 20:29:46 +0200
changeset 26250 39e76d5e07164030472e53cd0189c85bf678253e
parent 26249 07458a671842fcfaa3b29308dfa33654a1d1b555
child 26251 9a718ca3cae10186ae34102d18515a89bf5145fa
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs1176936
Bug 1176936 - Event extraction broken with single locale Lightning. r=philipp
calendar/base/content/calendar-extract.js
calendar/base/modules/calExtract.jsm
calendar/test/unit/test_extract.js
--- a/calendar/base/content/calendar-extract.js
+++ b/calendar/base/content/calendar-extract.js
@@ -87,24 +87,23 @@ let calendarExtract = {
                                                   false,
                                                   true,
                                                   { });
         cal.LOG("[calExtract] Original email content: \n" + title + "\r\n" + content);
         let date = new Date(message.date/1000);
         let time = (new Date()).getTime();
 
         let locale = Preferences.get("general.useragent.locale", "en-US");
-        let baseUrl = "resource://calendar/chrome/calendar-LOCALE/locale/LOCALE/calendar/calendar-extract.properties";
         let dayStart = Preferences.get("calendar.view.daystarthour", 6);
         let extractor;
 
         if (fixedLang) {
-            extractor = new Extractor(baseUrl, fixedLocale, dayStart);
+            extractor = new Extractor(fixedLocale, dayStart);
         } else {
-            extractor = new Extractor(baseUrl, locale, dayStart, false);
+            extractor = new Extractor(locale, dayStart, false);
         }
 
         let item;
         item = isEvent ? cal.createEvent() : cal.createTodo();
         item.title = message.mime2DecodedSubject;
         item.calendar = getSelectedCalendar();
         item.setProperty("DESCRIPTION", content);
         cal.setDefaultStartEndHour(item);
--- a/calendar/base/modules/calExtract.jsm
+++ b/calendar/base/modules/calExtract.jsm
@@ -5,27 +5,28 @@
 const EXPORTED_SYMBOLS = ["Extractor"];
 Components.utils.import("resource://calendar/modules/calUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/Preferences.jsm");
 
 /**
 * Initializes extraction
 *
-* @param baseUrl         path for the properties file containing patterns,
-*                            locale in path should be substituted with LOCALE
 * @param fallbackLocale  locale to use when others are not found or
 *                            detection is disabled
 * @param dayStart        ambiguous hours earlier than this are considered to
 *                            be in the afternoon, when null then by default
 *                            set to 6
 * @param fixedLang       whether to use only fallbackLocale for extraction
 */
-function Extractor(baseUrl, fallbackLocale, dayStart, fixedLang) {
-    this.bundleUrl = baseUrl;
+function Extractor(fallbackLocale, dayStart, fixedLang) {
+    // url for multi locale AMO build
+    this.bundleUrl = "resource://calendar/chrome/calendar-LOCALE/locale/LOCALE/calendar/calendar-extract.properties";
+    // url for single locale python packaged build
+    this.packagedUrl = "jar:resource://calendar/chrome.jar!/calendar-LOCALE/locale/LOCALE/calendar/calendar-extract.properties";
     this.fallbackLocale = fallbackLocale;
     this.email = "";
     this.marker = "--MARK--";
     // this should never be found in an email
     this.defPattern = "061dc19c-719f-47f3-b2b5-e767e6f02b7a";
     this.collected = [];
     this.numbers = [];
     this.hourlyNumbers = [];
@@ -40,16 +41,21 @@ function Extractor(baseUrl, fallbackLoca
 
     if (dayStart != null) {
         this.dayStart = dayStart;
     }
 
     if (fixedLang != null) {
         this.fixedLang = fixedLang;
     }
+
+    if (!this.checkBundle(fallbackLocale)) {
+        this.bundleUrl = this.packagedUrl;
+        cal.WARN("Your installed Lightning only includes a single locale, extracting event info from other languages is likely inaccurate. You can install Lightning from addons.mozilla.org manually for multiple locale support.")
+    }
 }
 
 Extractor.prototype = {
     /**
     * Removes confusing data like urls, timezones and phone numbers from email
     * Also removes standard signatures and quoted content from previous emails
     */
     cleanup: function cleanup() {
--- a/calendar/test/unit/test_extract.js
+++ b/calendar/test/unit/test_extract.js
@@ -1,17 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://calendar/modules/calExtract.jsm");
 Components.utils.import("resource://gre/modules/Preferences.jsm");
 
-let baseUrl = "resource://calendar/chrome/calendar-LOCALE/locale/LOCALE/calendar/calendar-extract.properties";
-let extractor = new Extractor(baseUrl, "en-US", 8);
+let extractor = new Extractor("en-US", 8);
 
 function run_test() {
     // Sanity check to make sure the base url is still right. If this fails,
     // don't forget to also fix the url in base/content/calendar-extract.js.
     ok(extractor.checkBundle("en-US"));
 
     test_event_start_end();
     test_event_start_duration();