summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorniko <niko>2012-10-26 14:46:03 (GMT)
committerniko <niko>2012-10-26 14:46:03 (GMT)
commit3ce6a3cf783d624c84e0a05a6a03310ad43c6e9a (patch)
tree3456f29001536e2eb8b13c40ff2713a8340ff884
parentcbcc1d1672fd98e4088f6274d40daf2b74eb1eac (diff)
downloadsynckolab-3ce6a3cf783d624c84e0a05a6a03310ad43c6e9a.tar.gz
test quoted decoding
-rw-r--r--src/chrome/content/synckolab/addressbookTools.js33
-rw-r--r--src/chrome/content/synckolab/tools.js31
-rw-r--r--src/chrome/content/synckolab/tools/text.js1
-rw-r--r--test/synckolab/tools/data/quotedtest1.eml24
-rw-r--r--test/synckolab/tools/toolsTest.js23
5 files changed, 69 insertions, 43 deletions
diff --git a/src/chrome/content/synckolab/addressbookTools.js b/src/chrome/content/synckolab/addressbookTools.js
index 8ba7bf8..ed42a09 100644
--- a/src/chrome/content/synckolab/addressbookTools.js
+++ b/src/chrome/content/synckolab/addressbookTools.js
@@ -1686,16 +1686,16 @@ synckolab.addressbookTools.card2Kolab3 = function (card, skipHeader, fields) {
var adate;
if (this.haveCardProperty(card, "BirthYear") && this.haveCardProperty(card, "BirthMonth") && this.haveCardProperty(card, "BirthDay")) {
- adate = synckolab.tools.text.splitDate2String (card, "Birth", true);
+ adate = synckolab.tools.text.splitDate2String(card, "Birth", true);
xml += " <bday>" + synckolab.tools.text.nodeWithContent("date-time", adate + "T000000", false) + "</bday>\n";
}
if (this.haveCardProperty(card, "AnniversaryYear") && this.haveCardProperty(card, "AnniversaryMonth") && this.haveCardProperty(card, "AnniversaryDay")) {
- adate = synckolab.tools.text.splitDate2String (card, "Anniversary", true);
+ adate = synckolab.tools.text.splitDate2String(card, "Anniversary", true);
xml += " <anniversary>" + synckolab.tools.text.nodeWithContent("date", adate, false) + "</anniversary>\n";
}
- // TODO photo name = photo - base64-Encoded
+ // photo name = photo - base64-Encoded
var ptype = this.getCardProperty(card, "PhotoType");
if(ptype === "inline") {
var fileName = this.getCardProperty(card, "PhotoName");
@@ -1704,19 +1704,6 @@ synckolab.addressbookTools.card2Kolab3 = function (card, skipHeader, fields) {
xml += " <photo>\n <uri>data:" + ptype + ";base64," + synckolab.tools.text.splitInto(this.getCardProperty(card, "PhotoData"), 72) +
"</uri>\n </photo>";
}
- /*
- xml += synckolab.tools.text.nodeWithContent("picture", this.getCardProperty(card, "PhotoName"), false);
-
- // we can probably ignore that
- if (ptype === "web" || ptype === "file") {
- * kolab:
- * 1. read the file: FILENAME = this.getCardProperty(card, "PhotoName")
- * found in ~profil/Photos/FILENAME
- * 2. create an attachment name FILENAME with the content (base64 encoded)
- *
- xml += synckolab.tools.text.nodeWithContent("picture-uri", this.getCardProperty(card, "PhotoURI"), false); // we can distinguish between file: and http: anyways
- }
- */
xml += this.getXmlProperty(card, "AimScreenName", "impp", "uri");
@@ -3505,7 +3492,16 @@ synckolab.addressbookTools.card2Message = function (card, email, format, fields)
return synckolab.tools.generateMail(this.getUID(card), email, "", "application/x-vnd.kolab.contact.distlist", true, synckolab.tools.text.utf8.encode(this.list2Xml(card, fields)), this.list2Human(card));
} else {
// generat email with optional image attachment
- 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), this.getCardProperty(card, "PhotoName"));
+ var img = null;
+ var ptype = this.getCardProperty(card, "PhotoType");
+ if(ptype === "inline") {
+ img = {
+ 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);
}
} else if(format === "xml-k3") {
// mailing list
@@ -3525,9 +3521,8 @@ synckolab.addressbookTools.card2Message = function (card, email, format, fields)
/*
return synckolab.tools.generateMail(this.getUID(card), email, "vCard", "text/vcard",
false, decodeURIComponent(card.translateTo("vcard")), null);
- - this works kinda... some fields ar emissing and others are wrong named in order to be compatible with kolab
+ - this works kinda... some fields are missing and others are wrong named in order to be compatible with kolab
*/
-
};
/*
diff --git a/src/chrome/content/synckolab/tools.js b/src/chrome/content/synckolab/tools.js
index 4b01825..512a6fd 100644
--- a/src/chrome/content/synckolab/tools.js
+++ b/src/chrome/content/synckolab/tools.js
@@ -555,7 +555,7 @@ 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 (the name of the image - it always resides in profile/Photos/XXX.jpg!)
+ * @param image optional image attachment (must be {"name": nameOfImage, "data": base64data} )
*/
generateMail: function (cid, mail, adsubject, mime, part, skcontent, hr, image){
// sometime we just do not want a new message :)
@@ -646,32 +646,17 @@ 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) {
- var file = this.getProfileFolder();
+ if (part && image && image.data) {
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 (fileContent !== null) {
- this.logMessage("got " + fileContent.length + " bytes", synckolab.global.LOG_INFO);
-
+ if (image.data !== null) {
// now we got the image into fileContent - lets attach
-
msg += '\n--Boundary-00='+bound+'\n';
- msg += 'Content-Type: image/jpeg;\n name="'+image+'"\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+'"\n\n';
- msg += fileContent;
+ msg += 'Content-Disposition: attachment;\n filename="'+image.name+'"\n\n';
+ msg += synckolab.tools.text.splitInto(image.data, 72);
}
}
catch (ex)
diff --git a/src/chrome/content/synckolab/tools/text.js b/src/chrome/content/synckolab/tools/text.js
index 2eaa683..17cd000 100644
--- a/src/chrome/content/synckolab/tools/text.js
+++ b/src/chrome/content/synckolab/tools/text.js
@@ -255,6 +255,7 @@ synckolab.tools.text = {
switch(tz) {
case "/kolab.org/Europe/Berlin": tz = 1; break;
case "/kolab.org/Europe/Vienna": tz = 1; break;
+ case "/kolab.org/Europe/Rome": tz = 1; break;
}
}
diff --git a/test/synckolab/tools/data/quotedtest1.eml b/test/synckolab/tools/data/quotedtest1.eml
new file mode 100644
index 0000000..2ced3e0
--- /dev/null
+++ b/test/synckolab/tools/data/quotedtest1.eml
@@ -0,0 +1,24 @@
+From: test@no.com
+Reply-To:
+Bcc:
+To: synckolab@no.tld
+Subject: iCal bcf938ec-c5ce-49a9-bb89-5c5442c87415
+Date: Thu, 3 May 2007 12:22:32 +0200
+Content-Type: text/calendar;
+ charset="utf-8"
+Content-Transfer-Encoding: quoted-printable
+User-Agent: SyncKolab 0.4.33
+
+BEGIN:VCALENDAR
+PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
+VERSION:2.0
+BEGIN:VEVENT
+CREATED:20121026T122145Z
+LAST-MODIFIED:20121026T122205Z
+DTSTAMP:20121026T122205Z
+UID:19a700e7-c207-4e7c-a212-6831dbfbb0fc
+SUMMARY:test
+DTSTART;TZID=3DEurope/Rome:20121027T140000
+DTEND;TZID=3DEurope/Rome:20121027T150000
+END:VEVENT
+END:VCALENDAR
diff --git a/test/synckolab/tools/toolsTest.js b/test/synckolab/tools/toolsTest.js
index b58f210..7d4770c 100644
--- a/test/synckolab/tools/toolsTest.js
+++ b/test/synckolab/tools/toolsTest.js
@@ -49,8 +49,29 @@ test("synckolab.tools.uudecode", function(){
"BDAY;VALUE=DATE:20121010\n" +
"UID:bfcaf3d0-4c85-4c5c-94e2-ca5f9ea1d264\n" +
"END:VCARD").replace(/\n/g, " "), "uuencoded vcard");
-
});
+
+/**
+ * Test encoded message
+ */
+test("synckolab.tools.quoteddecode", function(){
+ var message = readFile("test/synckolab/tools/data/quotedtest1.eml");
+ message = synckolab.tools.stripMailHeader(message);
+ equal(message.content.replace(/[ \r\n]+/g, ""), ("BEGIN:VCALENDAR" +
+"PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN " +
+"VERSION:2.0 " +
+"BEGIN:VEVENT " +
+"CREATED:20121026T122145Z " +
+"LAST-MODIFIED:20121026T122205Z " +
+"DTSTAMP:20121026T122205Z " +
+"UID:19a700e7-c207-4e7c-a212-6831dbfbb0fc " +
+"SUMMARY:test " +
+"DTSTART;TZID=Europe/Rome:20121027T140000 " +
+"DTEND;TZID=Europe/Rome:20121027T150000 " +
+"END:VEVENT " +
+"END:VCALENDAR").replace(/[ \n]/g, ""), "quoted encoded vcard");
+});
+
/*
var content = readFile("test/synckolab/tools/data/uutest1.eml");
print(synckolab.tools.stripMailHeader(content));