Skip to content

Commit

Permalink
Use native host to clean Quoted Printable message data
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehuff committed Mar 29, 2015
1 parent 85200da commit d1bc403
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,14 444,30 @@ webpg.background = {
var content,
plaintext = (request.plaintext!==undefined) ?
request.plaintext : null;
if (request.data && request.data.length > 0) {
content = request.data.replace(/^([-] )(?=[\r\n]|\s\n)/gm, '\\$1');
var lowerBlock = content.match(/(-----BEGIN PGP.*?)\n.*?\n\n/gim);
if (lowerBlock && lowerBlock.length > 1) {
content.substr(0, content.indexOf(lowerBlock[1]) lowerBlock[1].length)
content.substr(content.indexOf(lowerBlock[1]) lowerBlock[1].length, content.length).replace(/\n\n/gim, "\n");
}
request.data = content;
function cleanData(data, content) {
if (data && data.length > 0) {
content = data.replace(/^([-] )(?=[\r\n]|\s\n)/gm, '\\$1');
var lowerBlock = content.match(/(-----BEGIN PGP.*?)\n.*?\n\n/gim);
if (lowerBlock && lowerBlock.length > 1) {
content.substr(0, content.indexOf(lowerBlock[1]) lowerBlock[1].length)
content.substr(content.indexOf(lowerBlock[1]) lowerBlock[1].length, content.length).replace(/\n\n/gim, "\n");
}
request.data = content;
}
processMessage();
};
if (request.hasOwnProperty('encoding')) {
console.log(request);
if (request.encoding === 'quoted-printable')
webpg.plugin.quotedPrintableDecode(request.data, function(res) {
cleanData(res, content);
});
else if (request.encoding === 'base64')
webpg.plugin.base64Decode(request.data, function(res) {
cleanData(res, content);
});
} else {
cleanData(request.data, content);
}
function checkSignatures(response) {
if (response.signatures === null) {
Expand Down Expand Up @@ -493,13 509,15 @@ webpg.background = {
checkSignatures(response);
}
};
if (request.message_event && request.message_event === "context") {
content = (request.data) ? request.data :
request.selectionData.selectionText;
content = content.replace(/^([-] )(?=[\r\n]|\s\n)/gm, '\\$1');
webpg.plugin.gpgVerify(content, plaintext, responseMethod);
} else {
webpg.plugin.gpgVerify(request.data, plaintext, responseMethod);
function processMessage() {
if (request.message_event && request.message_event === "context") {
content = (request.data) ? request.data :
request.selectionData.selectionText;
content = content.replace(/^([-] )(?=[\r\n]|\s\n)/gm, '\\$1');
webpg.plugin.gpgVerify(content, plaintext, responseMethod);
} else {
webpg.plugin.gpgVerify(request.data, plaintext, responseMethod);
}
}
return true;
break;
Expand Down

0 comments on commit d1bc403

Please sign in to comment.