From af83cbabffa13f6f642ce0659deb7fa381b85c06 Mon Sep 17 00:00:00 2001
From: "Marc H. Thoben" <mthoben@mpipz.mpg.de>
Date: Mon, 1 Feb 2016 16:03:05 +0100
Subject: [PATCH 1/3] Handle email addresses without tags HOME or WORK when
 downloading differently.

* First encountered address will be put into PrimaryEmail.
* Second encountered address will be put into SecondEmail.
* All other emails will be ignored...
* ...AND DELETED when syncing back to the server!
---
 .../content/sogo-connector/general/vcards.utils.js | 24 +++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/chrome/content/sogo-connector/general/vcards.utils.js b/chrome/content/sogo-connector/general/vcards.utils.js
index 03a8c2e..9be9575 100644
--- a/chrome/content/sogo-connector/general/vcards.utils.js
+++ b/chrome/content/sogo-connector/general/vcards.utils.js
@@ -384,12 +384,7 @@ let _insertCardMethods = {
             props["SecondEmail"] = values[0];
         }
         else {
-            if (props["PrimaryEmail"] && props["PrimaryEmail"].length > 0) {
-                props["SecondEmail"] = values[0];
-            }
-            else {
-                props["PrimaryEmail"] = values[0];
-            }
+            props["PrimaryEmail"] = values[0];
         }
     },
     url: function(props, parameters, values) {
@@ -539,7 +534,22 @@ function InsertCardData(card, tag, parameters, values) {
                 card.deleteProperty(k);
             }
             else {
-                card.setProperty(k, properties[k]);
+                let tmpPrimaryEmail = card.getProperty("PrimaryEmail", "");
+                let tmpSecondEmail = card.getProperty("SecondEmail", "");
+                if (k == "PrimaryEmail") {
+                    if (tmpPrimaryEmail.length == 0) {
+                        card.setProperty(k, properties[k]);
+                    }
+                    else if (tmpSecondEmail.length == 0) {
+                        card.setProperty("SecondEmail", properties[k]);
+                    }
+                }
+                else if (k == "SecondEmail" && tmpSecondEmail.length == 0) {
+                    card.setProperty("SecondEmail", properties[k]);
+                }
+                else {
+                    card.setProperty(k, properties[k]);
+                }
             }
             // if (k == "PhotoURI" || k == "PhotoName") {
             //     dump("  card value: " + card.getProperty(k, "(nil)") + "\n");
-- 
2.6.2

