mod_cloud_notify_encrypted/mod_cloud_notify_encrypted.lua
changeset 4655 8231774f5bfd
parent 4654 44af84178cea
child 5058 62480053c87b
equal deleted inserted replaced
4654:44af84178cea 4655:8231774f5bfd
     1 local array = require "util.array";
     1 local array = require "util.array";
     2 local base64 = require "util.encodings".base64;
     2 local base64 = require "util.encodings".base64;
       
     3 local valid_utf8 = require "util.encodings".utf8.valid;
     3 local ciphers = require "openssl.cipher";
     4 local ciphers = require "openssl.cipher";
     4 local jid = require "util.jid";
     5 local jid = require "util.jid";
     5 local json = require "util.json";
     6 local json = require "util.json";
     6 local random = require "util.random";
     7 local random = require "util.random";
     7 local set = require "util.set";
     8 local set = require "util.set";
    76 		body = "You have received an encrypted message";
    77 		body = "You have received an encrypted message";
    77 	else
    78 	else
    78 		body = original_stanza:get_child_text("body");
    79 		body = original_stanza:get_child_text("body");
    79 		if body and #body > 255 then
    80 		if body and #body > 255 then
    80 			body = body:sub(1, 255);
    81 			body = body:sub(1, 255);
       
    82 			if not valid_utf8(body) then
       
    83 				body = body:gsub("[\194-\244][\128-\191]*$", "");
       
    84 			end
    81 		end
    85 		end
    82 	end
    86 	end
    83 
    87 
    84 	local push_payload = {
    88 	local push_payload = {
    85 		unread = tonumber(push_summary["message-count"]) or 1;
    89 		unread = tonumber(push_summary["message-count"]) or 1;