summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorniko <niko>2012-10-27 00:43:25 (GMT)
committerniko <niko>2012-10-27 00:43:25 (GMT)
commit23f86ba282449381f8ed5dc82b50673a02c6b93f (patch)
treeb6ebeb34684c53bc09620727f0443c18be6be0f4
parent3ce6a3cf783d624c84e0a05a6a03310ad43c6e9a (diff)
downloadsynckolab-23f86ba282449381f8ed5dc82b50673a02c6b93f.tar.gz
rewrite parsing
-rw-r--r--src/chrome/content/synckolab/addressbook.js9
-rw-r--r--src/chrome/content/synckolab/addressbookTools.js306
-rw-r--r--src/chrome/content/synckolab/calendar.js4
-rw-r--r--src/chrome/content/synckolab/synckolab.js11
-rw-r--r--src/chrome/content/synckolab/tools.js495
-rw-r--r--src/chrome/content/synckolab/tools/text.js2
-rw-r--r--test/lib/testOverride.js2
-rw-r--r--test/suite.js2
-rw-r--r--test/synckolab/parser/kolab2/contactTest.js19
-rw-r--r--test/synckolab/parser/kolab2/json/contactFullTest.json2
-rw-r--r--test/synckolab/parser/kolab2/json/test-image.json8
-rw-r--r--test/synckolab/parser/kolab2/raw/contactFullTest.eml5
-rw-r--r--test/synckolab/parser/kolab2/raw/contactMinimalTest.eml5
-rw-r--r--test/synckolab/parser/kolab2/raw/testcontact.eml2
-rw-r--r--test/synckolab/parser/kolab3/calendarTest.js4
-rw-r--r--test/synckolab/parser/kolab3/contactTest.js13
-rw-r--r--test/synckolab/parser/kolab3/json/contact.complex.mime.json6
-rw-r--r--test/synckolab/parser/kolab3/json/contact.simple.mime.json4
-rw-r--r--test/synckolab/parser/kolab3/json/contact.test.mime.json4
-rw-r--r--test/synckolab/parser/kolab3/json/contact.test2.mime.json4
-rw-r--r--test/synckolab/parser/kolab3/json/contact.test3.mime.json1
-rw-r--r--test/synckolab/parser/kolab3/raw/contact.complex.mime2
-rw-r--r--test/synckolab/parser/kolab3/raw/contact.test3.mime50
-rw-r--r--test/synckolab/parser/kolab3/xml/contact.complex.mime.xml7
-rw-r--r--test/synckolab/parser/kolab3/xml/contact.simple.mime.xml1
-rw-r--r--test/synckolab/parser/kolab3/xml/contact.test.mime.xml1
-rw-r--r--test/synckolab/parser/kolab3/xml/contact.test2.mime.xml1
-rw-r--r--test/synckolab/parser/kolab3/xml/contact.test3.mime.xml17
-rw-r--r--test/synckolab/tools/data/multipart.eml74
-rw-r--r--test/synckolab/tools/toolsTest.js19
30 files changed, 689 insertions, 391 deletions
diff --git a/src/chrome/content/synckolab/addressbook.js b/src/chrome/content/synckolab/addressbook.js
index f536fe8..737d144 100644
--- a/src/chrome/content/synckolab/addressbook.js
+++ b/src/chrome/content/synckolab/addressbook.js
@@ -168,7 +168,7 @@ synckolab.AddressBook = {
// get the dbfile from the local disk
var idxEntry = synckolab.tools.file.getSyncDbFile(cConfig, cUID);
// write the current content in the sync-db file (parse to json object first)
- synckolab.tools.writeSyncDBFile(idxEntry, synckolab.addressbookTools.parseMessageContent(synckolab.tools.stripMailHeader(abcontent)));
+ synckolab.tools.writeSyncDBFile(idxEntry, synckolab.addressbookTools.parseMessageContent(synckolab.tools.parseMail(abcontent)));
synckolab.tools.logMessage("Writing card to imap" , synckolab.global.LOG_INFO + synckolab.global.LOG_AB);
@@ -320,7 +320,7 @@ synckolab.AddressBook = {
cConfig.recentProcessed.push(cUID);
// write the current content in the sync-db file (parse to json object first)
- synckolab.tools.writeSyncDBFile(idxEntry, synckolab.addressbookTools.parseMessageContent(synckolab.tools.stripMailHeader(abcontent)));
+ synckolab.tools.writeSyncDBFile(idxEntry, synckolab.addressbookTools.parseMessageContent(synckolab.tools.parseMail(abcontent)));
var listener = this;
synckolab.main.writeImapMessage(abcontent, cConfig,
@@ -725,6 +725,7 @@ synckolab.AddressBook = {
// parse the new item
newCard = this.tools.parseMessageContent(fileContent);
+
if (newCard && newCard.isMailList)
{
synckolab.tools.logMessage("got mailing list " + this.tools.getUID(newCard) +"\n " + newCard.toSource(), synckolab.global.LOG_WARNING + synckolab.global.LOG_AB);
@@ -1020,7 +1021,7 @@ synckolab.AddressBook = {
abcontent = this.tools.card2Message(foundCard, this.gConfig.email, this.gConfig.format);
// write the current content in the sync-db file
- synckolab.tools.writeSyncDBFile(idxEntry, this.tools.parseMessageContent(synckolab.tools.stripMailHeader(abcontent)));
+ synckolab.tools.writeSyncDBFile(idxEntry, this.tools.parseMessageContent(synckolab.tools.parseMail(abcontent)));
return abcontent;
}
return null; // Return null, we either updated nothing or updated only local
@@ -1111,7 +1112,7 @@ synckolab.AddressBook = {
// remember this message for update - generate mail message (incl. extra fields)
abcontent = this.tools.card2Message(foundCard, this.gConfig.email, this.gConfig.format);
// write the current content in the sync-db file
- synckolab.tools.writeSyncDBFile(idxEntry, this.tools.parseMessageContent(synckolab.tools.stripMailHeader(abcontent)));
+ synckolab.tools.writeSyncDBFile(idxEntry, this.tools.parseMessageContent(synckolab.tools.parseMail(abcontent)));
return abcontent;
}
diff --git a/src/chrome/content/synckolab/addressbookTools.js b/src/chrome/content/synckolab/addressbookTools.js
index ed42a09..5fb8436 100644
--- a/src/chrome/content/synckolab/addressbookTools.js
+++ b/src/chrome/content/synckolab/addressbookTools.js
@@ -564,7 +564,7 @@ synckolab.addressbookTools.findCard = function (cards, vId, directory) {
*
* @param xml a dom node of a card or a string with the xml
* @param card the card object to update
- * @param attachment optional attachment image (photo)
+ * @param attachment optional attachments (photo)
*/
synckolab.addressbookTools.xml2Card = function (xml, card, attachment) {
var cur;
@@ -707,14 +707,15 @@ synckolab.addressbookTools.xml2Card = function (xml, card, attachment) {
// KOLAB 3
case "N":
- this.setCardProperty(card, "FirstName", cur.getXmlResult("SURNAME", ""));
- this.setCardProperty(card, "LastName", cur.getXmlResult("GIVEN", ""));
+ this.setCardProperty(card, "FirstName", cur.getXmlResult("GIVEN", ""));
+ this.setCardProperty(card, "LastName", cur.getXmlResult("SURNAME", ""));
// others: ADDITIONAL/PREFIX/SUFFIX
found = true;
break;
case "FN": // kolab 3
case "DISPLAY-NAME": // kolab 2
+ //synckolab.tools.logMessage("DISPLAY NAME while parsing - " + cur.getFirstData() , synckolab.global.LOG_DEBUG + synckolab.global.LOG_AB);
this.setCardProperty(card, "DisplayName", cur.getFirstData());
break;
@@ -1004,25 +1005,56 @@ synckolab.addressbookTools.xml2Card = function (xml, card, attachment) {
tok = cur.getChildNode("uri");
if(tok) {
value = tok.getFirstData();
- types = value.substring(0, 30); // get the first few bytes
+
+ types = value.substring(0, 100); // get the first few bytes
+ synckolab.tools.logMessage("checking photo: " + types + " last 10 bytes " + value.substring(value.length - 15), synckolab.global.LOG_DEBUG + synckolab.global.LOG_AB);
+
if(types.indexOf("data:") !== -1) { // got an inline data uri
// get the correct type:
// data:image/png;base64,BASE64DATA
types = types.substring(5); // cut away data:
tok = types.indexOf(";"); // search for the mime
- where = synckolab.tools.file.analyzeMimeType(types.substring(0, tok).toLowerCase());
+ where = synckolab.tools.file.analyzeMimeType(types.substring(0, tok));
// set the type
this.setCardProperty(card, "PhotoType", "inline");
this.setCardProperty(card, "PhotoName", "photo." + where); // generate filename
-
+
+ synckolab.tools.logMessage("photo is inline: " + value.length + " last 10 bytes " + value.substring(value.length - 10), synckolab.global.LOG_INFO + synckolab.global.LOG_AB);
+
where = types.substring(tok);
if(where.indexOf("base64") !== -1) {
tok = value.indexOf(",");
// get rid of newlines and =
- this.setCardProperty(card, "PhotoData", value.substring(tok+1).replace("=3D", "").replace(/[\r\n \t=]+/g, ""));
+ this.setCardProperty(card, "PhotoData", value.substring(tok+1).replace("=3D", "=").replace(/[\r\n \t]+/g, ""));
} else {
synckolab.tools.logMessage("Unknown photo encoding: " + value.substring(0, 30), synckolab.global.LOG_INFO + synckolab.global.LOG_AB);
}
+ } else if(types.indexOf("cid:") !== -1) {
+ // photo is attached (content id)
+
+ types = types.substring(4); // strip the cid:
+ synckolab.tools.logMessage("Looking for content id: " + types, synckolab.global.LOG_INFO + synckolab.global.LOG_AB);
+ if(!attachment) {
+ synckolab.tools.logMessage("no attachments available!", synckolab.global.LOG_ERROR + synckolab.global.LOG_AB);
+ }
+ value = -1;
+
+ for(where = 0; where < attachment.length; where++) {
+ if(attachment[where].id === types) {
+ value = where;
+ break;
+ }
+ }
+
+ if(value !== -1) {
+ this.setCardProperty(card, "PhotoType", "inline");
+ this.setCardProperty(card, "PhotoName", attachment[value].name);
+ this.setCardProperty(card, "PhotoData", attachment[value].content.replace(/[\r\n ]/g, "")); // get rid of whitespace
+ }
+ else {
+ synckolab.tools.logMessage("attachment "+ types +" NOT found!", synckolab.global.LOG_ERROR + synckolab.global.LOG_AB);
+ }
+
}
}
@@ -1033,9 +1065,34 @@ synckolab.addressbookTools.xml2Card = function (xml, card, attachment) {
if (cur.firstChild === null) {
break;
}
-
+ where = cur.getFirstData();
this.setCardProperty(card, "PhotoName", cur.getFirstData());
- // the attachment already happened in parseMessageContent
+ // check if we have a picture with that mail attached
+ value = -1;
+ for(types = 0; types < attachment.length; types++) {
+ if(attachment[types].id === where) {
+ value = types;
+ break;
+ }
+ }
+
+ // if we have only one and its an image.. use it
+ if(value === -1) {
+ for(types = 0; types < attachment.length; types++) {
+ if(attachment[types].contentType.indexOf("image") !== -1) {
+ value = types;
+ break;
+ }
+ }
+ }
+
+ if(value !== -1) {
+ this.setCardProperty(card, "PhotoType", "inline");
+ this.setCardProperty(card, "PhotoName", attachment[value].name);
+ this.setCardProperty(card, "PhotoData", attachment[value].content);
+ } else {
+ this.setCardProperty(card, "PhotoURI", null);
+ }
break;
@@ -1159,7 +1216,7 @@ synckolab.addressbookTools.xml2Card = function (xml, card, attachment) {
if (cur.firstChild === null) {
break;
}
- this.setCardProperty(card, "AllowRemoteContent", 'TRUE' === cur.getFirstData().toUpperCase());
+ this.setCardProperty(card, "AllowRemoteContent", ('TRUE' === cur.getFirstData().toUpperCase()));
break;
// set the prefer mail format (this is not covered by kolab itself)
@@ -1601,6 +1658,9 @@ synckolab.addressbookTools.card2Kolab3 = function (card, skipHeader, fields) {
var displayName = "";
var xml = "";
+ // attach array
+ var attach = [];
+
if(!skipHeader) {
xml += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n";
xml += "<vcards xmlns=\"urn:ietf:params:xml:ns:vcard-4.0\">\n";
@@ -1631,16 +1691,18 @@ synckolab.addressbookTools.card2Kolab3 = function (card, skipHeader, fields) {
xml += synckolab.tools.text.nodeContainerWithContent("fn", "text", displayName);
}
- // then name
- xml += " <n>\n";
- xml += this.getXmlProperty(card, "LastName", "surname");
- xml += this.getXmlProperty(card, "FirstName", "given");
- /* also available in kolab3:
- <additional/>
- <prefix/>
- <suffix/>
- */
- xml += " </n>\n";
+ if (this.haveCardProperty(card, "FirstName") || this.haveCardProperty(card, "LastName")) {
+ // then name
+ xml += " <n>\n";
+ xml += this.getXmlProperty(card, "LastName", "surname");
+ xml += this.getXmlProperty(card, "FirstName", "given");
+ /* also available in kolab3:
+ <additional/>
+ <prefix/>
+ <suffix/>
+ */
+ xml += " </n>\n";
+ }
}
@@ -1701,8 +1763,26 @@ synckolab.addressbookTools.card2Kolab3 = function (card, skipHeader, fields) {
var fileName = this.getCardProperty(card, "PhotoName");
// based on the name - get the MIME
ptype = synckolab.tools.file.getMimeType(fileName.substring(fileName.lastIndexOf(".")+1));
- xml += " <photo>\n <uri>data:" + ptype + ";base64," + synckolab.tools.text.splitInto(this.getCardProperty(card, "PhotoData"), 72) +
- "</uri>\n </photo>";
+
+ // basedon the length attach it or write it in the data (-buffer)
+ if(this.getCardProperty(card, "PhotoData").length < (4096-20)) {
+ xml += " <photo>\n <uri>data:" + ptype + ";base64," + synckolab.tools.text.splitInto(this.getCardProperty(card, "PhotoData"), 72) +
+ "</uri>\n </photo>";
+ } else {
+ synckolab.tools.logMessage("attaching resource because of length " + this.getCardProperty(card, "PhotoData").length, synckolab.global.LOG_INFO + synckolab.global.LOG_AB);
+ // too big add - need to attach
+ var cid = synckolab.tools.text.randomVcardId() + "@kolab.resource.synckolab";
+
+ xml += " <photo>\n <uri>cid:"+ cid + "</uri>\n </photo>";
+
+ var newAttach = {
+ id: cid,
+ type: ptype,
+ name: fileName,
+ data: this.getCardProperty(card, "PhotoData")
+ };
+ attach.push(newAttach);
+ }
}
xml += this.getXmlProperty(card, "AimScreenName", "impp", "uri");
@@ -1757,12 +1837,12 @@ synckolab.addressbookTools.card2Kolab3 = function (card, skipHeader, fields) {
// custom fields are last
// if the mail format is set...
- if (this.getCardProperty(card, "PreferMailFormat") && this.getCardProperty(card, "PreferMailFormat") !== synckolab.addressbookTools.MAIL_FORMAT_UNKNOWN) {
- if (Number(this.getCardProperty(card, "PreferMailFormat")) === this.MAIL_FORMAT_PLAINTEXT) {
- xml += "<x-custom><identifier>X-PreferMailFormat</identifier><value>text</value></x-custom>\n";
- } else if (Number(this.getCardProperty(card, "PreferMailFormat")) === this.MAIL_FORMAT_HTML) {
- xml += "<x-custom><identifier>X-PreferMailFormat</identifier><value>html</value></x-custom>\n";
- }
+ if (Number(this.getCardProperty(card, "PreferMailFormat")) === this.MAIL_FORMAT_PLAINTEXT) {
+ xml += "<x-custom><identifier>X-PreferMailFormat</identifier><value>text</value></x-custom>\n";
+ } else if (Number(this.getCardProperty(card, "PreferMailFormat")) === this.MAIL_FORMAT_HTML) {
+ xml += "<x-custom><identifier>X-PreferMailFormat</identifier><value>html</value></x-custom>\n";
+ } else {
+ xml += "<x-custom><identifier>X-PreferMailFormat</identifier><value>unknown</value></x-custom>\n";
}
if (this.getCardProperty(card, "Custom1")) {
@@ -1799,7 +1879,15 @@ synckolab.addressbookTools.card2Kolab3 = function (card, skipHeader, fields) {
xml += "</vcards>\n";
}
- return xml;
+ if(attach.length == 0) {
+ return xml;
+ }
+
+ // we got attachments
+ return {
+ content: xml,
+ attach: attach
+ };
};
/**
@@ -1814,7 +1902,7 @@ synckolab.addressbookTools.card2Pojo = function (card, uid, fields) {
}
var pojo = {
- synckolab : synckolab.config.version, // synckolab version
+ synckolab: synckolab.config.version, // synckolab version
type : "contact", // a contact
isMailList : false,
ts : new Date().getTime() // the current time
@@ -1829,19 +1917,33 @@ synckolab.addressbookTools.card2Pojo = function (card, uid, fields) {
var copyFields = ["FirstName", "LastName", "DisplayName", "JobTitle", "NickName",
"PrimaryEmail", "SecondEmail", "Category", "Company",
"HomePhone", "WorkPhone", "CellularNumber", "FaxNumber", "PagerNumber",
- "CellularNumber", "HomePhone", "FaxNumber", "WorkPhone",
- "PagerNumber", "BirthYear", "BirthMonth", "BirthDay",
- "AnniversaryYear", "AnniversaryMonth", "AnniversaryDay", "HomeAddress",
- "HomeAddress2", "HomeCity", "HomeState", "HomeZipCode", "HomeCountry", "WorkAddress",
- "WorkAddress2", "WorkCity", "WorkState", "WorkZipCode", "WorkCountry",
- "Notes", "Department", "WebPage1", "WebPage2", "WebPage3",
- "AimScreenName", "Custom1", "Custom2", "Custom3", "Custom4", "AllowRemoteContent", "PreferMailFormat",
- "Profesion"];
+ "CellularNumber", "HomePhone", "FaxNumber", "WorkPhone", "PagerNumber",
+ "HomeAddress", "HomeAddress2", "HomeCity", "HomeState", "HomeZipCode", "HomeCountry",
+ "WorkAddress", "WorkAddress2", "WorkCity", "WorkState", "WorkZipCode", "WorkCountry",
+ "Notes", "Department", "Profession", "WebPage1", "WebPage2", "WebPage3",
+ "AimScreenName", "Custom1", "Custom2", "Custom3", "Custom4"];
var i;
for(i = 0; i < copyFields.length; i++) {
- this.setCardProperty(pojo, copyFields[i], this.getCardProperty(card, copyFields[i]));
+ if(this.haveCardProperty(card, copyFields[i])) {
+ var prop = this.getCardProperty(card, copyFields[i]);
+ this.setCardProperty(pojo, copyFields[i], prop);
+ //synckolab.tools.logMessage("read field: "+ copyFields[i] +": " + prop + " VS. " this.getCardProperty(pojo, copyFields[i]), synckolab.global.LOG_WARNING);
+ }
}
-
+
+ // some we want as number
+ copyFields = [ "AnniversaryYear", "AnniversaryMonth", "AnniversaryDay",
+ "BirthYear", "BirthMonth", "BirthDay",
+ "AllowRemoteContent", "PreferMailFormat"];
+ for(i = 0; i < copyFields.length; i++) {
+ if(this.haveCardProperty(card, copyFields[i])) {
+ var num = this.getCardProperty(card, copyFields[i]);
+ if(!isNaN(num)) {
+ this.setCardProperty(pojo, copyFields[i], Number(num));
+ }
+ }
+ }
+
this.setUID(pojo, uid);
// handle photo
@@ -1854,41 +1956,40 @@ synckolab.addressbookTools.card2Pojo = function (card, uid, fields) {
* found in ~profil/Photos/FILENAME
* 2. create an attachment name FILENAME with the content (base64 encoded)
*/
+ synckolab.tools.logMessage("Trying to read image: "+uri, synckolab.global.LOG_DEBUG);
// image is the last part of the uri
- var image = uri.substring(uri.lastIndexOf("/"));
+ var image = uri.substring(uri.lastIndexOf("/") + 1);
- var file = synckolab.tools.getProfileFolder();
+ var file = synckolab.tools.getFile(uri);
try {
- file.append("Photos");
if (!file.exists()) {
- file.create(1, parseInt("0775", 8));
- }
-
- // fix newName: we can have C:\ - file:// and more - remove all that and put it in the photos folder
- var imageName = image.replace(/[^A-Za-z0-9._ \-]/g, "");
- imageName = imageName.replace(/ /g, "_");
-
- file.append(imageName);
- // file actually exists - we can try to read it and attach it
- var fileContent = this.readFileIntoBase64(file);
-
- // if we have a file - put it in
- if (fileContent !== null) {
- this.setCardProperty("PhotoType", "inline");
- this.setCardProperty("PhotoData", fileContent);
- // last part of the path is the name
- this.setCardProperty("PhotoName", uri.substring(uri.lastIndexOf("/")));
+ synckolab.tools.logMessage("Photo does not exist: "+uri, synckolab.global.LOG_WARNING);
+
+ } else {
+ // fix newName: we can have C:\ - file:// and more - remove all that and put it in the photos folder
+ //var imageName = image.replace(/[^A-Za-z0-9._ \-]/g, "");
+ //imageName = imageName.replace(/ /g, "_");
+
+ // file actually exists - we can try to read it and attach it
+ var fileContent = synckolab.tools.readFileIntoBase64(file);
+
+ // if we have a file - put it in
+ if (fileContent !== null) {
+ this.setCardProperty(pojo, "PhotoType", "inline");
+ this.setCardProperty(pojo, "PhotoData", fileContent);
+ // last part of the path is the name
+ this.setCardProperty(pojo, "PhotoName", image);
+ }
}
}
catch (ex)
{
- this.logMessage("Unable to read image: "+image+"\n" + ex, synckolab.global.LOG_WARNING);
- return null;
+ synckolab.tools.logMessage("Unable to read image: "+image+"\n" + ex, synckolab.global.LOG_WARNING);
}
} else {
- this.setCardProperty("PhotoType", "web");
- this.setCardProperty("PhotoData", uri);
+ this.setCardProperty(pojo, "PhotoType", "web");
+ this.setCardProperty(pojo, "PhotoData", uri);
}
}
@@ -2149,7 +2250,7 @@ synckolab.addressbookTools.equalsContact = function (a, b) {
"PreferMailFormat", "BirthYear", "BirthMonth", "BirthDay", "AnniversaryYear", "AnniversaryMonth", "AnniversaryDay",
// now for strings
"FirstName", "LastName", "DisplayName", "NickName", "PrimaryEmail", "SecondEmail", "AimScreenName", "WorkPhone", "HomePhone", "FaxNumber", "PagerNumber", "CellularNumber", "HomeAddress", "HomeAddress2", "HomeCity", "HomeState", "HomeZipCode", "HomeCountry", "WebPage2", "JobTitle",
- "Department", "Company", "WorkAddress", "WorkAddress2", "WorkCity", "WorkState", "WorkZipCode", "WorkCountry", "WebPage1", "Custom1", "Custom2", "Custom3", "Custom4", "Notes", "PhotoURI" ]; // PhotoType, PhotoName
+ "Department", "Company", "WorkAddress", "WorkAddress2", "WorkCity", "WorkState", "WorkZipCode", "WorkCountry", "WebPage1", "Custom1", "Custom2", "Custom3", "Custom4", "Notes", "PhotoURI", "PhotoData", "PhotoType"]; // ignore photo name
numericFieldCount = 7;
}
@@ -2185,6 +2286,17 @@ synckolab.addressbookTools.equalsContact = function (a, b) {
return false;
}
}
+
+ if(sa.length !== sb.length) {
+ if(sa.length > 100) {
+ sa = sa.length;
+ }
+ if(sb.length > 100) {
+ sb = sb.length;
+ }
+ synckolab.tools.logMessage("not equals " + fieldsArray[i] + " '" + sa + "' vs. '" + sb + "'", synckolab.global.LOG_INFO + synckolab.global.LOG_AB);
+ return false;
+ }
// check if not equals
if (sa !== sb) {
@@ -2522,6 +2634,10 @@ synckolab.addressbookTools.Xml2List = function (topNode, card) {
* @return true if the message contains a list instead of a card
*/
synckolab.addressbookTools.isMailList = function (message) {
+ if(!message) {
+ return false;
+ }
+
if(message.synckolab) {
return message.type === "maillist";
}
@@ -2571,21 +2687,18 @@ synckolab.addressbookTools.parseMessageContent = function (message) {
// the current time
};
- // its possible we have an image - attach it (still base64 encoded)
- if(message.image) {
- this.setCardProperty(card, "PhotoName", message.imageName); // generate filename
- this.setCardProperty(card, "PhotoType", "inline");
- this.setCardProperty(card, "PhotoData", message.image.replace("=3D", "").replace(/[\r\n \t=]+/g, ""));
+ if(!message.content) {
+ synckolab.tools.logMessage("single part message", synckolab.global.LOG_DEBUG + synckolab.global.LOG_AB);
+ message = {
+ content: message
+ };
+ } else {
+ synckolab.tools.logMessage("multi part message with " + message.parts.length + " parts", synckolab.global.LOG_INFO + synckolab.global.LOG_AB);
}
- // form now one: message is just a string (the content)
- if(message.content) {
- message = message.content;
- }
-
// check for xml style
- if (message.indexOf("<?xml") !== -1 || message.indexOf("<?XML") !== -1) {
- if (this.xml2Card(message, card)) {
+ if (message.content.indexOf("<?xml") !== -1 || message.content.indexOf("<?XML") !== -1) {
+ if (this.xml2Card(message.content, card, message.parts)) {
card.sha1 = synckolab.addressbookTools.genConSha1(card);
return card;
}
@@ -2593,8 +2706,25 @@ synckolab.addressbookTools.parseMessageContent = function (message) {
synckolab.tools.logMessage("VCARD/VLIST!", synckolab.global.LOG_INFO + synckolab.global.LOG_AB);
}
+ var i;
+ // its possible we have an image - attach it (still base64 encoded)
+ if(message.parts) {
+ for(i = 0; i < message.parts; i++) {
+ if(message.parts[i].contentType.indexOf("image") !== -1) {
+ this.setCardProperty(card, "PhotoName", message.parts[i].name); // generate filename
+ this.setCardProperty(card, "PhotoType", "inline");
+ this.setCardProperty(card, "PhotoData", message.parts[i].data.replace("=3D", "").replace(/[\r\n \t=]+/g, ""));
+ }
+
+ }
+ }
+
+ // unwrap
+ if(message.content) {
+ message = message.content;
+ }
+
// decode utf8
- message = synckolab.tools.text.utf8.decode(message);
// check for errors in the decoded message
if (message.indexOf("TYPE=3D") !== -1) {
@@ -2609,7 +2739,7 @@ synckolab.addressbookTools.parseMessageContent = function (message) {
var lines = message.split("\n");
// check if we got a list
- for ( var i = 0; i < lines.length; i++) {
+ for (i = 0; i < lines.length; i++) {
if (lines[i].toUpperCase().indexOf("X-LIST") !== -1) {
synckolab.tools.logMessage("parsing a list: " + message, synckolab.global.LOG_DEBUG + synckolab.global.LOG_AB);
if (!this.vList2Card(lines[i], lines, card)) {
@@ -3485,6 +3615,7 @@ synckolab.addressbookTools.card2Message = function (card, email, format, fields)
synckolab.tools.logMessage("creating message out of card... ", synckolab.global.LOG_INFO + synckolab.global.LOG_AB);
+ var data,content;
// for the kolab xml format
if (format === "xml-k2") {
// mailing list
@@ -3495,10 +3626,12 @@ synckolab.addressbookTools.card2Message = function (card, email, format, fields)
var img = null;
var ptype = this.getCardProperty(card, "PhotoType");
if(ptype === "inline") {
- img = {
+ img = [];
+ img.push({
+ id: null,
name: this.getCardProperty(card, "PhotoName"),
data: this.getCardProperty(card, "PhotoData")
- };
+ });
}
return synckolab.tools.generateMail(this.getUID(card), email, "", "application/x-vnd.kolab.contact", true, synckolab.tools.text.utf8.encode(this.card2Xml(card, fields)), this.card2Human(card), img);
@@ -3508,7 +3641,16 @@ synckolab.addressbookTools.card2Message = function (card, email, format, fields)
if (card.isMailList) {
return synckolab.tools.generateMail(this.getUID(card), email, "", "application/x-vcard.list+xml", true, synckolab.tools.text.utf8.encode(this.list2Kolab3(card, fields)), this.list2Human(card));
} else {
- return synckolab.tools.generateMail(this.getUID(card), email, "", "application/vcard+xml", true, synckolab.tools.text.utf8.encode(this.card2Kolab3(card, fields)), this.card2Human(card));
+ data = this.card2Kolab3(card, fields);
+ if(data.content) {
+ content = data.content;
+ data = data.attach;
+ } else {
+ content = data;
+ data = null;
+ }
+
+ return synckolab.tools.generateMail(this.getUID(card), email, "", "application/vcard+xml", true, synckolab.tools.text.utf8.encode(content), this.card2Human(card), data);
}
}
diff --git a/src/chrome/content/synckolab/calendar.js b/src/chrome/content/synckolab/calendar.js
index 070bb27..0f62ed1 100644
--- a/src/chrome/content/synckolab/calendar.js
+++ b/src/chrome/content/synckolab/calendar.js
@@ -578,6 +578,10 @@ synckolab.Calendar = {
* The content is already parsed and stripped of any headers
*/
parseMessage : function (fileContent) {
+ // no attachments - thus: unwrap
+ if(fileContent.content) {
+ fileContent = fileContent.content;
+ }
// create a new item in the itemList for display
this.curItemInList = this.doc.createElement("treerow");
diff --git a/src/chrome/content/synckolab/synckolab.js b/src/chrome/content/synckolab/synckolab.js
index 19b3ac4..fda94f6 100644
--- a/src/chrome/content/synckolab/synckolab.js
+++ b/src/chrome/content/synckolab/synckolab.js
@@ -913,12 +913,12 @@ synckolab.main.getMessageIntoContent = function(content) {
onStopRequest: function (aRequest, aContext, aStatusCode) {
synckolab.tools.logMessage("got Message [" + content.message + "]:\n" + content.fileContent, synckolab.global.LOG_DEBUG);
- // remove the header of the content
- content.fileContent = synckolab.tools.stripMailHeader(content.fileContent);
+ // parse the mail
+ synckolab.main.currentMessage.fileContent = synckolab.tools.parseMail(content.fileContent);
// make sure we dont come into an endless loop here
synckolab.global.triggerRunning = true;
- content.nextFunc(content);
+ content.nextFunc(synckolab.main.currentMessage.fileContent);
synckolab.global.triggerRunning = false;
}
}, false, null, msgWindow, aurl
@@ -968,7 +968,7 @@ synckolab.main.copyToFolder = function(fileName, folderUri, listener)
/**
* we now got the message content. this needs to parsed and checked
*/
-synckolab.main.parseMessageRunner = function()
+synckolab.main.parseMessageRunner = function(mail)
{
// pause sync...
if (synckolab.global.wnd && synckolab.global.wnd.gPauseSync)
@@ -992,8 +992,9 @@ synckolab.main.parseMessageRunner = function()
// fix the message for line truncs (last char in line is =)
// content might be a preparsed json
if(!synckolab.main.currentMessage.fileContent.synckolab) {
- synckolab.main.currentMessage.fileContent = synckolab.main.currentMessage.fileContent.content.replace(/\=\n(\S)/g, "$1");
+ synckolab.main.currentMessage.fileContent.content = synckolab.main.currentMessage.fileContent.content.replace(/\=\n(\S)/g, "$1");
}
+
skcontent = synckolab.main.gSync.parseMessage(synckolab.main.currentMessage.fileContent, synckolab.main.updateMessagesContent, (synckolab.main.gLaterMessages.pointer === 0));
}
diff --git a/src/chrome/content/synckolab/tools.js b/src/chrome/content/synckolab/tools.js
index 512a6fd..f219ddf 100644
--- a/src/chrome/content/synckolab/tools.js
+++ b/src/chrome/content/synckolab/tools.js
@@ -222,8 +222,30 @@ equalsObject: function(a, b, skipFields)
if(skipFields && skipFields[p]) {
break;
}
+
+ // both are "false"
+ if(!a[p] && !b[p]) {
+ break;
+ }
+
+ if((a === true || a === false) && a !== b) {
+ synckolab.tools.logMessage("not equals (bool): " + p + " a: " + a[p] + " b: " + b[p], synckolab.global.LOG_INFO);
+ return false;
+ }
+
+ if(("" + a[p]).length !== ("" +b[p]).length) {
+ synckolab.tools.logMessage("not equals (strlen): " + p + " a: " + a[p] + (""+a[p]).length + " b: " + b[p] + (""+b[p]).length, synckolab.global.LOG_INFO);
+ return false;
+ }
+ if(!isNaN(a[p]) && !isNaN(b[p])) {
+ if(Number(a[p]) !== Number(b[p])) {
+ synckolab.tools.logMessage("not equals (number): " + p + " a: " + a[p] + " b: " + b[p], synckolab.global.LOG_INFO);
+ return false;
+ }
+ }
+
if (a[p] !== b[p] && Number(a[p]) !== Number(b[p])) {
- synckolab.tools.logMessage("not equals: : " + p + " a: " + a[p] + " b: " + b[p], synckolab.global.LOG_INFO);
+ synckolab.tools.logMessage("not equals: " + p + " a: " + a[p] + " b: " + b[p], synckolab.global.LOG_INFO);
return false;
}
}
@@ -250,12 +272,12 @@ equalsObject: function(a, b, skipFields)
},
/**
- * Removes a possible mail header and extracts only the "real" content.
+ * parses the mail and extracts the content.
* This also trims the message and removes some common problems (like -- at the end)
* @param skcontent the mail content
- * @returns Object with content and image ({ content: STRING, image: STRING });
+ * @returns Object with content and image ({ content: STRING, parts: [{id, contentTypem name, data }]);
*/
-stripMailHeader: function (skcontent) {
+parseMail: function (skcontent) {
if (skcontent === null) {
return null;
}
@@ -310,233 +332,198 @@ stripMailHeader: function (skcontent) {
this.logMessage("Stripping header from multipart message", synckolab.global.LOG_DEBUG);
// we got a multipart message - strip it apart
+ var messageContent = {
+ content: null,
+ parts: []
+ };
// XXXboundary="XXX" or XXXboundary=XXX\n
var boundary = null;
boundary = skcontent.substring(skcontent.search(/boundary=/)+9);
-
- // lets trim boundary (in case we have whitespace after the =
- boundary = synckolab.tools.text.trim(boundary);
-
- // if the boundary string starts with "... we look for an end
- if (boundary.charAt(0) === '"')
- {
- // get rid of the first "
- boundary = boundary.substring(1);
- // find the second "
- boundary = boundary.substring(0, boundary.indexOf('"'));
- }
- else
- {
- // cut away at \n or \r or space.. whichever comes first
- var cutWS = boundary.indexOf(' ');
- var ws = boundary.indexOf('\n');
- if (ws !== -1 && ws < cutWS) {
- cutWS = ws;
- }
- ws = boundary.indexOf('\t');
- if (ws !== -1 && ws < cutWS) {
- cutWS = ws;
- }
- ws = boundary.indexOf('\r');
- if (ws !== -1 && ws < cutWS) {
- cutWS = ws;
- }
- boundary = boundary.substring(0, cutWS);
- }
- // try to get the start of the card part
-
- // remove the tmp image if it exists (only in xul environment)...
- if (typeof Components !== "undefined") {
- var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("TmpD", Components.interfaces.nsIFile);
- file.append("syncKolab.img");
- if (file.exists()) {
- file.remove(true);
- }
- }
-
- // check if we have an image attachment
- var imgC = skcontent;
- var imgIdx = imgC.search(/Content-Type:[ \t\r\n]+image/i);
- var imgName = "photo.png";
+ // strip away the " or any whitespace
+ boundary = boundary.substring(boundary, boundary.indexOf('\n')).replace(/['" \n\r\t]/g, "");
+ // split the message into boundaries
+ var msgParts = skcontent.split("\n--" + boundary);
- // TODO figure out the picture name
- // only works in xul environment
- if (imgIdx !== -1)
- {
- // get rid of the last part until the boundary
- imgC = imgC.substring(imgIdx);
- var idx = imgC.indexOf(boundary);
- if (idx !== -1) {
- imgC = imgC.substring(0, idx);
- }
- // get rid of windows encoding
- imgC = imgC.replace(/\r/g, "");
-
- // get the image data (make sure to remove \n and whitespace
- idx = imgC.indexOf('\n\n');
- imgC = imgC.substring(idx);
- imgC = imgC.replace(/[\r\n \t\-]+/g, "");
- } else {
- // no image attached
- imgC = null;
- }
+ this.logMessage("Multipart message with " + msgParts.length + " parts", synckolab.global.LOG_DEBUG);
- // check kolab XML first
- var contentIdx = -1;
- var endcontentIdx;
- var contTypeIdx = skcontent.search(/Content-Type:[ \t\r\n]+application\/x-vnd.kolab./i);
- if (contTypeIdx !== -1)
- {
- skcontent = skcontent.substring(contTypeIdx); // cut everything before this part
- // there might be a second boundary... remove that as well
- endcontentIdx = skcontent.indexOf(boundary);
- if (endcontentIdx !== -1) {
- skcontent = skcontent.substring(0, endcontentIdx);
- }
- if ((new RegExp("--$")).test(skcontent)) {
- skcontent = skcontent.substring(0, skcontent.length - 2);
- }
+ var msgI = 0;
+ // skip the first part: its just the header
+ for(msgI = 1; msgI < msgParts.length; msgI++){
+ // split the msg into lines for easier parsing
+ var msgContent = msgParts[msgI].split("\n");
+ var gotHeader = false;
+ var part = {};
- contentIdx = skcontent.indexOf("<?xml");
- }
- else
- {
- // check for vcard | ical
- contTypeIdx = skcontent.search(/Content-Type:[ \t\r\n]+text\/x-vcard/i);
- if (contTypeIdx === -1) {
- contTypeIdx = skcontent.search(/Content-Type:[ \t\r\n]+text\/x-ical/i);
- }
- if (contTypeIdx === -1) {
- contTypeIdx = skcontent.search(/Content-Type:[ \t\r\n]+text\/calendar/i);
- }
+ for(var li = 0; li < msgContent.length; li++){
+ var line = msgContent[li];
+ // skip text without id...
+ if(gotHeader && part.contentType === "text" && !part.id) {
+ part = null;
+ break;
+ }
- if (contTypeIdx !== -1)
- {
- skcontent = skcontent.substring(contTypeIdx); // cut everything before this part
- // handle multi-line
- skcontent = skcontent.replace(/[\n\r]+ /, "");
- // there might be a second boundary... remove that as well
- endcontentIdx = skcontent.indexOf(boundary);
- if (endcontentIdx !== -1) {
- skcontent = skcontent.substring(0, endcontentIdx);
- }
- if ((new RegExp("--$")).test(skcontent)) {
- skcontent = skcontent.substring(0, skcontent.length - 2);
+ if(!gotHeader) {
+ // empty line - done with the header
+ if(li > 2 && line.replace(/[\r\n]/g, "").length === 0) {
+ part.content = "";
+ gotHeader = true;
+ continue;
+ }
+ // look ahead -
+ if(msgContent.length > li+1 && msgContent[li+1].charAt(0) === ' ') {
+ line += msgContent[li+1];
+ // skip the next line
+ li++;
+ }
+
+ if(line.indexOf(":") === -1) {
+ continue;
+ }
+
+ // check the header
+ var val;
+ switch(line.substring(0, line.indexOf(':'))) {
+ case "Content-Type":
+ val = line.substring(line.indexOf(':') + 1).split(";");
+ val[0] = val[0].toLowerCase();
+ if(val[0].indexOf('text/plain') !== -1) {
+ part.contentType = "text";
+ } else {
+ part.contentType = val[0];
+ }
+
+ if(val.length > 1) {
+ if(val[1].indexOf("name") !== -1 ) {
+ part.name = val[1].substring(val[1].indexOf("name")+4);
+ // get rid of special chars
+ part.name = part.name.replace(/[ "';=\n\r]/g, "");
+ }
+ }
+ part.contentType = part.contentType.toLowerCase();
+ break;
+ case "Content-ID":
+ if(line.indexOf('<') !== -1) {
+ part.id = line.substring(line.indexOf('<') + 1, line.indexOf('>'));
+ } else {
+ part.id = line.substring(line.indexOf(':' + 1));
+ part.id = part.id.replace(/[ "';=]/g, "");
+ }
+ break;
+ case "Content-Transfer-Encoding":
+ part.encoding = line.substring(line.indexOf(':' + 1));
+ part.encoding = part.encoding.replace(/[ "';=]/g, "");
+ break;
+ }
+ } else {
+ // jsut add the content up
+ part.content += line + "\n";
}
-
- contentIdx = skcontent.indexOf("BEGIN:");
- }
- }
-
-
- // if we did not find a decoded card, it might be base64
- if (contentIdx === -1)
- {
- isQP = skcontent.search(/Content-Transfer-Encoding:[ \t\r\n]+quoted-printable/i);
- var isBase64 = skcontent.search(/Content-Transfer-Encoding:[ \t\r\n]+base64/i);
-
- this.logMessage("contentIdx === -1: looks like its encoded: QP=" + isQP + " B64=" + isBase64, synckolab.global.LOG_DEBUG);
+
+ } // # end go through lines
- if (isBase64 !== -1)
- {
- this.logMessage("Base64 Decoding message. (Boundary: "+boundary+")", synckolab.global.LOG_DEBUG);
- // get rid of the header
- skcontent = skcontent.substring(isBase64, skcontent.length);
- startPos = skcontent.indexOf("\r\n\r\n");
- var startPos2 = skcontent.indexOf("\n\n");
- if (startPos2 !== -1 && (startPos2 < startPos || startPos === -1)) {
- startPos = startPos2;
- }
-
- var endPos = skcontent.indexOf("--"); // we could check for "--"+boundary but its not necessary since base64 doesnt allow it anyways
- // we probably removed the -- already, but to make sure
- if (endPos === -1) {
- endPos = skcontent.length;
+ // only check the part if it's valid
+ if(part && part.content && (part.encoding || part.contentType || part.id)) {
+ // check encoding
+ isQP = part.encoding.indexOf("quoted-printable") !== -1;
+ var isBase64 = part.encoding.indexOf("base64") !== -1;
+
+ if(!part.id && part.contentType.indexOf("image") !== -1) {
+ part.id = part.name;
}
-
- skcontent = skcontent.substring(startPos, endPos).replace(/[\r\n \t]+/g, "");
-
- this.logMessage("Base64 message: " + skcontent, synckolab.global.LOG_DEBUG);
-
- // for base64 we use a two storied approach
- // first: use atob
- // if that gives us an outofmemoryexception use the slow but working javascript
- // engine
- try {
- skcontent = atob(skcontent);
- } catch (e) {
- // out of memory error... this can be handled :)
- if (e.result === Components.results.NS_ERROR_OUT_OF_MEMORY)
- {
- skcontent = synckolab.tools.text.base64.decode(skcontent);
- this.logMessage("decoded base64: " + skcontent, synckolab.global.LOG_DEBUG);
-
+
+ // lets check the "main" part - should not have an id, type include xml
+ if(!part.id) {
+ var valid = false;
+ if(part.contentType.indexOf("text/x-vcard") !== -1) {
+ valid = true;
+ }
+ if(part.contentType.indexOf("text/x-ical") !== -1) {
+ valid = true;
+ }
+ if(part.contentType.indexOf("text/calendar") !== -1) {
+ valid = true;
+ }
+ if(part.contentType.indexOf("x-vnd.kolab") !== -1) {
+ valid = true;
+ }
+ if(part.contentType.indexOf("application") !== -1 && part.contentType.indexOf("xml") !== -1) {
+ valid = true;
}
- else
+
+ // skip if not valid
+ if(!valid) {
+ this.logMessage("INVALID PART: " + part.contentType, synckolab.global.LOG_INFO);
+ continue;
+ }
+
+ if (isBase64)
{
- this.logMessage("Error decoding base64 (" + e + "): " + skcontent, synckolab.global.LOG_ERROR);
- return null;
+ // clean up the base64
+ part.content = part.content.replace(/[\r\n \t]+/g, "");
+
+ this.logMessage("Base64 message:\n" + part.content , synckolab.global.LOG_DEBUG);
+
+ // for base64 we use a two storied approach
+ // first: use atob
+ // if that gives us an outofmemoryexception use the slow but working javascript
+ // engine
+ try {
+ part.content = atob(part.content);
+ } catch (e) {
+ // out of memory error... this can be handled :)
+ if (typeof Components !== "undefined" && e.result === Components.results.NS_ERROR_OUT_OF_MEMORY)
+ {
+ part.content = synckolab.tools.text.base64.decode(part.content);
+ this.logMessage("decoded base64", synckolab.global.LOG_DEBUG);
+ }
+ else
+ {
+ // skip this part
+ this.logMessage("Error decoding base64 (" + e.message + "):\n" + part.content, synckolab.global.LOG_ERROR);
+ continue;
+ }
+ }
+ // decode utf8 only for testing! (no Components there) - tbird already does the decoding correctly
+ if(typeof Components === "undefined" && part.content) {
+ part.content = synckolab.tools.text.utf8.decode(part.content);
+ }
}
- }
- // decode utf8
- if(skcontent) {
- skcontent = synckolab.tools.text.utf8.decode(skcontent);
- }
- }
-
-
- if (isQP !== -1)
- {
- skcontent = skcontent.substring(isQP, skcontent.length);
- skcontent = synckolab.tools.text.quoted.decode(skcontent);
- }
-
-
+ // decode the content (quoted-printable)
+ if (isQP)
+ {
+ part.content = synckolab.tools.text.quoted.decode(part.content);
+ }
- if (isQP === -1 && isBase64 === -1)
- {
- // so this message has no <xml>something</xml> area
- this.logMessage("Error parsing this message: no xml segment found\n" + skcontent, synckolab.global.LOG_ERROR);
- return null;
- }
-
- // with the decoded content - check for the real start
- contentIdx = skcontent.indexOf("<?xml");
- if (contentIdx === -1) {
- contentIdx = skcontent.indexOf("BEGIN:");
- }
+ // content might still be quoted printable... doublecheck
+ // check if we have to decode quoted printable
+ if (part.content.indexOf(" version=3D") !== -1 || part.content.indexOf("TZID=3D")) // we know from the version (or in case of citadel from the tzid)
+ {
+ this.logMessage("Message is quoted", synckolab.global.LOG_DEBUG);
+ part.content = synckolab.tools.text.quoted.decode(part.content);
+ }
+
+ // now set the main content
+ messageContent.content = part.content;
+ } else {
+ this.logMessage("Adding part: " + part.contentType + " name: "+ part.name, synckolab.global.LOG_DEBUG);
-
- if (contentIdx !== -1) {
- skcontent = skcontent.substring(contentIdx);
- }
- }
- else
- {
- skcontent = skcontent.substring(contentIdx);
- // until the boundary = end of xml|vcard/ical
- if (skcontent.indexOf(boundary) !== -1) {
- skcontent = skcontent.substring(0, skcontent.indexOf("--"+boundary));
+ // add the part
+ messageContent.parts.push(part);
+ }
}
}
- // content might still be quoted printable... doublecheck
- // check if we have to decode quoted printable
- if (skcontent.indexOf(" version=3D") !== -1 || skcontent.indexOf("TZID=3D")) // we know from the version (or in case of citadel from the tzid)
- {
- this.logMessage("Message is quoted", synckolab.global.LOG_DEBUG);
- skcontent = synckolab.tools.text.quoted.decode(skcontent);
+ // only continue if we found a "main" content part
+ if(messageContent.content !== null) {
+ return messageContent;
}
-
- return {
- content: synckolab.tools.text.trim(skcontent),
- imageName: imgName,
- image: imgC
- };
+
+ this.logMessage("Empty message.. ignoring", synckolab.global.LOG_INFO);
+ return null;
},
/**
@@ -547,6 +534,18 @@ getProfileFolder: function () {
},
/**
+ * get the profile folder object
+ */
+getFile: function (path) {
+ var localFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
+ // strip away the path
+ if(path.indexOf("file://") !== -1) {
+ path = path.substring(7);
+ }
+ localFile.initWithPath(path);
+ return localFile;
+},
+/**
* Create a message to be stored on the Kolab server
*
* @param cid the id of the card/event
@@ -555,9 +554,9 @@ getProfileFolder: function () {
* @param part true if this is a multipart message
* @param content the content for the message
* @param hr human Readable Part (optional)
- * @param image optional image attachment (must be {"name": nameOfImage, "data": base64data} )
+ * @param attachments optional image attachment(s) (must be {"id":optionalId, "name": nameOfImage, "data": base64data} )
*/
-generateMail: function (cid, mail, adsubject, mime, part, skcontent, hr, image){
+generateMail: function (cid, mail, adsubject, mime, part, skcontent, hr, attachments){
// sometime we just do not want a new message :)
if (skcontent === null) {
return null;
@@ -626,19 +625,10 @@ generateMail: function (cid, mail, adsubject, mime, part, skcontent, hr, image){
msg += 'Content-Type: '+mime+';\n name="kolab.xml"\n';
msg += 'Content-Transfer-Encoding: base64\n';
msg += 'Content-Disposition: attachment;\n filename="kolab.xml"\n\n';
+
// keep lines at 80 chars
var acontent = btoa(skcontent);
- var n = 0;
- for (n= 0; n < acontent.length; )
- {
- if (n + 80 < acontent.length) {
- msg += acontent.slice(n, n+80);
- } else {
- msg += acontent.slice(n);
- }
- msg += "=\n";
- n+=80;
- }
+ msg += synckolab.tools.text.splitInto(acontent, 72);
}
else {
// add the content
@@ -646,25 +636,21 @@ generateMail: function (cid, mail, adsubject, mime, part, skcontent, hr, image){
}
// if we have an image try to read it and create a new part (ONLY for xml)
- if (part && image && image.data) {
- try {
- if (image.data !== null) {
- // now we got the image into fileContent - lets attach
- msg += '\n--Boundary-00='+bound+'\n';
- // based on the name - get the MIME
- var ptype = synckolab.tools.file.getMimeType(image.name.substring(image.name.lastIndexOf(".")+1));
- msg += 'Content-Type: '+ptype+';\n name="'+image.name+'"\n';
- msg += 'Content-Transfer-Encoding: base64\n';
- msg += 'Content-Disposition: attachment;\n filename="'+image.name+'"\n\n';
- msg += synckolab.tools.text.splitInto(image.data, 72);
+ if (part && attachments && attachments.length > 0) {
+ for(var i = 0; i < attachments.length; i++) {
+ var cur = attachments[i];
+ // now we got the image into fileContent - lets attach
+ msg += '\n--Boundary-00='+bound+'\n';
+ // based on the name - get the MIME
+ var ptype = synckolab.tools.file.getMimeType(cur.name.substring(cur.name.lastIndexOf(".")+1));
+ if(cur.id) {
+ msg += "Content-ID: <"+cur.id+">\n";
}
+ msg += 'Content-Type: '+ptype+';\n name="'+cur.name+'"\n';
+ msg += 'Content-Transfer-Encoding: base64\n';
+ msg += 'Content-Disposition: attachment;\n filename="'+cur.name+'"\n\n';
+ msg += synckolab.tools.text.splitInto(cur.data, 72);
}
- catch (ex)
- {
- this.logMessage("Unable to read image: "+image+"\n" + ex, synckolab.global.LOG_WARNING);
- return null;
- }
-
}
if (part) {
@@ -694,20 +680,7 @@ readFileIntoBase64: function (file) {
while ((csize = fileIO.available()) !== 0)
{
var data = fileIO.readBytes(csize);
-
- // keep lines at 80 chars
- var acontent = btoa(data);
- var n = 0;
- for (n= 0; n < acontent.length; )
- {
- if (n + 80 < acontent.length) {
- fileContent += acontent.slice(n, n+80);
- } else {
- fileContent += acontent.slice(n);
- }
- fileContent += "=\n";
- n+=80;
- }
+ fileContent += btoa(data);
}
fileIO.close();
istream.close();
@@ -900,7 +873,7 @@ synckolab.tools.file = {
case "jpeg":
case "jpg":
case "image/jpg":
- return "png";
+ return "jpg";
case "gif":
case "image/gif":
return "gif";
@@ -1013,7 +986,7 @@ synckolab.tools.writeSyncDBFile = function (file, data, direct)
if(direct) {
skcontent = data;
} else {
- skcontent = JSON.stringify(data);
+ skcontent = JSON.stringify(data, null, " ");
}
file.create(file.NORMAL_FILE_TYPE, parseInt("0666", 8));
@@ -1021,7 +994,7 @@ synckolab.tools.writeSyncDBFile = function (file, data, direct)
stream.init(file, 2, 0x200, false); // open as "write only"
var cstream = Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);
- cstream.init(stream, "UTF-8", 0, 0);
+ cstream.init(stream, "UTF-8", 0, 0x000);
cstream.writeString(skcontent);
cstream.close();
@@ -1056,7 +1029,7 @@ synckolab.tools.readSyncDBFile = function (file, direct)
istream.init(file, 0x01, 4, null);
var cstream = Components.classes["@mozilla.org/intl/converter-input-stream;1"].createInstance(Components.interfaces.nsIConverterInputStream);
- cstream.init(istream, "UTF-8", 0, 0);
+ cstream.init(istream, "UTF-8", 1024, 0);
var fileContent = "";
var csize = 0;
@@ -1440,7 +1413,15 @@ synckolab.Node.prototype.getFirstData = function () {
if (!text.firstChild) {
return null;
}
- return synckolab.tools.text.decode4XML(text.firstChild.data);
+ // uri can be quite large so handle ALL childs
+ var combinedNode = "";
+ var cur = text.firstChild;
+ while(cur) {
+ combinedNode = cur.data;
+ cur = cur.nextSibling;
+ }
+
+ return synckolab.tools.text.decode4XML(combinedNode);
}
// cur.nodeType === Node.TEXT_NODE
diff --git a/src/chrome/content/synckolab/tools/text.js b/src/chrome/content/synckolab/tools/text.js
index 17cd000..ecf35a8 100644
--- a/src/chrome/content/synckolab/tools/text.js
+++ b/src/chrome/content/synckolab/tools/text.js
@@ -540,10 +540,10 @@ synckolab.tools.text = {
{
if (n + width < text.length) {
out += text.slice(n, n+width);
+ out += "\n";
} else {
out += text.slice(n);
}
- out += "\n";
n+=width;
}
return out;
diff --git a/test/lib/testOverride.js b/test/lib/testOverride.js
index dbf7366..0538f5f 100644
--- a/test/lib/testOverride.js
+++ b/test/lib/testOverride.js
@@ -36,7 +36,7 @@ synckolab.tools.parseXml = function(content) {
}
synckolab.tools.logMessage = function(msg, level) {
- if (!level) {
+ if (typeof (level) === "undefined") {
print("NO LEVEL GIVEN: " + synckolab.tools.trace());
}
var infolvl = synckolab.config.DEBUG_SYNCKOLAB_LEVEL%4;
diff --git a/test/suite.js b/test/suite.js
index 0e13548..322460b 100644
--- a/test/suite.js
+++ b/test/suite.js
@@ -44,7 +44,7 @@ load("test/synckolab/parser/kolab2/calendarTest.js");
load("test/synckolab/parser/kolab2/contactTest.js");
load("test/synckolab/parser/kolab3/contactTest.js");
//load("test/synckolab/parser/kolab3/calendarTest.js");
-
+//*/
print("========================")
print("Tests Run: " + (testRuns.fail+testRuns.pass));
print(" Passed Tests: " + testRuns.pass);
diff --git a/test/synckolab/parser/kolab2/contactTest.js b/test/synckolab/parser/kolab2/contactTest.js
index c81ca20..1a197ed 100644
--- a/test/synckolab/parser/kolab2/contactTest.js
+++ b/test/synckolab/parser/kolab2/contactTest.js
@@ -21,12 +21,13 @@ test("skolab2 ynckolab.addressbookTools.parseMessageContent", function(){
print("INFO: KOLAB 2 TESTING CONTACT: " + src +"\n");
content = readFile("test/synckolab/parser/kolab2/raw/"+src+".eml");
- content = synckolab.tools.stripMailHeader(content);
+ content = synckolab.tools.parseMail(content);
+
entry = synckolab.addressbookTools.parseMessageContent(content);
+
content = readFile("test/synckolab/parser/kolab2/json/"+src+".json");
jsonEntry = JSON.parse(content);
equal(synckolab.tools.equalsObject(entry, jsonEntry, {UUID:true}), true, src + "\n" + JSON.stringify(entry, null, " "));
-
// json -> kolab 2 xml
/*
if(entry.type === "maillist") {
@@ -47,18 +48,22 @@ test("skolab2 ynckolab.addressbookTools.parseMessageContent", function(){
});
-
/*
-var testFiles = ["contactMinimalTest", "contactFullTest", "list.test", "list.test2"];
+
+var testFiles = ["contactMinimalTest"]; //, "contactMinimalTest", "contactFullTest", "list.test", "list.test2"];
var content, entry, jsonEntry;
for(var i = 0; i < testFiles.length; i++) {
var src = testFiles[i];
- content = readFile("test/synckolab/parser/kolab2/raw/"+src+".xml");
+ content = readFile("test/synckolab/parser/kolab2/raw/"+src+".eml");
+ content = content.replace (/\#\$\#/g, "");
+ print("CONTENT: " + content + "\n\n");
+ content = synckolab.tools.parseMail(content);
+ print(" PRSED CONTENT: " + content)
entry = synckolab.addressbookTools.parseMessageContent(content);
+ print(JSON.stringify(entry, null, " "));
content = readFile("test/synckolab/parser/kolab2/json/"+src+".json");
jsonEntry = JSON.parse(content);
}
-
-*/ \ No newline at end of file
+//*/
diff --git a/test/synckolab/parser/kolab2/json/contactFullTest.json b/test/synckolab/parser/kolab2/json/contactFullTest.json
index f900772..f71c692 100644
--- a/test/synckolab/parser/kolab2/json/contactFullTest.json
+++ b/test/synckolab/parser/kolab2/json/contactFullTest.json
@@ -1 +1 @@
-{"synckolab":"2.0.2","type":"contact","isMailList":false,"ts":1341399615448,"UUID":"pas-id-1D84CEA337CD1878","Notes":"multiline\nnote with öäü!","FirstName":"testöä","LastName":"lastnameöäü","DisplayName":"testöä lastname","Company":"w-org","WebPage1":"w-web","WebPage2":"p-web","Department":"w-department","JobTitle":"w-title","NickName":"nick","BirthYear":"1980","BirthMonth":"01","BirthDay":"22","HomePhone":"01-home","WorkPhone":"01-work","FaxNumber":"01-fax","CellularNumber":"01-mobile","PagerNumber":"01-page","PrimaryEmail":"email@mail.com","SecondEmail":"additional@mail.com","HomeAddress":"priv-addr1","HomeAddress2":"priv-addr2","HomeCity":"priv-city","HomeState":"priv-state","HomeZipCode":"p123","HomeCountry":"p-country","WorkAddress":"w-addr1","WorkAddress2":"w-addr2","WorkCity":"w-city","WorkState":"w-state","WorkZipCode":"w123","WorkCountry":"w-country","Custom1":"cust1","Custom2":"cust2","Custom3":"cust3","AllowRemoteContent":true,"sha1":"6045abc16ac427b939636fd110fe44d5f55b9d0f"} \ No newline at end of file
+{"synckolab":"2.0.2","type":"contact","isMailList":false,"ts":1341399615448,"UUID":"pas-id-1D84CEA337CD1878","Notes":"multiline\nnote with öäü!","FirstName":"testöä","LastName":"lastnameöäü","DisplayName":"testöä lastname","Company":"w-org","WebPage1":"w-web","WebPage2":"p-web","Department":"w-department","JobTitle":"w-title","NickName":"nick","BirthYear":1980,"BirthMonth":1,"BirthDay":22,"HomePhone":"01-home","WorkPhone":"01-work","FaxNumber":"01-fax","CellularNumber":"01-mobile","PagerNumber":"01-page","PrimaryEmail":"email@mail.com","SecondEmail":"additional@mail.com","HomeAddress":"priv-addr1","HomeAddress2":"priv-addr2","HomeCity":"priv-city","HomeState":"priv-state","HomeZipCode":"p123","HomeCountry":"p-country","WorkAddress":"w-addr1","WorkAddress2":"w-addr2","WorkCity":"w-city","WorkState":"w-state","WorkZipCode":"w123","WorkCountry":"w-country","Custom1":"cust1","Custom2":"cust2","Custom3":"cust3","AllowRemoteContent":true,"sha1":"6045abc16ac427b939636fd110fe44d5f55b9d0f"} \ No newline at end of file
diff --git a/test/synckolab/parser/kolab2/json/test-image.json b/test/synckolab/parser/kolab2/json/test-image.json
index 3ce35ea..3758b7a 100644
--- a/test/synckolab/parser/kolab2/json/test-image.json
+++ b/test/synckolab/parser/kolab2/json/test-image.json
@@ -2,10 +2,7 @@
"synckolab": "3.0.0",
"type": "contact",
"isMailList": false,
- "ts": 1351254809554,
- "PhotoName": "8028141781098217.jpg",
- "PhotoType": "inline",
- "PhotoData": "/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wgARCAAYABwDAREAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAABwQFBgj/xAAZAQEAAwEBAAAAAAAAAAAAAAAEAgMFAAH/2gAMAwEAAhADEAAAAegj2mZD2N61phzUd1WPFn26iLoyIwsycPJ3SUWl/8QAHBAAAwEAAgMAAAAAAAAAAAAAAwQFAgABBhIT/9oACAEBAAEFArVcM0LNvDu5OCtZX32QPls0FzM0q6wCPFC1OL9k67tBZ0lv20taLyKxRyh//8QAIhEAAgICAQMFAAAAAAAAAAAAAQIDEQAEEgUTIRAxMkJh/9oACAEDAQE/AYxbe14epxQOYxGGrzibse1DySNRf56KsnG0zXlo9ub5DNZe8xP1xhRrI5Qi8awyR3fHBMoHhcamN5//xAAiEQABBAIBBAMAAAAAAAAAAAABAAIDEQQSExAUMVEiIzL/2gAIAQIBAT8BmeGt80jOAdbJoKJ3I3cE9JeNxpyxsho+uX9BOyDfw8Jp2FqWAyO2tDGd7XbH2m21oC//xAAkEAABAwMEAgMBAAAAAAAAAAABAgMRAAQSBRMhMUFRMnHBkf/aAAgBAQAGPwKHHdkqOIVBNSxfXZAQCVNLxH30aRdN6hfKwV8HVgpJ9dc0lSuCe6LKrpy2cYVI20zkcRTSXYQCNkQykwB4Pmtq2cGwB4bA5/lNq88gz7Bg0+telPLClSC0ZHQH5Uq0h/L3Imoa0a5P0RQy0/CVKUAtyDBUT+1//8QAHBABAAICAwEAAAAAAAAAAAAAAQARITFBUWGh/9oACAEBAAE/ITiyxMveAiXCql1eC2ku5sXwEG1hSD8CwNXKnkqw1BfBn7G6t32CW1k6iVg9GfcVpz8g3K5MBmaPRglgDaOZUK4zEavSDp37GBOKyCAsj//aAAwDAQACAAMAAAAQFY3ECh//xAAfEQEAAgICAgMAAAAAAAAAAAABABEhQTFRcYEQYZH/2gAIAQMBAT8QqPwjnQWsWj0nEEfUCE8Z+LDFeLlpxTbWjt33KiStBXe/XEs1qZ8Mclk+JUmCJrauf//EAB4RAAICAQUBAAAAAAAAAAAAAAERACFhEEFRcfGx/9oACAECAQE/EDN98N3DCvsGBZnzQ2OwKBz5LYoLKpDO/MegwVC73gwjvKuCpwcw4IyGhP/EAB4QAQADAAIDAQEAAAAAAAAAAAEAESExQWFxgVGR/9oACAEBAAE/EGNXHVBgVuu/c7gmGU0LTUALCC8n4N0psqWVx0iTwqSkxrxkU3AqhEQoAtKxfkE8jVUUrStOE9QO/bFYKKcaSu13AJrADgOKyV1Uov20MRwXp65qXb4Jgii6vhT7L6zgMP4RVbGaEqsTHyf/2Q",
+ "ts": 1351292484677,
"UUID": "sk-vc-231B43ABE83388D3",
"Notes": "Introduced by a software engineer.",
"FirstName": "First",
@@ -16,6 +13,9 @@
"NickName": "Name, First",
"PrimaryEmail": "name@yahoo.com",
"PreferMailFormat": 2,
+ "PhotoName": "8028140781098217.jpg",
+ "PhotoType": "inline",
+ "PhotoData": "/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDAAMCAgMCAgMDAwME\r\nAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBD\r\nAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU\r\nFBQUFBQUFBT/wgARCAAYABwDAREAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAABwQFBgj/xAAZ\r\nAQEAAwEBAAAAAAAAAAAAAAAEAgMFAAH/2gAMAwEAAhADEAAAAegj2mZD2N61phzUd1WPFn26iLoy\r\nIwsycPJ3SUWl/8QAHBAAAwEAAgMAAAAAAAAAAAAAAwQFAgABBhIT/9oACAEBAAEFArVcM0LNvDu5\r\nOCtZX32QPls0FzM0q6wCPFC1OL9k67tBZ0lv20taLyKxRyh//8QAIhEAAgICAQMFAAAAAAAAAAAA\r\nAQIDEQAEEgUTIRAxMkJh/9oACAEDAQE/AYxbe14epxQOYxGGrzibse1DySNRf56KsnG0zXlo9ub5\r\nDNZe8xP1xhRrI5Qi8awyR3fHBMoHhcamN5//xAAiEQABBAIBBAMAAAAAAAAAAAABAAIDEQQSExAU\r\nMVEiIzL/2gAIAQIBAT8BmeGt80jOAdbJoKJ3I3cE9JeNxpyxsho+uX9BOyDfw8Jp2FqWAyO2tDGd\r\n7XbH2m21oC//xAAkEAABAwMEAgMBAAAAAAAAAAABAgMRAAQSBRMhMUFRMnHBkf/aAAgBAQAGPwKH\r\nHdkqOIVBNSxfXZAQCVNLxH30aRdN6hfKwV8HVgpJ9dc0lSuCe6LKrpy2cYVI20zkcRTSXYQCNkQy\r\nkwB4Pmtq2cGwB4bA5/lNq88gz7Bg0+telPLClSC0ZHQH5Uq0h/L3Imoa0a5P0RQy0/CVKUAtyDBU\r\nT+1//8QAHBABAAICAwEAAAAAAAAAAAAAAQARITFBUWGh/9oACAEBAAE/ITiyxMveAiXCql1eC2ku\r\n5sXwEG1hSD8CwNXKnkqw1BfBn7G6t32CW1k6iVg9GfcVpz8g3K5MBmaPRglgDaOZUK4zEavSDp37\r\nGBOKyCAsj//aAAwDAQACAAMAAAAQFY3ECh//xAAfEQEAAgICAgMAAAAAAAAAAAABABEhQTFRcYEQ\r\nYZH/2gAIAQMBAT8QqPwjnQWsWj0nEEfUCE8Z+LDFeLlpxTbWjt33KiStBXe/XEs1qZ8Mclk+JUmC\r\nJrauf//EAB4RAAICAQUBAAAAAAAAAAAAAAERACFhEEFRcfGx/9oACAECAQE/EDN98N3DCvsGBZnz\r\nQ2OwKBz5LYoLKpDO/MegwVC73gwjvKuCpwcw4IyGhP/EAB4QAQADAAIDAQEAAAAAAAAAAAEAESEx\r\nQWFxgVGR/9oACAEBAAE/EGNXHVBgVuu/c7gmGU0LTUALCC8n4N0psqWVx0iTwqSkxrxkU3AqhEQo\r\nAtKxfkE8jVUUrStOE9QO/bFYKKcaSu13AJrADgOKyV1Uov20MRwXp65qXb4Jgii6vhT7L6zgMP4R\r\nVbGaEqsTHyf/2Q==\r\n\r\n",
"AllowRemoteContent": true,
"sha1": "c4522c8b1a011a75fb702d9c96a9c4929582bfa4"
} \ No newline at end of file
diff --git a/test/synckolab/parser/kolab2/raw/contactFullTest.eml b/test/synckolab/parser/kolab2/raw/contactFullTest.eml
index bbfabdf..8f58cc0 100644
--- a/test/synckolab/parser/kolab2/raw/contactFullTest.eml
+++ b/test/synckolab/parser/kolab2/raw/contactFullTest.eml
@@ -17,7 +17,7 @@ To view this object you will need an email client that can understand the Kolab
For a list of such email clients please visit
http://www.kolab.org/kolab2-clients.html
---Boundary-00=6988F02CCC809628
+--nextPart38186565.1WqI9LYOEs
Content-Type: application/x-vnd.kolab.contact;
name="kolab.xml"
Content-Transfer-Encoding: quoted-printable
@@ -95,4 +95,5 @@ note with öäü!</body>
<custom3>cust3</custom3>
<allow-remote-content>true</allow-remote-content>
</contact>
---Boundary-00=6988F02CCC809628-- \ No newline at end of file
+
+--nextPart38186565.1WqI9LYOEs-- \ No newline at end of file
diff --git a/test/synckolab/parser/kolab2/raw/contactMinimalTest.eml b/test/synckolab/parser/kolab2/raw/contactMinimalTest.eml
index 675157d..e8d14dd 100644
--- a/test/synckolab/parser/kolab2/raw/contactMinimalTest.eml
+++ b/test/synckolab/parser/kolab2/raw/contactMinimalTest.eml
@@ -17,7 +17,7 @@ To view this object you will need an email client that can understand the Kolab
For a list of such email clients please visit
http://www.kolab.org/kolab2-clients.html
---Boundary-00=6988F02CCC809628
+--nextPart38186565.1WqI9LYOEs
Content-Type: application/x-vnd.kolab.contact;
name="kolab.xml"
Content-Transfer-Encoding: quoted-printable
@@ -40,4 +40,5 @@ Content-Disposition: attachment;
</email>
<allow-remote-content>true</allow-remote-content>
</contact>
---Boundary-00=6988F02CCC809628-- \ No newline at end of file
+
+--nextPart38186565.1WqI9LYOEs--
diff --git a/test/synckolab/parser/kolab2/raw/testcontact.eml b/test/synckolab/parser/kolab2/raw/testcontact.eml
index c3343c7..c110cf5 100644
--- a/test/synckolab/parser/kolab2/raw/testcontact.eml
+++ b/test/synckolab/parser/kolab2/raw/testcontact.eml
@@ -21,7 +21,7 @@ http://www.kolab.org/kolab2-clients.html
--Boundary-00=173882C61DEE82C7
Content-Type: application/x-vnd.kolab.contact;
name="kolab.xml"
-Content-Transfer-Encoding: base64
+Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="kolab.xml"
diff --git a/test/synckolab/parser/kolab3/calendarTest.js b/test/synckolab/parser/kolab3/calendarTest.js
index e3c912b..a5f64be 100644
--- a/test/synckolab/parser/kolab3/calendarTest.js
+++ b/test/synckolab/parser/kolab3/calendarTest.js
@@ -21,7 +21,7 @@ test("kolab3 synckolab.addressbookTools.parseMessageContent", function(){
print("INFO: KOLAB 3 TESTING - EVENT: " + src +"\n")
content = readFile("test/synckolab/parser/kolab3/raw/"+src);
- content = synckolab.tools.stripMailHeader(content);
+ content = synckolab.tools.parseMail(content);
entry = synckolab.calendarTools.message2json(content, false);
content = readFile("test/synckolab/parser/kolab3/json/"+src+".json");
jsonEntry = JSON.parse(content);
@@ -42,7 +42,7 @@ test("kolab3 synckolab.addressbookTools.parseMessageContent", function(){
var src = testFiles[i];
content = readFile("test/synckolab/parser/kolab3/raw/"+src);
- content = synckolab.tools.stripMailHeader(content);
+ content = synckolab.tools.parseMail(content);
print(content);
print("==== STARTING PARSE")
entry = synckolab.calendarTools.message2json(content, false);
diff --git a/test/synckolab/parser/kolab3/contactTest.js b/test/synckolab/parser/kolab3/contactTest.js
index 3a66a08..b24dc69 100644
--- a/test/synckolab/parser/kolab3/contactTest.js
+++ b/test/synckolab/parser/kolab3/contactTest.js
@@ -12,7 +12,7 @@ load("test/lib/testOverride.js");
test("kolab3 synckolab.addressbookTools.parseMessageContent", function(){
equal(null, synckolab.addressbookTools.parseMessageContent(null), "parsing a null message");
- var testFiles = ["contact.simple.mime","contact.complex.mime","contact.test.mime","contact.test2.mime", "list.test1.eml"];
+ var testFiles = ["contact.test3.mime", "contact.simple.mime","contact.complex.mime","contact.test.mime","contact.test2.mime", "list.test1.eml"];
var content, entry, jsonEntry;
@@ -20,7 +20,7 @@ test("kolab3 synckolab.addressbookTools.parseMessageContent", function(){
var src = testFiles[i];
print("INFO: KOLAB 3 TESTING - CONTACT: " + src +"\n")
content = readFile("test/synckolab/parser/kolab3/raw/"+src);
- content = synckolab.tools.stripMailHeader(content);
+ content = synckolab.tools.parseMail(content);
entry = synckolab.addressbookTools.parseMessageContent(content);
content = readFile("test/synckolab/parser/kolab3/json/"+src+".json");
jsonEntry = JSON.parse(content);
@@ -32,6 +32,9 @@ test("kolab3 synckolab.addressbookTools.parseMessageContent", function(){
} else {
content = synckolab.addressbookTools.card2Kolab3(entry);
}
+ if(content.content) {
+ content = content.content;
+ }
xmlcontent = readFile("test/synckolab/parser/kolab3/xml/"+src + ".xml");
if (xmlcontent.replace(/[\n\r\t ]/g, "").length !== content.replace(/[\n\r\t ]/g, "").length) {
equal(xmlcontent.replace(/[\n\r\t ]/g, ""), content.replace(/[\n\r\t ]/g, ""), src);
@@ -47,7 +50,7 @@ for(var i = 0; i < testFiles.length; i++) {
var src = testFiles[i];
print("KOLAB 3 TESTING: " + src +"\n============")
content = readFile("test/synckolab/parser/kolab3/raw/"+src);
- content = synckolab.tools.stripMailHeader(content);
+ content = synckolab.tools.parseMail(content);
entry = synckolab.addressbookTools.parseMessageContent(content);
if(entry.isMailList) {
print(entry.toSource());
@@ -68,7 +71,7 @@ for(var i = 0; i < testFiles.length; i++) {
print("DIFF FOUND:"+ xmlcontent.replace(/[\n\r\t ]/g, "").length + " vs. "+ content.replace(/[\n\r\t ]/g, "").length +"\n" + diff);
}
}
-*/
+
/*
var testFiles = ["list.test1.eml"];
@@ -79,7 +82,7 @@ for(var i = 0; i < testFiles.length; i++) {
var src = testFiles[i];
content = readFile("test/synckolab/parser/kolab3/raw/"+src);
- content = synckolab.tools.stripMailHeader(content);
+ content = synckolab.tools.parseMail(content);
print(content);
print("==== STARTING PARSE")
entry = synckolab.addressbookTools.parseMessageContent(content);
diff --git a/test/synckolab/parser/kolab3/json/contact.complex.mime.json b/test/synckolab/parser/kolab3/json/contact.complex.mime.json
index c2cb6d0..eb613e6 100644
--- a/test/synckolab/parser/kolab3/json/contact.complex.mime.json
+++ b/test/synckolab/parser/kolab3/json/contact.complex.mime.json
@@ -5,14 +5,14 @@
"ts": 1349565039427,
"UUID": "urn:uuid:Huu5X7hfYy",
"DisplayName": "Displayname",
- "FirstName": "Lastname",
- "LastName": "Firstname",
+ "FirstName": "Firstname",
+ "LastName": "Lastname",
"Notes": "Notes",
"JobTitle": "Title",
"Profession": "Profession",
"PhotoName": "photo.png",
"PhotoType": "inline",
- "PhotoData": "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAOTQAADpwB3vacVwAABAVJREFUeJztncFrFGcYxt/szLrJmk2yWTeojQktQluiqNFeKglSQmsOHhRyUApKPbeHQC8taKl4E0Hw4sGToAcvgojVQCg0B+2ph0DprTlYs7SQsNlkdzKzmf4DzxvYsCRP9Pkdn5n53iG/fPDy7TczZkIIIYQQov107PQNtI0vrR/mOfveveap/eAcSXeqRsYdSOwIEkKGhJAhIWRICBkSQsbua3u/slEUj346OoPyUrGEW1Uzm5mfycMDNRtB8ciHIy9RXswXi16NuYU5XOOx1VGsGUKGhJAhIWRICBkSQka40zfgcs6uoHjis4l7KB8fG8+ifPa3Wb9GZJdRPHZq7A7KTx45CWu8/uO1X6NFNEPIkBAyJIQMCSFDQsjYni4rxWtmnVOdsGMyM5s8PfkNyocPDwcor1QrcJwoiNzbOvvF2bsoL5fKsMZidRGOU7OaW6NVNEPIkBAyJIQMCSFDQshob5flbCTr/br3BcrPjJ854Q2V78/DTudt9S08P7YY5uXhslfC4jjGNdZwjaSewHwtXHNrtIpmCBkSQoaEkCEhZEgIGRJCxtba3vN4s1q5NADb2+MfHYMbyRqZBmw7zcxqq3jBLg5xe5tkcEu6buteCUsSfE0cOzUifH4jbLg1WkUzhAwJIUNCyJAQMiSEDL/LumQXvENDhaFHKB/sG4QbyZaiJfgTblLDXYuZWZzHnc56irum9SzOkw6/RtOaOE9xnjTxWJmwff/XmiFkSAgZEkKGhJAhIWT4XVYQuOtMS7Vl+J6ON3+/gedv7NvAA5X8G0uL+HUj5j1eCfu7TfLNjjmlzdlz19XEz3VuBc0QMiSEDAkhQ0LIkBAy/C7rQfOxd2jl6toCygufFJ6jPGlEPSiv5+p+/b1OXnByr/varAHyuinv6QLn/CByG9KW0QwhQ0LIkBAyJIQMCSFDQsjY2ka5+8nvKF6ZXv4Y5YWBnl9R3pfthOebmS1nl/C9dToXOO1wrj/nlbAocVYLvXZ4FcdBs32P2WiGkCEhZEgIGRJChoSQ0d6ncG/bfyheSatHUd71c/dDb6gDuQ+mUL6Y/gNX8tIUt0Z9/7qv7bVKXME74jIbeLXQ+SU6zKjLemeREDIkhAwJIUNCyNieN8p14NWhutUuepdEPzVeofxQbugWyivVRa/78r8A8Zf9CPOBzA0U70lC+PcK0qBtX5nQDCFDQsiQEDIkhAwJIWP3fYPqevg5ig8ePPALynu7e72tdfbnk3m8je54eArF+8v7n6G8mOnza7xwaugbVLsDCSFDQsiQEDIkhAwJIWP3tb0eNw2+MTnoyl7zLmlOx985h/DvwV6Nnk1qfNtaDc0QMiSEDAkhQ0LIkBAhhBBCCPEe8D+b5dDLeP4TXAAAAABJRU5ErkJggg",
+ "PhotoData": "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAOTQAADpwB3vacVwAABAVJREFUeJztncFrFGcYxt/szLrJmk2yWTeojQktQluiqNFeKglSQmsOHhRyUApKPbeHQC8taKl4E0Hw4sGToAcvgojVQCg0B+2ph0DprTlYs7SQsNlkdzKzmf4DzxvYsCRP9Pkdn5n53iG/fPDy7TczZkIIIYQQov107PQNtI0vrR/mOfveveap/eAcSXeqRsYdSOwIEkKGhJAhIWRICBkSQsbua3u/slEUj346OoPyUrGEW1Uzm5mfycMDNRtB8ciHIy9RXswXi16NuYU5XOOx1VGsGUKGhJAhIWRICBkSQka40zfgcs6uoHjis4l7KB8fG8+ifPa3Wb9GZJdRPHZq7A7KTx45CWu8/uO1X6NFNEPIkBAyJIQMCSFDQsjYni4rxWtmnVOdsGMyM5s8PfkNyocPDwcor1QrcJwoiNzbOvvF2bsoL5fKsMZidRGOU7OaW6NVNEPIkBAyJIQMCSFDQshob5flbCTr/br3BcrPjJ854Q2V78/DTudt9S08P7YY5uXhslfC4jjGNdZwjaSewHwtXHNrtIpmCBkSQoaEkCEhZEgIGRJCxtba3vN4s1q5NADb2+MfHYMbyRqZBmw7zcxqq3jBLg5xe5tkcEu6buteCUsSfE0cOzUifH4jbLg1WkUzhAwJIUNCyJAQMiSEDL/LumQXvENDhaFHKB/sG4QbyZaiJfgTblLDXYuZWZzHnc56irum9SzOkw6/RtOaOE9xnjTxWJmwff/XmiFkSAgZEkKGhJAhIWT4XVYQuOtMS7Vl+J6ON3+/gedv7NvAA5X8G0uL+HUj5j1eCfu7TfLNjjmlzdlz19XEz3VuBc0QMiSEDAkhQ0LIkBAy/C7rQfOxd2jl6toCygufFJ6jPGlEPSiv5+p+/b1OXnByr/varAHyuinv6QLn/CByG9KW0QwhQ0LIkBAyJIQMCSFDQsjY2ka5+8nvKF6ZXv4Y5YWBnl9R3pfthOebmS1nl/C9dToXOO1wrj/nlbAocVYLvXZ4FcdBs32P2WiGkCEhZEgIGRJChoSQ0d6ncG/bfyheSatHUd71c/dDb6gDuQ+mUL6Y/gNX8tIUt0Z9/7qv7bVKXME74jIbeLXQ+SU6zKjLemeREDIkhAwJIUNCyNieN8p14NWhutUuepdEPzVeofxQbugWyivVRa/78r8A8Zf9CPOBzA0U70lC+PcK0qBtX5nQDCFDQsiQEDIkhAwJIWP3fYPqevg5ig8ePPALynu7e72tdfbnk3m8je54eArF+8v7n6G8mOnza7xwaugbVLsDCSFDQsiQEDIkhAwJIWP3tb0eNw2+MTnoyl7zLmlOx985h/DvwV6Nnk1qfNtaDc0QMiSEDAkhQ0LIkBAhhBBCCPEe8D+b5dDLeP4TXAAAAABJRU5ErkJggg==",
"WebPage1": "www.homepage.org",
"WebPage2": "www.blog.test",
"HomeAddress": "Home Street",
diff --git a/test/synckolab/parser/kolab3/json/contact.simple.mime.json b/test/synckolab/parser/kolab3/json/contact.simple.mime.json
index 6e779b9..d330f4e 100644
--- a/test/synckolab/parser/kolab3/json/contact.simple.mime.json
+++ b/test/synckolab/parser/kolab3/json/contact.simple.mime.json
@@ -5,8 +5,8 @@
"ts": 1349536624864,
"UUID": "urn:uuid:4xuyC0cyjV",
"DisplayName": "Volker Krause",
- "FirstName": "Krause",
- "LastName": "Volker",
+ "FirstName": "Volker",
+ "LastName": "Krause",
"PrimaryEmail": "vkrause@kde.org",
"sha1": "b93a56ffad8ad756d72ca9aae70f49e4bd85ecb8"
} \ No newline at end of file
diff --git a/test/synckolab/parser/kolab3/json/contact.test.mime.json b/test/synckolab/parser/kolab3/json/contact.test.mime.json
index bff573d..d8aa331 100644
--- a/test/synckolab/parser/kolab3/json/contact.test.mime.json
+++ b/test/synckolab/parser/kolab3/json/contact.test.mime.json
@@ -5,8 +5,8 @@
"ts": 1349900866998,
"UUID": "urn:uuid:e79e08cc-0f02-11e2-9e3c-000476ed9009",
"DisplayName": "firstname lastname",
- "FirstName": "lastname",
- "LastName": "firstname",
+ "FirstName": "firstname",
+ "LastName": "lastname",
"Notes": "multi line\nnotes\n\nwith empty",
"HomeAddress": "homestreet",
"HomeAddress2": "",
diff --git a/test/synckolab/parser/kolab3/json/contact.test2.mime.json b/test/synckolab/parser/kolab3/json/contact.test2.mime.json
index 7c35a9a..6c08d2f 100644
--- a/test/synckolab/parser/kolab3/json/contact.test2.mime.json
+++ b/test/synckolab/parser/kolab3/json/contact.test2.mime.json
@@ -5,8 +5,8 @@
"ts": 1349900714929,
"UUID": "urn: uuid:ebf6fdc2-1149-11e2-841b-000476ed9009",
"DisplayName": "Hans Wurst",
- "FirstName": "Wurst",
- "LastName": "Hans",
+ "FirstName": "Hans",
+ "LastName": "Wurst",
"HomePhone": "+49123456789",
"PrimaryEmail": "hans@wurst.de",
"sha1": "c4ea78596ac0cf988a5d6dac68f1510b9ef66b13"
diff --git a/test/synckolab/parser/kolab3/json/contact.test3.mime.json b/test/synckolab/parser/kolab3/json/contact.test3.mime.json
new file mode 100644
index 0000000..d16e37c
--- /dev/null
+++ b/test/synckolab/parser/kolab3/json/contact.test3.mime.json
@@ -0,0 +1 @@
+{"synckolab":"2.9.0","type":"contact","isMailList":false,"ts":1351269299411,"UUID":"urn:uuid:pas-id-A4E937D838A897AD","DisplayName":"cont2#öüä&$","PrimaryEmail":"weird@email.com","PreferMailFormat":0,"AllowRemoteContent":true,"sha1":"f1b30ff3264e645934db12e2894016a83916af8b"} \ No newline at end of file
diff --git a/test/synckolab/parser/kolab3/raw/contact.complex.mime b/test/synckolab/parser/kolab3/raw/contact.complex.mime
index 4a3d52a..54ade78 100644
--- a/test/synckolab/parser/kolab3/raw/contact.complex.mime
+++ b/test/synckolab/parser/kolab3/raw/contact.complex.mime
@@ -84,7 +84,7 @@ CBkSQoaEkJE2M++8vn+OvwNMTw9fhw3ZPdyh5e1lJVVxGp3XClK/wrwwFv6dUOTrpBGcRDO=
EDAkhQ0LIkBAyJISMpHt7z5QwF+Or4LrwDW3NMt5/2rvv3ANiZmFXGn4gh6bxpbqZEXxNRp=
CJhr0a7aIZQoaEkCEhZEgIGRJChoSQQbvsrZb/gA987Jb6fkL5fiX6FOV3y7kvvBoDqTQ8R=
TezY2+hvK8/WEJ52Ki3d1tyApohZEgIGRJChoSQISFk0K6yPto4gGf/l5cP/N/RaB/n2QaD=
-vyT28dIcPvQ2sNnjl9C9vecaCSFDQsiQEDIkhIx/AF4jzh2wCYImAAAAAElFTkSuQmCC</u=
+vyT28dIcPvQ2sNnjl9C9vecaCSFDQsiQEDIkhIx/AF4jzh2wCYImAAAAAElFTkSuQmCC==</u=
ri>
</logo>
<related>
diff --git a/test/synckolab/parser/kolab3/raw/contact.test3.mime b/test/synckolab/parser/kolab3/raw/contact.test3.mime
new file mode 100644
index 0000000..849a35a
--- /dev/null
+++ b/test/synckolab/parser/kolab3/raw/contact.test3.mime
@@ -0,0 +1,50 @@
+From: niko.berger@corinis.com
+Reply-To:
+Bcc:
+To: synckolab@no.tld
+Subject: urn:uuid:pas-id-A4E937D838A897AD
+Date: Fri, 26 Oct 2012 17:25:49 +0200
+Content-Type: Multipart/Mixed;boundary="Boundary-00=D2A398834E826D6C"
+User-Agent: SyncKolab 2.9.0
+X-Kolab-Type: application/vcard+xml
+
+--Boundary-00=D2A398834E826D6C
+Content-Type: Text/Plain;
+ charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+This is a Kolab Groupware object.
+To view this object you will need an email client that can understand the Kolab Groupware format.
+For a list of such email clients please visit
+http://kolab.org/content/kolab-clients
+---
+Name: cont2#&$
+E-Mail:weird@email.com
+---
+
+Notice:
+The information above is only valid, if no other client than synckolab updated this message. (ie. a client that updates the attachment but not the message)
+
+--Boundary-00=D2A398834E826D6C
+Content-Type: application/vcard+xml;
+ name="kolab.xml"
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment;
+ filename="kolab.xml"
+
+PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIiA/
+Pgo8dmNhcmRzIHhtbG5zPSJ1cm46aWV0ZjpwYXJhbXM6eG1sOm5zOnZjYXJkLTQuMCI+Cjx2
+Y2FyZD4KIDx1aWQ+PHVyaT51cm46dXVpZDpwYXMtaWQtQTRFOTM3RDgzOEE4OTdBRDwvdXJp
+PjwvdWlkPgogPHgta29sYWItdmVyc2lvbj48dGV4dD4zLjBkZXYxPC90ZXh0PjwveC1rb2xh
+Yi12ZXJzaW9uPgogPHByb2RpZD48dGV4dD5TeW5jS29sYWIgMi45LjAsIEtvbGFiIHJlc291
+cmNlPC90ZXh0PjwvcHJvZGlkPgogPHJldj48dGltZXN0YW1wPjE5NzAwMTAxVDAwMDAwMFpa
+PC90aW1lc3RhbXA+PC9yZXY+CiA8a2luZD48dGV4dD5pbmRpdmlkdWFsPC90ZXh0Pjwva2lu
+ZD4KICA8Zm4+PHRleHQ+Y29udDIjw7bDvMOkJmFtcDskPC90ZXh0PjwvZm4+CiA8ZW1haWw+
+CiAgPHBhcmFtZXRlcnM+PHByZWY+PGludGVnZXI+MTwvaW50ZWdlcj48L3ByZWY+PC9wYXJh
+bWV0ZXJzPgogIDx0ZXh0PndlaXJkQGVtYWlsLmNvbTwvdGV4dD4KIDwvZW1haWw+Cjx4LWN1
+c3RvbT48aWRlbnRpZmllcj5YLVByZWZlck1haWxGb3JtYXQ8L2lkZW50aWZpZXI+PHZhbHVl
+PnVua25vd248L3ZhbHVlPjwveC1jdXN0b20+CiA8eC1jdXN0b20+PGlkZW50aWZpZXI+WC1B
+bGxvd1JlbW90ZUNvbnRlbnQ8L2lkZW50aWZpZXI+PHZhbHVlPnRydWU8L3ZhbHVlPjwveC1j
+dXN0b20+CjwvdmNhcmQ+CjwvdmNhcmRzPgo=
+
+--Boundary-00=D2A398834E826D6C--
diff --git a/test/synckolab/parser/kolab3/xml/contact.complex.mime.xml b/test/synckolab/parser/kolab3/xml/contact.complex.mime.xml
index 1892809..193c291 100644
--- a/test/synckolab/parser/kolab3/xml/contact.complex.mime.xml
+++ b/test/synckolab/parser/kolab3/xml/contact.complex.mime.xml
@@ -8,8 +8,8 @@
<kind><text>individual</text></kind>
<fn><text>Displayname</text></fn>
<n>
- <surname>Firstname</surname>
- <given>Lastname</given>
+ <surname>Lastname</surname>
+ <given>Firstname</given>
</n>
<note>
<text>Notes</text>
@@ -70,7 +70,7 @@ IUt0Z9/7qv7bVKXME74jIbeLXQ+SU6zKjLemeREDIkhAwJIUNCyNieN8p14NWhutUuepdEP
zVeofxQbugWyivVRa/78r8A8Zf9CPOBzA0U70lC+PcK0qBtX5nQDCFDQsiQEDIkhAwJIWP3
fYPqevg5ig8ePPALynu7e72tdfbnk3m8je54eArF+8v7n6G8mOnza7xwaugbVLsDCSFDQsi
QEDIkhAwJIWP3tb0eNw2+MTnoyl7zLmlOx985h/DvwV6Nnk1qfNtaDc0QMiSEDAkhQ0LIkB
-AhhBBCCPEe8D+b5dDLeP4TXAAAAABJRU5ErkJggg</uri>
+AhhBBCCPEe8D+b5dDLeP4TXAAAAABJRU5ErkJggg==</uri>
</photo>
<tel>
<parameters><type><text>home</text></type></parameters>
@@ -99,6 +99,7 @@ AhhBBCCPEe8D+b5dDLeP4TXAAAAABJRU5ErkJggg</uri>
<text>second@email.org</text>
</email>
<x-custom><identifier>Profession</identifier><value>Profession</value></x-custom>
+ <x-custom><identifier>X-PreferMailFormat</identifier><value>unknown</value></x-custom>
<x-custom><identifier>X-AllowRemoteContent</identifier><value>true</value></x-custom>
</vcard>
</vcards> \ No newline at end of file
diff --git a/test/synckolab/parser/kolab3/xml/contact.simple.mime.xml b/test/synckolab/parser/kolab3/xml/contact.simple.mime.xml
index 36fe656..b507b69 100644
--- a/test/synckolab/parser/kolab3/xml/contact.simple.mime.xml
+++ b/test/synckolab/parser/kolab3/xml/contact.simple.mime.xml
@@ -17,6 +17,7 @@
<parameters><pref><integer>1</integer></pref></parameters>
<text>vkrause@kde.org</text>
</email>
+ <x-custom><identifier>X-PreferMailFormat</identifier><value>unknown</value></x-custom>
<x-custom><identifier>X-AllowRemoteContent</identifier><value>false</value></x-custom>
</vcard>
</vcards> \ No newline at end of file
diff --git a/test/synckolab/parser/kolab3/xml/contact.test.mime.xml b/test/synckolab/parser/kolab3/xml/contact.test.mime.xml
index 19e7b22..77eba92 100644
--- a/test/synckolab/parser/kolab3/xml/contact.test.mime.xml
+++ b/test/synckolab/parser/kolab3/xml/contact.test.mime.xml
@@ -36,6 +36,7 @@ with empty</text>
<code>1234</code>
<country>homecountry</country>
</adr>
+ <x-custom><identifier>X-PreferMailFormat</identifier><value>unknown</value></x-custom>
<x-custom><identifier>X-AllowRemoteContent</identifier><value>false</value></x-custom>
</vcard>
</vcards> \ No newline at end of file
diff --git a/test/synckolab/parser/kolab3/xml/contact.test2.mime.xml b/test/synckolab/parser/kolab3/xml/contact.test2.mime.xml
index 5a92b9b..8ecf7d8 100644
--- a/test/synckolab/parser/kolab3/xml/contact.test2.mime.xml
+++ b/test/synckolab/parser/kolab3/xml/contact.test2.mime.xml
@@ -21,6 +21,7 @@
<parameters><pref><integer>1</integer></pref></parameters>
<text>hans@wurst.de</text>
</email>
+ <x-custom><identifier>X-PreferMailFormat</identifier><value>unknown</value></x-custom>
<x-custom><identifier>X-AllowRemoteContent</identifier><value>false</value></x-custom>
</vcard>
</vcards> \ No newline at end of file
diff --git a/test/synckolab/parser/kolab3/xml/contact.test3.mime.xml b/test/synckolab/parser/kolab3/xml/contact.test3.mime.xml
new file mode 100644
index 0000000..52d2ebb
--- /dev/null
+++ b/test/synckolab/parser/kolab3/xml/contact.test3.mime.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+<vcards xmlns="urn:ietf:params:xml:ns:vcard-4.0">
+<vcard>
+ <uid><uri>urn:uuid:pas-id-A4E937D838A897AD</uri></uid>
+ <x-kolab-version><text>3.0dev1</text></x-kolab-version>
+ <prodid><text>SyncKolab 2.9.0, Kolab resource</text></prodid>
+ <rev><timestamp>19700101T000000ZZ</timestamp></rev>
+ <kind><text>individual</text></kind>
+ <fn><text>cont2#öüä&amp;$</text></fn>
+ <email>
+ <parameters><pref><integer>1</integer></pref></parameters>
+ <text>weird@email.com</text>
+ </email>
+ <x-custom><identifier>X-PreferMailFormat</identifier><value>unknown</value></x-custom>
+ <x-custom><identifier>X-AllowRemoteContent</identifier><value>true</value></x-custom>
+</vcard>
+</vcards>
diff --git a/test/synckolab/tools/data/multipart.eml b/test/synckolab/tools/data/multipart.eml
new file mode 100644
index 0000000..d181b2a
--- /dev/null
+++ b/test/synckolab/tools/data/multipart.eml
@@ -0,0 +1,74 @@
+Date: Fri, 27 Apr 2012 16:58:49 +0200
+X-Kolab-Type: application/x-vnd.kolab.task
+X-Kolab-Mime-Version: 3.0
+User-Agent: Libkolab-0.2.0
+Content-Type: multipart/mixed; boundary="nextPart1676922.i4WXLoZAWe"
+Subject: KOrganizer-396756838.184
+MIME-Version: 1.0
+
+
+--nextPart1676922.i4WXLoZAWe
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: 7Bit
+
+plaintext-part1
+
+--nextPart1676922.i4WXLoZAWe
+Content-Type: application/calendar+xml; name="kolab.xml"
+Content-Transfer-Encoding: quoted-printable
+Content-Disposition: attachment; filename="kolab.xml"
+
+<?xml version=3D"1.0" encoding=3D"UTF-8" standalone=3D"no" ?>
+<xml>
+ <part>2</part>
+</xml>
+
+--nextPart1676922.i4WXLoZAWe
+Content-ID: <2838853.9Y25si6h6e@kolab.resource.akonadi>
+Content-Type: image/png; name="akonadi.png"
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment; filename="akonadi.png"
+
+iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A
+/wD/oL2nkwAAAAlwSFlzAAAbrwAAG68BXhqRHAAAAAd0SU1FB9gFEQkdFPibCIYAAAMrSURBVDjL
+pZNLaBx1AMZ/M/P/78zOzO7ObDbvNUnTxsUUm6YmaulNxN70UKEIRTyIBy8KHrypRUTw4Ek8CqKn
+XuyhHgQRFTRNAvVFbOnDNO/EfWZmdmczszPrwcdBvPnBd/ng98F3+OB/Svl3cPbSx5mZ+ZkXjKx+
+setHs4cHbaW+7d2s79SvhK29j+6vvXH0nwVPfLh1WsTptdnxuDDxoGv3NZWuf4S3G1C722BrrcrO
+nY1f/ebO05s337n3N6cBLLy1bI7njr4uD4nJhx4by5SGLQYcAzWnI6SGVFUkQKwMRqH/jGHNfXJY
+XwoBBMDc/MhLThpOJ6ZEMzM4moquQpIVxI5Br5QlHrEImw5xuzRJ0n4beBlABRgwxcXhUp5Ww6OX
+QvCXo/TPjUJq6FmJldPJOTZ2znj++HOfnwQQ0y9+e67X6iykpmTCNTnY9xBjeTQVelFC0u3RjxNI
++6iaQiajYtmGlXa6NxZe/f4pobv24/X9thBSYebUEHc26zT6kLMkaZTQ84+IvYioE9PrRvTTCBSF
+2PczUTxyVuiOsXHju58Y0XTaQcTJM0OsXt9kaqqIrinEQUTYCPGrAR2vRbcbELS7ZGWEj72hzL+5
+MqS0uzvBys/CzbsUxx0KJROvnTBZLtCPU/y6j1erE/g1wrBNdqREWKwktdB4QP3h8qO/K6Z2RR8b
+JmjtUx7KMDtd4MSozuatXX5Zus3tH29Rre7S18GtjFNanAMpr37w2ti+ABAyeT0eLJ7vtWoDX1z9
+BiXV0DRJmqakSRfd1iiMOmSPjeKeqVC/H3oPT8r3ZNyzVID3L1V2nDzPqsPlQ2PiGKoJCQFJ4qPI
+FH0gh3P6ONlHKlQ3ve6EEb57fl7GSh9DAVjaqmrNRsv97Kv1xeurjcthkCyqURs7JzBdE6NokQgJ
+SbQ+O65+euqEszo4UPytWMhvCwBUkSqq1jk356xNDUevLK/sPbl+L7jQ8ZLyUaepGE1xMDZhfDlb
+KSwPFt1tXcp9qWk1VWjhP2e6dneLvhdqLc/L7B3UzfX1qttsdfKKguo4ZlguO36xWAgLth3mbSsy
+TatnyFz6B+BnWV0A/UiAAAAAAElFTkSuQmCC
+
+--nextPart1676922.i4WXLoZAWe
+Content-ID: <2222@kolab.resource.akonadi>
+Content-Type: image/png; name="akonadi2.png"
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment; filename="akonadi2.png"
+
+iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A
+/wD/oL2nkwAAAAlwSFlzAAAbrwAAG68BXhqRHAAAAAd0SU1FB9gFEQkdFPibCIYAAAMrSURBVDjL
+pZNLaBx1AMZ/M/P/78zOzO7ObDbvNUnTxsUUm6YmaulNxN70UKEIRTyIBy8KHrypRUTw4Ek8CqKn
+XuyhHgQRFTRNAvVFbOnDNO/EfWZmdmczszPrwcdBvPnBd/ng98F3+OB/Svl3cPbSx5mZ+ZkXjKx+
+setHs4cHbaW+7d2s79SvhK29j+6vvXH0nwVPfLh1WsTptdnxuDDxoGv3NZWuf4S3G1C722BrrcrO
+nY1f/ebO05s337n3N6cBLLy1bI7njr4uD4nJhx4by5SGLQYcAzWnI6SGVFUkQKwMRqH/jGHNfXJY
+XwoBBMDc/MhLThpOJ6ZEMzM4moquQpIVxI5Br5QlHrEImw5xuzRJ0n4beBlABRgwxcXhUp5Ww6OX
+QvCXo/TPjUJq6FmJldPJOTZ2znj++HOfnwQQ0y9+e67X6iykpmTCNTnY9xBjeTQVelFC0u3RjxNI
++6iaQiajYtmGlXa6NxZe/f4pobv24/X9thBSYebUEHc26zT6kLMkaZTQ84+IvYioE9PrRvTTCBSF
+2PczUTxyVuiOsXHju58Y0XTaQcTJM0OsXt9kaqqIrinEQUTYCPGrAR2vRbcbELS7ZGWEj72hzL+5
+MqS0uzvBys/CzbsUxx0KJROvnTBZLtCPU/y6j1erE/g1wrBNdqREWKwktdB4QP3h8qO/K6Z2RR8b
+JmjtUx7KMDtd4MSozuatXX5Zus3tH29Rre7S18GtjFNanAMpr37w2ti+ABAyeT0eLJ7vtWoDX1z9
+BiXV0DRJmqakSRfd1iiMOmSPjeKeqVC/H3oPT8r3ZNyzVID3L1V2nDzPqsPlQ2PiGKoJCQFJ4qPI
+FH0gh3P6ONlHKlQ3ve6EEb57fl7GSh9DAVjaqmrNRsv97Kv1xeurjcthkCyqURs7JzBdE6NokQgJ
+SbQ+O65+euqEszo4UPytWMhvCwBUkSqq1jk356xNDUevLK/sPbl+L7jQ8ZLyUaepGE1xMDZhfDlb
+KSwPFt1tXcp9qWk1VWjhP2e6dneLvhdqLc/L7B3UzfX1qttsdfKKguo4ZlguO36xWAgLth3mbSsy
+TatnyFz6B+BnWV0A/UiAAAAAAElFTkSuQmCC
+
+--nextPart1676922.i4WXLoZAWe--
diff --git a/test/synckolab/tools/toolsTest.js b/test/synckolab/tools/toolsTest.js
index 7d4770c..47517a8 100644
--- a/test/synckolab/tools/toolsTest.js
+++ b/test/synckolab/tools/toolsTest.js
@@ -26,13 +26,26 @@ test("synckolab.Node", function(){
});
+test("synckolab.tools.parseMail", function(){
+ var message = readFile("test/synckolab/tools/data/multipart.eml");
+ message = synckolab.tools.parseMail(message);
+ equal(message.content.replace(/[\r\n ]+/g, ""), ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>" +
+"<xml>" +
+" <part>2</part>" +
+"</xml>").replace(/[\r\n ]+/g, ""), "content");
+ equal(2, message.parts.length, "2 attachments");
+ equal(message.parts[0].id, "2838853.9Y25si6h6e@kolab.resource.akonadi", "content id of attchment 1");
+ equal(message.parts[0].name, "akonadi.png", "name of attchment 1");
+ equal(message.parts[1].id, "2222@kolab.resource.akonadi", "content id of attchment 2");
+ equal(message.parts[1].name, "akonadi2.png", "name of attchment 2");
+});
/**
* Test uuencoded message
*/
test("synckolab.tools.uudecode", function(){
var message = readFile("test/synckolab/tools/data/uutest1.eml");
- message = synckolab.tools.stripMailHeader(message);
+ message = synckolab.tools.parseMail(message);
equal(message.content.replace(/[\r\n]+/g, " "), ("BEGIN:VCARD " +
"VERSION:3.0 " +
"PRODID:-//kerio.com/Contacts//NONSGML v1.0//EN " +
@@ -56,7 +69,7 @@ test("synckolab.tools.uudecode", function(){
*/
test("synckolab.tools.quoteddecode", function(){
var message = readFile("test/synckolab/tools/data/quotedtest1.eml");
- message = synckolab.tools.stripMailHeader(message);
+ message = synckolab.tools.parseMail(message);
equal(message.content.replace(/[ \r\n]+/g, ""), ("BEGIN:VCALENDAR" +
"PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN " +
"VERSION:2.0 " +
@@ -74,5 +87,5 @@ test("synckolab.tools.quoteddecode", function(){
/*
var content = readFile("test/synckolab/tools/data/uutest1.eml");
-print(synckolab.tools.stripMailHeader(content));
+print(synckolab.tools.parseMail(content));
*/ \ No newline at end of file