# HG changeset patch
# User luis.merino@x41-dsec.de
# Date 1559663661 -7200
#      Tue Jun 04 17:54:21 2019 +0200
# Node ID 58768479ed77a3cf96967140ad1b9781a9670bac
# Parent  a7a13478e5a180d15741be289d3e07a93e9d9425
Bug 1553814 - Update libical from upstream. r+a=philipp

diff -r a7a13478e5a1 -r 58768479ed77 comm/calendar/libical/src/libical/icalvalue.c
--- a/comm/calendar/libical/src/libical/icalvalue.c	Wed May 29 16:44:53 2019 +0200
+++ b/comm/calendar/libical/src/libical/icalvalue.c	Tue Jun 04 17:54:21 2019 +0200
@@ -189,77 +189,80 @@
 
 static char* icalmemory_strdup_and_dequote(const char* str)
 {
-    const char* p;
-    char* out = (char*)malloc(sizeof(char) * strlen(str) +1);
-    char* pout;
+    const char *p;
+    char *out = (char *)malloc(sizeof(char) * strlen(str) + 1);
+    char *pout;
+    int wroteNull = 0;
 
-    if (out == 0){
-	return 0;
+    if (out == 0) {
+        return 0;
     }
 
     pout = out;
 
-    for (p = str; *p!=0; p++){
-	
-	if( *p == '\\')
-	{
-	    p++;
-	    switch(*p){
-		case 0:
-		{
-		    *pout = '\0';
-		    break;
+    /* Stop the loop when encountering a terminator in the source string
+       or if a null has been written to the destination. This prevents
+       reading past the end of the source string if the last character
+       is a backslash. */
+    for (p = str; !wroteNull && *p != 0; p++) {
 
-		}
-		case 'n':
-		case 'N':
-		{
-		    *pout = '\n';
-		    break;
-		}
-		case 't':
-		case 'T':
-		{
-		    *pout = '\t';
-		    break;
-		}
-		case 'r':
-		case 'R':
-		{
-		    *pout = '\r';
-		    break;
-		}
-		case 'b':
-		case 'B':
-		{
-		    *pout = '\b';
-		    break;
-		}
-		case 'f':
-		case 'F':
-		{
-		    *pout = '\f';
-		    break;
-		}
-		case ';':
-		case ',':
-		case '"':
-		case '\\':
-		{
-		    *pout = *p;
-		    break;
-		}
-		default:
-		{
-		    *pout = ' ';
-		}		
-	    }
-	} else {
-	    *pout = *p;
-	}
+        if (*p == '\\') {
+            p++;
+            switch (*p) {
+            case 0:
+                {
+                    wroteNull = 1;      //stops iteration so p isn't incremented past the end of str
+                    *pout = '\0';
+                    break;
+                }
+            case 'n':
+            case 'N':
+                {
+                    *pout = '\n';
+                    break;
+                }
+            case 't':
+            case 'T':
+                {
+                    *pout = '\t';
+                    break;
+                }
+            case 'r':
+            case 'R':
+                {
+                    *pout = '\r';
+                    break;
+                }
+            case 'b':
+            case 'B':
+                {
+                    *pout = '\b';
+                    break;
+                }
+            case 'f':
+            case 'F':
+                {
+                    *pout = '\f';
+                    break;
+                }
+            case ';':
+            case ',':
+            case '"':
+            case '\\':
+                {
+                    *pout = *p;
+                    break;
+                }
+            default:
+                {
+                    *pout = ' ';
+                }
+            }
+        } else {
+            *pout = *p;
+        }
 
-	pout++;
-	
+        pout++;
     }
 
     *pout = '\0';
@@ -267,6 +270,8 @@
     return out;
 }
 
+
+
  /* 
   * Returns a quoted copy of a string
  */
# HG changeset patch
# User Geoff Lankow <geoff@darktrojan.net>
# Date 1559701094 -43200
#      Wed Jun 05 14:18:14 2019 +1200
# Node ID 94b581a7a285b611c3691de8f8323eba80d61806
# Parent  58768479ed77a3cf96967140ad1b9781a9670bac
Bug 1553808 - Update libical from upstream. r+a=philipp

diff -r 58768479ed77 -r 94b581a7a285 comm/calendar/libical/src/libical/icalrecur.c
--- a/comm/calendar/libical/src/libical/icalrecur.c	Tue Jun 04 17:54:21 2019 +0200
+++ b/comm/calendar/libical/src/libical/icalrecur.c	Wed Jun 05 14:18:14 2019 +1200
@@ -404,10 +404,15 @@
 
 	wd = icalrecur_string_to_weekday(t);
 
-        if (wd != ICAL_NO_WEEKDAY) {
-            array[i++] = (short) (sign * (wd + 8 * weekno));
-            array[i] = ICAL_RECURRENCE_ARRAY_MAX;
+        /* Sanity check value */
+        if (wd == ICAL_NO_WEEKDAY || weekno >= ICAL_BY_WEEKNO_SIZE) {
+            free(vals_copy);
+            return;
         }
+
+        int position = sign * weekno;
+        array[i++] = (wd + (8 * abs(position))) * ((position < 0) ? -1 : 1);
+        array[i] = ICAL_RECURRENCE_ARRAY_MAX;
     }
 
     free(vals_copy);
# HG changeset patch
# User luis.merino@x41-dsec.de
# Date 1559333634 -10800
#      Fri May 31 23:13:54 2019 +0300
# Node ID 54655ef5946473058177a8a6223c8111a676bcc7
# Parent  94b581a7a285b611c3691de8f8323eba80d61806
Bug 1553820 - Update libical from upstream. r+a=philipp

Like https://github.com/libical/libical/blame/e84714e9d6ec724dca889531e11fb963cadc2dba/src/libical/icalparser.c#L147

diff -r 94b581a7a285 -r 54655ef59464 comm/calendar/libical/src/libical/icalparser.c
--- a/comm/calendar/libical/src/libical/icalparser.c	Wed Jun 05 14:18:14 2019 +1200
+++ b/comm/calendar/libical/src/libical/icalparser.c	Fri May 31 23:13:54 2019 +0300
@@ -190,25 +190,24 @@
 char* parser_get_next_char(char c, char *str, int qm)
 {
     int quote_mode = 0;
-    char* p;
-
-    for(p=str; *p!=0; p++){
-	    if (qm == 1) {
-				if ( quote_mode == 0 && *p=='"' && *(p-1) != '\\' ){
-						quote_mode =1;
-						continue;
-				}
+    char *p = str;
+    char next_char = *p;
+    char prev_char = 0;
 
-				if ( quote_mode == 1 && *p=='"' && *(p-1) != '\\' ){
-						quote_mode =0;
-						continue;
-				}
-	    }
-		
-		if (quote_mode == 0 &&  *p== c  && *(p-1) != '\\' ){
-				return p;
-		} 
+    while (next_char != '\0') {
+        if (prev_char != '\\') {
+            if (qm == 1 && next_char == '"') {
+                /* Encountered a quote, toggle quote mode */
+                quote_mode = !quote_mode;
+            } else if (quote_mode == 0 && next_char == c) {
+                /* Found a matching character out of quote mode, return it */
+                return p;
+            }
+        }
 
+        /* Save the previous character so we can check if it's a backslash in the next iteration */
+        prev_char = next_char;
+        next_char = *(++p);
     }
 
     return 0;
# HG changeset patch
# User Geoff Lankow <geoff@darktrojan.net>
# Date 1559897516 -43200
#      Fri Jun 07 20:51:56 2019 +1200
# Node ID 55c22d6687db36bbf199c813a9f8ddfa9c22c72c
# Parent  54655ef5946473058177a8a6223c8111a676bcc7
Bug 1553820 - Follow-up. r+a=philipp

diff -r 54655ef59464 -r 55c22d6687db comm/calendar/libical/src/libical/icalparser.c
--- a/comm/calendar/libical/src/libical/icalparser.c	Fri May 31 23:13:54 2019 +0300
+++ b/comm/calendar/libical/src/libical/icalparser.c	Fri Jun 07 20:51:56 2019 +1200
@@ -381,10 +381,9 @@
 	/* If the comma is preceded by a '\', then it is a literal and
 	   not a value separator*/  
       
-	if ( (next!=0 && *(next-1) == '\\') ||
-	     (next!=0 && *(next-3) == '\\')
-	    ) 
-	    /*second clause for '/' is on prev line. HACK may be out of bounds */
+  if ((next!=0 && *(next-1) == '\\') ||
+      (next!=0 && (next-3) >= line && *(next-3) == '\\' && *(next-2) == '\r' && *(next-1) == '\n'))
+      /* second clause for '\' is on prev line */
 	{
 	    p = next+1;
 	} else {
# HG changeset patch
# User Geoff Lankow <geoff@darktrojan.net>
# Date 1559896994 -43200
#      Fri Jun 07 20:43:14 2019 +1200
# Node ID 92c00c2241054e5f40c7224fcac1305879f5af4f
# Parent  55c22d6687db36bbf199c813a9f8ddfa9c22c72c
Bug 1555646 - Update libical from upstream. r+a=philipp

Copied from https://github.com/libical/libical/commit/53e68ff6e2133c54ff44df53e8b75ef21125fb3d

diff -r 55c22d6687db -r 92c00c224105 comm/calendar/libical/src/libical/icalparser.c
--- a/comm/calendar/libical/src/libical/icalparser.c	Fri Jun 07 20:51:56 2019 +1200
+++ b/comm/calendar/libical/src/libical/icalparser.c	Fri Jun 07 20:43:14 2019 +1200
@@ -968,6 +968,12 @@
 
 	    /* If it is a VALUE parameter, set the kind of value*/
 	    if (icalparameter_isa(param)==ICAL_VALUE_PARAMETER){
+        const char unknown_type[] =
+            "Got a VALUE parameter with an unknown type";
+        const char illegal_type[] =
+            "Got a VALUE parameter with an illegal type for property";
+        const char *value_err = NULL;
+
 
 		value_kind = (icalvalue_kind)
                     icalparameter_value_to_value_kind(
@@ -979,10 +985,69 @@
 		    /* Ooops, could not parse the value of the
 		       parameter ( it was not one of the defined
 		       values ), so reset the value_kind */
-			
-		    insert_error(
-			tail, str, 
-			"Got a VALUE parameter with an unknown type",
+
+        value_err = unknown_type;
+    }
+    else if (value_kind !=
+             icalproperty_kind_to_value_kind(icalproperty_isa(prop))) {
+        /* VALUE parameter type does not match default type
+           for this property (check for allowed alternate types) */
+
+        switch (prop_kind) {
+        case ICAL_ATTACH_PROPERTY:
+        // case ICAL_IMAGE_PROPERTY:
+            /* Accept BINARY */
+            if (value_kind != ICAL_BINARY_VALUE)
+                value_err = illegal_type;
+            break;
+
+        case ICAL_DTEND_PROPERTY:
+        case ICAL_DUE_PROPERTY:
+        case ICAL_DTSTART_PROPERTY:
+        case ICAL_EXDATE_PROPERTY:
+        case ICAL_RECURRENCEID_PROPERTY:
+            /* Accept DATE */
+            if (value_kind != ICAL_DATE_VALUE)
+                value_err = illegal_type;
+            break;
+
+        case ICAL_GEO_PROPERTY:
+            /* Accept FLOAT (but change to GEO) */
+            if (value_kind != ICAL_FLOAT_VALUE)
+                value_err = illegal_type;
+            else value_kind = ICAL_GEO_VALUE;
+            break;
+
+        case ICAL_RDATE_PROPERTY:
+            /* Accept DATE-TIME, DATE or PERIOD */
+            if (value_kind != ICAL_DATETIME_VALUE &&
+                value_kind != ICAL_DATE_VALUE &&
+                value_kind != ICAL_PERIOD_VALUE)
+                value_err = illegal_type;
+            break;
+
+        case ICAL_TRIGGER_PROPERTY:
+            /* Accept DATE-TIME */
+            if (value_kind != ICAL_DATETIME_VALUE)
+                value_err = illegal_type;
+            break;
+
+        case ICAL_X_PROPERTY:
+            /* Accept ANY value type */
+            break;
+
+        default:
+            /* ONLY default type is allowed */
+            value_err = illegal_type;
+            break;
+        }
+    }
+
+    if (value_err != NULL) {
+        /* Ooops, unknown/illegal VALUE parameter,
+           so reset the value_kind */
+
+        insert_error(tail, str, value_err,
 			ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR);
 			
 		    value_kind = 
# HG changeset patch
# User Geoff Lankow <geoff@darktrojan.net>
# Date 1555368608 -43200
#      Tue Apr 16 10:50:08 2019 +1200
# Node ID dd8f19e7ee1d886118377422f3918c14bd495bd2
# Parent  92c00c2241054e5f40c7224fcac1305879f5af4f
Bug 680620 - Optimise display of events that extend outside the current calendar view; r+a=Fallen

diff -r 92c00c224105 -r dd8f19e7ee1d comm/calendar/base/content/calendar-month-view.xml
--- a/comm/calendar/base/content/calendar-month-view.xml	Fri Jun 07 20:43:14 2019 +1200
+++ b/comm/calendar/base/content/calendar-month-view.xml	Tue Apr 16 10:50:08 2019 +1200
@@ -981,6 +981,15 @@
                 return boxes;
             }
 
+            if (targetDate.compare(this.mStartDate) < 0) {
+                targetDate = this.mStartDate.clone();
+            }
+
+            if (finishDate.compare(this.mEndDate) > 0) {
+                finishDate = this.mEndDate.clone();
+                finishDate.day++;
+            }
+
             if (!targetDate.isDate) {
                 // Reset the time to 00:00, so that we really get all the boxes
                 targetDate.hour = 0;
@@ -1075,6 +1084,10 @@
         <parameter name="aAlarmItem"/>
         <parameter name="aStop"/>
         <body><![CDATA[
+            if (!this.initialized) {
+                return;
+            }
+
             let showIndicator = Preferences.get("calendar.alarms.indicator.show", true);
             let totaltime = Preferences.get("calendar.alarms.indicator.totaltime", 3600);
 
diff -r 92c00c224105 -r dd8f19e7ee1d comm/calendar/base/content/calendar-multiday-view.xml
--- a/comm/calendar/base/content/calendar-multiday-view.xml	Fri Jun 07 20:43:14 2019 +1200
+++ b/comm/calendar/base/content/calendar-multiday-view.xml	Tue Apr 16 10:50:08 2019 +1200
@@ -3557,6 +3557,15 @@
             let finishDate = (aItem.endDate || aItem.dueDate || aItem.entryDate || startDate)
                                  .getInTimezone(timezone);
 
+            if (targetDate.compare(this.mStartDate) < 0) {
+                targetDate = this.mStartDate.clone();
+            }
+
+            if (finishDate.compare(this.mEndDate) > 0) {
+                finishDate = this.mEndDate.clone();
+                finishDate.day++;
+            }
+
             if (!targetDate.isDate) {
                 // Set the time to 00:00 so that we get all the boxes
                 targetDate.hour = 0;
diff -r 92c00c224105 -r dd8f19e7ee1d comm/calendar/base/content/widgets/minimonth.xml
--- a/comm/calendar/base/content/widgets/minimonth.xml	Fri Jun 07 20:43:14 2019 +1200
+++ b/comm/calendar/base/content/widgets/minimonth.xml	Tue Apr 16 10:50:08 2019 +1200
@@ -584,6 +584,15 @@
                 return;
             }
 
+            if (start.compare(this.firstDate) < 0) {
+                start = this.firstDate.clone();
+            }
+
+            if (end.compare(this.lastDate) > 0) {
+                end = this.lastDate.clone();
+                end.day++;
+            }
+
             // We need to compare with midnight of the current day, so reset the
             // time here.
             let current = start.clone().getInTimezone(cal.dtz.defaultTimezone);
# HG changeset patch
# User Kai Engert <kaie>
# Date 1559346540 -7200
#      Sat Jun 01 01:49:00 2019 +0200
# Node ID a819a3a05f2109a7704d76267db248aaa972212f
# Parent  dd8f19e7ee1d886118377422f3918c14bd495bd2
Bug 1519093 - prompt for smartcard PIN when S/MIME signing. r=keeler a=jorgk

diff -r dd8f19e7ee1d -r a819a3a05f21 comm/comm-extra-nss.symbols
--- a/comm/comm-extra-nss.symbols	Tue Apr 16 10:50:08 2019 +1200
+++ b/comm/comm-extra-nss.symbols	Sat Jun 01 01:49:00 2019 +0200
@@ -1,2 +1,3 @@
+CERT_GetCertNicknames
 NSS_CMSSignedData_GetDigestAlgs
 NSS_CMSSignedData_HasDigests
diff -r dd8f19e7ee1d -r a819a3a05f21 comm/mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
--- a/comm/mailnews/extensions/smime/src/nsMsgComposeSecure.cpp	Tue Apr 16 10:50:08 2019 +1200
+++ b/comm/mailnews/extensions/smime/src/nsMsgComposeSecure.cpp	Sat Jun 01 01:49:00 2019 +0200
@@ -28,6 +28,7 @@
 #include "nspr.h"
 #include "pkix/Result.h"
 #include "nsNSSCertificate.h"
+#include "nsNSSHelper.h"
 
 using namespace mozilla::mailnews;
 using namespace mozilla;
@@ -888,6 +889,14 @@
   RefPtr<SharedCertVerifier> certVerifier(GetDefaultCertVerifier());
   NS_ENSURE_TRUE(certVerifier, NS_ERROR_UNEXPECTED);
 
+  // Calling CERT_GetCertNicknames has the desired side effect of
+  // traversing all tokens, and bringing up prompts to unlock them.
+  nsCOMPtr<nsIInterfaceRequestor> ctx = new PipUIContext();
+  CERTCertNicknames *result_unused =
+    CERT_GetCertNicknames(CERT_GetDefaultCertDB(),
+    SEC_CERT_NICKNAMES_USER, ctx);
+  CERT_FreeNicknames(result_unused);
+
   UniqueCERTCertList builtChain;
   if (!mEncryptionCertDBKey.IsEmpty()) {
     res = certdb->FindCertByDBKey(mEncryptionCertDBKey,
# HG changeset patch
# User aceman <acelists@atlas.sk>
# Date 1560286448 -7200
#      Tue Jun 11 22:54:08 2019 +0200
# Node ID a9f99cffa752340d368ddf90ba813c44c82eafce
# Parent  a819a3a05f2109a7704d76267db248aaa972212f
Bug 1506613 - Check parser_>m_db for null in MaildirStoreParser::TimerCallback to avoid crash. r=mkmelin a=jorgk

diff -r a819a3a05f21 -r a9f99cffa752 comm/mailnews/local/src/nsMsgMaildirStore.cpp
--- a/comm/mailnews/local/src/nsMsgMaildirStore.cpp	Sat Jun 01 01:49:00 2019 +0200
+++ b/comm/mailnews/local/src/nsMsgMaildirStore.cpp	Tue Jun 11 22:54:08 2019 +0200
@@ -1239,8 +1239,8 @@
     nsCOMPtr<nsIMsgPluggableStore> store;
     parser->m_folder->GetMsgStore(getter_AddRefs(store));
     parser->m_timer->Cancel();
-    parser->m_db->SetSummaryValid(true);
-//    store->SetSummaryFileValid(parser->m_folder, parser->m_db, true);
+    if (parser->m_db) parser->m_db->SetSummaryValid(true);
+    // store->SetSummaryFileValid(parser->m_folder, parser->m_db, true);
     if (parser->m_listener)
     {
       nsresult rv;
