[7146] | 1 | <!-- |
---|
| 2 | /* |
---|
| 3 | * Mail Archive JS API |
---|
| 4 | * |
---|
| 5 | * This JavaScript file is the core to use MailArchiver embeded at Expresso suite. |
---|
| 6 | * It contains all the resources used to handle local messages stored at the brand |
---|
| 7 | * new solution Mail Archiver (a embeded application server running at client side). |
---|
| 8 | * |
---|
| 9 | * This feature is a replacement for Google Gears(obsolete by now), used by |
---|
| 10 | * Expresso to store local messages at user workstation hard disk. |
---|
| 11 | * |
---|
| 12 | * @author Fernando Wendt [fernando-alberto.wendt@serpro.gov.br] |
---|
| 13 | * |
---|
| 14 | * @status under development |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | //var sessid = 'sessionId'; |
---|
| 18 | |
---|
| 19 | function zeroFill(d){ |
---|
| 20 | if(parseInt(d) < 10) |
---|
| 21 | return('0' + d); |
---|
| 22 | else |
---|
| 23 | return(d); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | //+ Jonas Raoni Soares Silva |
---|
| 27 | //@ http://jsfromhell.com/geral/utf-8 [v1.0] |
---|
| 28 | |
---|
| 29 | UTF8 = { |
---|
| 30 | encode: function(s){ |
---|
| 31 | for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l; |
---|
| 32 | s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i] |
---|
| 33 | ); |
---|
| 34 | return s.join(""); |
---|
| 35 | }, |
---|
| 36 | decode: function(s){ |
---|
| 37 | for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l; |
---|
| 38 | ((a = s[i][c](0)) & 0x80) && |
---|
| 39 | (s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ? |
---|
| 40 | o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "") |
---|
| 41 | ); |
---|
| 42 | return s.join(""); |
---|
| 43 | } |
---|
| 44 | }; |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | * Concatenates the values of a variable into an easily readable string |
---|
| 49 | * by Matt Hackett [scriptnode.com] |
---|
| 50 | * @param {Object} x The variable to debug |
---|
| 51 | * @param {Number} max The maximum number of recursions allowed (keep low, around 5 for HTML elements to prevent errors) [default: 10] |
---|
| 52 | * @param {String} sep The separator to use between [default: a single space ' '] |
---|
| 53 | * @param {Number} l The current level deep (amount of recursion). Do not use this parameter: it's for the function's own use |
---|
| 54 | */ |
---|
| 55 | function print_r(x, max, sep, l) { |
---|
| 56 | |
---|
| 57 | l = l || 0; |
---|
| 58 | max = max || 100; |
---|
| 59 | sep = sep || ' '; |
---|
| 60 | |
---|
| 61 | if (l > max) { |
---|
| 62 | return "[WARNING: Too much recursion]\n"; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | var |
---|
| 66 | i, |
---|
| 67 | r = '', |
---|
| 68 | t = typeof x, |
---|
| 69 | tab = ''; |
---|
| 70 | |
---|
| 71 | if (x === null) { |
---|
| 72 | r += "(null)\n"; |
---|
| 73 | } else if (t == 'object') { |
---|
| 74 | |
---|
| 75 | l++; |
---|
| 76 | |
---|
| 77 | for (i = 0; i < l; i++) { |
---|
| 78 | tab += sep; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | if (x && x.length) { |
---|
| 82 | t = 'array'; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | r += '(' + t + ") :\n"; |
---|
| 86 | |
---|
| 87 | for (i in x) { |
---|
| 88 | try { |
---|
| 89 | r += tab + '[' + i + '] : ' + print_r(x[i], max, sep, (l + 1)); |
---|
| 90 | } catch(e) { |
---|
| 91 | return "[ERROR: " + e + "]\n"; |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | } else { |
---|
| 96 | |
---|
| 97 | if (t == 'string') { |
---|
| 98 | if (x == '') { |
---|
| 99 | x = '(empty)'; |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | r += '(' + t + ') ' + x + "\n"; |
---|
| 104 | |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | return r; |
---|
| 108 | |
---|
| 109 | }; |
---|
| 110 | var_dump = print_r; |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | //Main object structure: object property data definition |
---|
| 115 | function MailArchiver() { |
---|
| 116 | this.enabled = null; |
---|
| 117 | this.interval = 500; |
---|
| 118 | this.timer = null; |
---|
| 119 | this.counter = 0; |
---|
| 120 | this.service_count = 0; |
---|
| 121 | this.service_count_tryouts = 0; |
---|
| 122 | this.message_list = new Array(); |
---|
| 123 | this.search_message_list = new Array(); |
---|
| 124 | this.messageslisted = new Array(); |
---|
| 125 | this.total_messages = 0; |
---|
| 126 | this.messages_processed = 0; |
---|
| 127 | this.messages_fail = 0; |
---|
| 128 | this.folder_origin = null; |
---|
| 129 | this.folder_destination = null; |
---|
| 130 | this.folders = null; |
---|
| 131 | this.currentfolder = 'local_root'; |
---|
| 132 | this.currentmessage = null; |
---|
| 133 | this.currentheaders = null; |
---|
| 134 | this.drawdata = null; |
---|
| 135 | this.onprocess = false; |
---|
| 136 | this.folder_data = false; |
---|
| 137 | this.queryconfig = new MAQueryConfig(); |
---|
| 138 | this.search_queryconfig = new MAQueryConfig(); |
---|
| 139 | this.pattern = new MAPattern(); |
---|
| 140 | this.messagesourcehandler = null; |
---|
| 141 | this.ServiceReturnObjectList = null; |
---|
| 142 | this.ServiceReturnObjectSearch = null; |
---|
| 143 | |
---|
| 144 | this.specialfolders = { |
---|
| 145 | "inbox":"local_inbox", |
---|
| 146 | "sent":"local_sent", |
---|
| 147 | "drafts":"local_drafts", |
---|
| 148 | "outbox":"local_outbox", |
---|
| 149 | "trash":"local_trash" |
---|
| 150 | }; |
---|
| 151 | this.unarchivecounter = 0; |
---|
| 152 | this.archivefolder = null; |
---|
| 153 | this.unarchievefolder = null; |
---|
| 154 | this.unarchievenewfolder = null; |
---|
| 155 | this.taglist = ""; |
---|
| 156 | this.currenttag = ""; |
---|
| 157 | this.tagmsg = false; |
---|
| 158 | this.progressbar = null; |
---|
| 159 | this.tmp_att_datasource = null; |
---|
| 160 | this.tmp_att_data = null; |
---|
| 161 | this.isbusy = false; |
---|
| 162 | this.update_counters = false; |
---|
| 163 | this.exportformat = 'zip'; |
---|
| 164 | this.querydata = null; |
---|
| 165 | this.queryresult = null; |
---|
| 166 | this.search_queryresult = null; |
---|
| 167 | this.balancerid = null; |
---|
| 168 | this.sessionid = null; |
---|
| 169 | this.logonid = null; |
---|
| 170 | this.session = null; |
---|
| 171 | this.selectedfolder = null; |
---|
[7409] | 172 | this.allmessagesbyfolder = new Array(); |
---|
[7468] | 173 | this.allcompletemessagesbyfolder = new Array(); |
---|
[7449] | 174 | this.isArchiveOperation = false; //Se estiver em andamento uma operação de arquivamento/desarquivamento. |
---|
[7455] | 175 | //Contadores da aba de listagem de mensagem |
---|
| 176 | this.tot_msgs_tab = 0; |
---|
| 177 | this.tot_unseen_msgs_tab = 0; |
---|
[7146] | 178 | } |
---|
| 179 | |
---|
| 180 | //Invoked at some possible MA crash issue |
---|
| 181 | MailArchiver.prototype.resetObject = function(){ |
---|
| 182 | expresso_mail_archive.message_list = new Array(); |
---|
| 183 | expresso_mail_archive.messagelisted = new Array(); |
---|
| 184 | expresso_mail_archive.total_messages = 0; |
---|
| 185 | expresso_mail_archive.messages_processed = 0; |
---|
| 186 | expresso_mail_archive.messages_fail = 0; |
---|
| 187 | //expresso_mail_archive.folder_origin = null; |
---|
| 188 | //expresso_mail_archive.folder_destination = null; |
---|
| 189 | //expresso_mail_archive.folder = null; |
---|
| 190 | expresso_mail_archive.isbusy = false; |
---|
| 191 | //window.alert('ResetedObject, deixando current folder como "' + expresso_mail_archive.currentfolder + '"\nfolder destination "' + expresso_mail_archive.folder_destination+ '"'); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | /*SystemCheck method: test if MailArchive is installed and/or running at user workstation |
---|
| 195 | *Try to get a instance of ArchiveServices object - the handler of services provided by |
---|
| 196 | *the MailArchive services provider interface, from user workstation. |
---|
| 197 | */ |
---|
| 198 | MailArchiver.prototype.SystemCheck = function(){ |
---|
| 199 | expresso_mail_archive.enabled = ((ArchiveServices) ? true : false); |
---|
| 200 | if(expresso_mail_archive.enabled){ |
---|
| 201 | expresso_mail_archive.getAuthId(); |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | //Check if preference is setted to use default local folders, try to create them |
---|
| 206 | MailArchiver.prototype.CreateDefaultStructrure = function(){ |
---|
| 207 | if(expresso_mail_archive.enabled){ |
---|
| 208 | //Base request object is a CXF Add-on CORS compatible component |
---|
| 209 | var reqHandler = new cxf_cors_request_object(); |
---|
| 210 | reqHandler.init(); |
---|
| 211 | this.messagesourcehandler = reqHandler.handler; |
---|
| 212 | if(preferences.auto_create_local == 1){ |
---|
| 213 | expresso_mail_archive.createFolder("","Trash"); |
---|
| 214 | expresso_mail_archive.createFolder("","Drafts"); |
---|
| 215 | expresso_mail_archive.createFolder("","Sent"); |
---|
| 216 | expresso_mail_archive.createFolder("","Outbox"); |
---|
| 217 | expresso_mail_archive.createFolder("","Spam"); |
---|
| 218 | } |
---|
| 219 | this.ActivateStatusListener(this); |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | //Turns on the listener timer to check services availability |
---|
| 225 | MailArchiver.prototype.ActivateStatusListener = function(obj){ |
---|
| 226 | if (document.getElementById('mail_archiver_retry')) |
---|
| 227 | tem_tag = true; |
---|
| 228 | else |
---|
| 229 | tem_tag = false; |
---|
| 230 | try{ |
---|
| 231 | if (obj.enabled){ |
---|
| 232 | obj.interval = 500; //set default timer to 1ms (imediate lauching) |
---|
| 233 | //draw_footer_box(get_current_folder()); |
---|
| 234 | obj.getServicesStatus(obj); |
---|
| 235 | } |
---|
| 236 | else{ |
---|
| 237 | throw "this is not enabled: " + obj; |
---|
| 238 | window.alert('Nope: obj.enabled is not true...'); |
---|
| 239 | } |
---|
| 240 | } |
---|
| 241 | catch (e){ |
---|
| 242 | window.alert('ActivateStatusListener error: ' + e); |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | //Turns off the service status listener, at a crash issue |
---|
| 247 | MailArchiver.prototype.DeactivateStatusListener = function(obj){ |
---|
| 248 | window.clearInterval(obj.timer); |
---|
| 249 | obj.enabled = null; |
---|
| 250 | obj.timer=null; |
---|
| 251 | obj.interval = 500; |
---|
| 252 | ArchiveServices = null; |
---|
| 253 | connector.purgeCache(); |
---|
| 254 | draw_footer_box(get_current_folder()); |
---|
| 255 | //auto_refresh(); |
---|
| 256 | if(document.getElementById('mail_archiver_retry')){ |
---|
| 257 | document.getElementById('mail_archiver_retry').parentNode.removeChild(document.getElementById('mail_archiver_retry')); |
---|
| 258 | } |
---|
| 259 | else{ |
---|
| 260 | //Redraw "Offline" linkage, intended to recoonect MailArchiver link |
---|
| 261 | connector.purgeCache(); |
---|
[7270] | 262 | draw_new_tree_folder(); |
---|
| 263 | change_folder('INBOX', 'INBOX'); |
---|
[7146] | 264 | } |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | //ServiceStatus callback OK |
---|
| 268 | MailArchiver.prototype.getServicesStatusOK = function(serviceData){ |
---|
| 269 | //window.alert('getServicesStatusOK com servicedata = ' + serviceData.getReturn()); |
---|
| 270 | expresso_mail_archive.service_count = expresso_mail_archive.counter; |
---|
| 271 | if ((serviceData.getReturn().toUpperCase() == "STARTED") || (serviceData.getReturn().toUpperCase() == "RUNNING")){ |
---|
| 272 | //If there is no timer activated to services check interval, set it up. |
---|
| 273 | if(expresso_mail_archive.enabled){ |
---|
| 274 | if(expresso_mail_archive.timer == null){ |
---|
| 275 | expresso_mail_archive.interval = 15000; |
---|
| 276 | expresso_mail_archive.timer = window.setInterval(expresso_mail_archive.getServicesStatus, expresso_mail_archive.interval); |
---|
| 277 | var drawinginfo = {treeObject: tree_folders, treeName: 'tree_folders', folderName: 'local_root'}; |
---|
| 278 | expresso_mail_archive.currentfolder = 'local_root'; |
---|
| 279 | expresso_mail_archive.drawdata = drawinginfo; |
---|
| 280 | expresso_mail_archive.getFoldersList(); |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | else{ |
---|
| 284 | window.clearInterval(expresso_mail_archive.timer); |
---|
[7270] | 285 | write_msg(get_lang('MailArchiver does not seems to be running or installed at this workstation, local messages are disabled. Check it out!'),false); |
---|
| 286 | expresso_mail_archive.enabled = false; |
---|
| 287 | expresso_mail_archive.turnOffLocalTreeStructure(); |
---|
[7146] | 288 | } |
---|
| 289 | } |
---|
| 290 | else{ |
---|
| 291 | window.clearInterval(expresso_mail_archive.timer); |
---|
[7270] | 292 | write_msg(get_lang('MailArchiver does not seems to be running or installed at this workstation, local messages are disabled. Check it out!'),false); |
---|
| 293 | expresso_mail_archive.enabled = false; |
---|
| 294 | expresso_mail_archive.turnOffLocalTreeStructure(); |
---|
[7146] | 295 | } |
---|
| 296 | //window.alert('fooArc set to null'); |
---|
| 297 | fooArc = null; |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | //Dettach resources handler |
---|
| 301 | MailArchiver.prototype.DeactivateResources = function(obj){ |
---|
| 302 | if(obj.timer) |
---|
| 303 | window.clearInterval(obj.timer); |
---|
| 304 | write_msg(get_lang('Mail Archiver is not responding. There is some communicating issue hang it up. Some services may not work properly. Check it out!')); |
---|
| 305 | obj.DeactivateStatusListener(obj); |
---|
[7270] | 306 | //draw_new_tree_folder(); |
---|
[7146] | 307 | return; |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | //Services Status Fail callback |
---|
| 311 | MailArchiver.prototype.getServicesStatusFailure = function(serviceData){ |
---|
| 312 | window.alert('getServicesStatusFailure incomming'); |
---|
| 313 | window.alert('getServicesStatusFailure feature: ' + serviceData); |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | //Service Status handler |
---|
| 317 | MailArchiver.prototype.getServicesStatus = function(obj){ |
---|
| 318 | //window.alert('em getServicesStatus obj.enabled = ' + obj.enabled + '\nArchiveServices.enabled = ' + ArchiveServices.enabled + '\nArchiveServices = ' + ArchiveServices); |
---|
| 319 | try{ |
---|
| 320 | //window.alert('on try 01'); |
---|
| 321 | expresso_mail_archive.service_count_tryouts++; |
---|
| 322 | //window.alert('service_count_tryouts = ' + expresso_mail_archive.service_count_tryouts + '\nservice_count = ' + expresso_mail_archive.service_count); |
---|
| 323 | |
---|
| 324 | if((expresso_mail_archive.service_count_tryouts - expresso_mail_archive.service_count) > 1){ |
---|
| 325 | //window.alert('problema -> deve desligar'); |
---|
| 326 | expresso_mail_archive.DeactivateResources(expresso_mail_archive); |
---|
| 327 | } |
---|
[7270] | 328 | //else |
---|
[7146] | 329 | //window.alert('ok'); |
---|
| 330 | |
---|
| 331 | var fooArc = new web_service_mailarchiver_serpro__ArchiveServices(); |
---|
| 332 | fooArc.url = mail_archive_protocol + "://" + mail_archive_host + ":" + mail_archive_port + "/arcserv/ArchiveServices"; |
---|
| 333 | //window.alert('typeof(fooArc) = ' + typeof(fooArc) + '\nfooArc = ' + fooArc); |
---|
| 334 | if(fooArc){ |
---|
| 335 | try{ |
---|
| 336 | //window.alert('on try 02'); |
---|
| 337 | fooArc.getState(expresso_mail_archive.getServicesStatusOK, expresso_mail_archive.getServicesStatusFailure, "true"); |
---|
| 338 | fooArc = null; |
---|
| 339 | }catch (e){ |
---|
| 340 | throw "Service failure status: getState"; |
---|
| 341 | } |
---|
| 342 | } |
---|
| 343 | else { |
---|
| 344 | throw "No ArchiveServices object present. Sorry, but leaving now..."; |
---|
| 345 | } |
---|
| 346 | }catch (e){ |
---|
| 347 | //window.alert('getServiceStatus exception:' + e); |
---|
| 348 | } |
---|
| 349 | expresso_mail_archive.counter = expresso_mail_archive.counter +1; |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | /*Restart method: re-initializes all the Mail Archive structure |
---|
| 353 | **/ |
---|
| 354 | MailArchiver.prototype.Restart = function(obj){ |
---|
| 355 | obj.SystemCheck(); |
---|
| 356 | obj.ActivateStatusListener(obj); |
---|
[7270] | 357 | //connector.resetProgressBarText(); |
---|
[7473] | 358 | clean_msg(); |
---|
[7270] | 359 | auto_refresh(); |
---|
[7146] | 360 | } |
---|
| 361 | |
---|
| 362 | /*Startup method: initializes all the Mail Archive structure to work so far as possible |
---|
| 363 | *Looks like the old 'gears_init', from Gears |
---|
| 364 | **/ |
---|
| 365 | MailArchiver.prototype.Startup = function(){ |
---|
| 366 | this.SystemCheck(); |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | MailArchiver.prototype.serializeToExpresso = function(data){ |
---|
| 370 | return(connector.serialize(data)); |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | MailArchiver.prototype.unserializeFromExpresso = function(data){ |
---|
| 374 | return(connector.unserialize(data)); |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | |
---|
| 378 | MailArchiver.prototype.CreateMessageList = function(msg_list){ |
---|
| 379 | //window.alert('criando messagelist de arquivamento.'); |
---|
| 380 | |
---|
| 381 | // for(var j=0; j<expresso_mail_archive.messageslisted.length; j++){ |
---|
| 382 | // window.alert('\nAnswered = ' + expresso_mail_archive.messageslisted[j]["Answered"] + '\nFlagged = ' + expresso_mail_archive.messageslisted[j]["Flagged"] + '\nUnseen = ' + expresso_mail_archive.messageslisted[j]["Unseen"] + '\nDraft = ' + expresso_mail_archive.messageslisted[j]["Draft"]); |
---|
| 383 | // } |
---|
| 384 | |
---|
| 385 | if((msg_list != null) && (msg_list != "") && (msg_list != " ")){ |
---|
| 386 | if (expresso_mail_archive.message_list.length == 0){ |
---|
| 387 | //Get all the messages ids by pass at msgs_id to "message_list" object array propertie - if more than one exists |
---|
| 388 | if(msg_list.indexOf(',') != -1){ |
---|
| 389 | var tmp_list = msg_list.split(','); |
---|
| 390 | for(var i=0; i < tmp_list.length; i++){ |
---|
| 391 | expresso_mail_archive.message_list.push(tmp_list[i]); |
---|
| 392 | } |
---|
| 393 | } |
---|
| 394 | |
---|
| 395 | //Push message list to process the only one |
---|
| 396 | else { |
---|
| 397 | //window.alert('testando marcadores default...\n->Answered = ' +expresso_mail_archive.messageslisted[i]["Answered"] + '\n->Unseen = '+expresso_mail_archive.messageslisted[i]["Unseen"]); |
---|
| 398 | expresso_mail_archive.message_list.push(msg_list); |
---|
| 399 | } |
---|
| 400 | } |
---|
| 401 | } |
---|
| 402 | //msg_list is corrupted. aborting population |
---|
| 403 | else expresso_mail_archive.message_list = new Array(); |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | |
---|
| 407 | //Archive Operation |
---|
| 408 | MailArchiver.prototype.Archive = function(source_folder,destination_folder,msgs_id){ |
---|
| 409 | //window.alert('tentando arquivar a mensagem [' + msgs_id + '], do folder ['+source_folder+'] para a pasta destino ['+destination_folder+']'); |
---|
[7157] | 410 | //modal('archive_queue'); |
---|
[7146] | 411 | |
---|
| 412 | try{ |
---|
| 413 | //Sets the folders properties: destination and origin |
---|
| 414 | expresso_mail_archive.folder_origin = source_folder; |
---|
| 415 | expresso_mail_archive.CreateMessageList(msgs_id); |
---|
[7449] | 416 | expresso_mail_archive.isArchiveOperation = true; |
---|
[7146] | 417 | var tagsHandler = function(data){ |
---|
| 418 | if(data){ |
---|
| 419 | var datah = eval(data); |
---|
| 420 | //window.alert('unseen = ' +datah["unseen"] + '\nrecent = ' + datah["recent"] + '\nflagged = ' + datah["flagged"] + '\ndraft = ' + datah["draft"] + '\nanswered = ' + datah["answered"] + '\ndeleted = ' + datah["deleted"] + '\nforwarded = ' + datah["forwarded"]); |
---|
| 421 | expresso_mail_archive.taglist = datah; |
---|
| 422 | //Sets the message counter and busy state |
---|
| 423 | if(expresso_mail_archive.isbusy == false){ |
---|
| 424 | expresso_mail_archive.total_messages = expresso_mail_archive.message_list.length; |
---|
| 425 | expresso_mail_archive.isbusy = true; |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | var fcaption = ""; |
---|
[8112] | 429 | |
---|
| 430 | // tratado o caso do id da pasta vir com local_messages_ ou messages_ |
---|
| 431 | var local_folder_id = destination_folder; |
---|
| 432 | if(local_folder_id){ |
---|
| 433 | if(local_folder_id.substr(0,5) == 'local'){ |
---|
| 434 | local_folder_id = local_folder_id.replace("local_messages_",""); |
---|
| 435 | } else if(local_folder_id.substr(0,8) == 'messages'){ |
---|
| 436 | local_folder_id = local_folder_id.replace("messages_",""); |
---|
| 437 | } |
---|
| 438 | } |
---|
| 439 | |
---|
[7146] | 440 | |
---|
| 441 | if(!expresso_mail_archive.archivefolder){ |
---|
[8112] | 442 | expresso_mail_archive.getFolderInfo(local_folder_id); |
---|
[7146] | 443 | if(typeof(expresso_mail_archive.folder) != "undefined"){ |
---|
| 444 | //window.alert('folder.path -> ' + expresso_mail_archive.folder.path); |
---|
| 445 | expresso_mail_archive.archivefolder = expresso_mail_archive.folder.path; |
---|
| 446 | //window.alert('folder.path2 -> ' + expresso_mail_archive.folder.path); |
---|
| 447 | } |
---|
| 448 | else{ |
---|
| 449 | //window.alert('ainda, sem folder.path'); |
---|
| 450 | //window.alert('testando folder.path agora ' + expresso_mail_archive.folder.path); |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | fcaption = expresso_mail_archive.archivefolder; |
---|
| 455 | |
---|
| 456 | //Special folders translation |
---|
| 457 | if (fcaption && ((fcaption.toLowerCase() == 'inbox') || (fcaption.toLowerCase() == 'outbox') || (fcaption.toLowerCase() == 'sent') || (fcaption.toLowerCase() == 'drafts') || (fcaption.toLowerCase() == 'trash'))) |
---|
| 458 | fcaption = get_lang(fcaption); |
---|
| 459 | |
---|
| 460 | |
---|
| 461 | var arch_handler = function(data){ |
---|
| 462 | //Store the message source from Ajax request by now (string data) |
---|
| 463 | var js_var = new String(data); |
---|
| 464 | try{ |
---|
| 465 | //Archive services needs session id, message source and destination folder |
---|
[7157] | 466 | ArchiveServices.archive(expresso_mail_archive.getArchiveOperationOK, expresso_mail_archive.getArchiveOperationFailure, expresso_mail_archive.session.id, expresso_mail_archive.folder_destination, data); |
---|
[7146] | 467 | } |
---|
| 468 | catch(e){ |
---|
| 469 | expresso_mail_archive.getFaultInfo(); |
---|
| 470 | } |
---|
| 471 | } |
---|
| 472 | |
---|
| 473 | //document.getElementById('main_title').innerHTML = get_lang('Archiving message %1 of %2 on folder %3', expresso_mail_archive.messages_processed, expresso_mail_archive.total_messages, fcaption); |
---|
[7157] | 474 | //document.getElementById('text_archive_queue').innerHTML = get_lang('Archiving message %1 of %2 on folder %3', expresso_mail_archive.messages_processed+1, expresso_mail_archive.total_messages, fcaption); |
---|
[7146] | 475 | cExecute("$this.exporteml.js_source_var",arch_handler,"folder="+url_decode(source_folder)+"&msgs_to_export="+expresso_mail_archive.message_list[0]); |
---|
| 476 | } |
---|
| 477 | else{ |
---|
[7157] | 478 | //close_lightbox(); |
---|
[7146] | 479 | write_msg(get_lang('Archive operation error: getting online message flags fails. Achievement will not be done'),true); |
---|
| 480 | expresso_mail_archive.archivefolder = null; |
---|
| 481 | } |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | if((expresso_mail_archive.message_list.length > 0) && (expresso_mail_archive.message_list[0] != '')){ |
---|
| 485 | |
---|
| 486 | //Get all tags from current archiving message |
---|
| 487 | if(!expresso_mail_archive.folder_origin){ |
---|
| 488 | var aux1_folder = expresso_mail_archive.message_list[0].split(';')[0]; |
---|
| 489 | var aux1_msg_number = expresso_mail_archive.message_list[0].split(';')[1]; |
---|
| 490 | } |
---|
| 491 | else{ |
---|
| 492 | var aux1_folder = expresso_mail_archive.folder_origin; |
---|
| 493 | var aux1_msg_number = expresso_mail_archive.message_list[0]; |
---|
| 494 | } |
---|
| 495 | //var pardata = "&folder=" + url_encode(expresso_mail_archive.folder_origin)+ "&msg_number="+ expresso_mail_archive.message_list[0]; |
---|
| 496 | var pardata = "&folder=" + url_encode(aux1_folder)+ "&msg_number="+ aux1_msg_number; |
---|
| 497 | cExecute("$this.imap_functions.get_msg_flags", tagsHandler, pardata); |
---|
| 498 | } |
---|
| 499 | else throw('Archive operation error: message list stack is empty'); |
---|
| 500 | } |
---|
| 501 | catch(e){ |
---|
| 502 | //window.alert(get_lang("Archive error: %1", (e.description)?e.description:e)); |
---|
[7157] | 503 | expresso_mail_archive.getFaultInfo(); |
---|
[7146] | 504 | } |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | //Archive callback OK |
---|
| 508 | MailArchiver.prototype.getArchiveOperationOK = function(status_message){ |
---|
| 509 | //message must be tagged |
---|
| 510 | var arcid = status_message.getReturn().getId(); |
---|
| 511 | var tlist = expresso_mail_archive.pattern.tagConfig(expresso_mail_archive.taglist, arcid, 0); |
---|
| 512 | if(tlist != null){ |
---|
| 513 | try{ |
---|
| 514 | expresso_mail_archive.drawdata = null //removes any draw parameter to archive msgs |
---|
| 515 | ArchiveServices.tagMessages(expresso_mail_archive.tagMessagesOperationOK, expresso_mail_archive.tagMessagesOperationFailure, expresso_mail_archive.session.id, tlist); |
---|
| 516 | }catch (e){ |
---|
| 517 | expresso_mail_archive.getFaultInfo(); |
---|
| 518 | } |
---|
| 519 | } |
---|
[7449] | 520 | |
---|
[7146] | 521 | //if user preference is setted to move messages, here, whe will call a delete message at mailserver |
---|
| 522 | if(preferences.keep_archived_messages == 0){ |
---|
| 523 | proxy_mensagens.delete_msgs(expresso_mail_archive.folder_origin,expresso_mail_archive.message_list[0],null,false,true); |
---|
| 524 | }else{ |
---|
| 525 | if (Element("check_box_message_" + expresso_mail_archive.message_list[0])) { |
---|
| 526 | Element("check_box_message_" + expresso_mail_archive.message_list[0]).checked = false; |
---|
| 527 | remove_className(Element(expresso_mail_archive.message_list[0]), 'selected_msg'); |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | //archivement allready done, update controll data and interface |
---|
| 532 | expresso_mail_archive.messages_processed++; |
---|
| 533 | if(expresso_mail_archive.message_list.length > 1){ |
---|
[7331] | 534 | write_msg(get_lang("Message %1 of %2 successfully archived", expresso_mail_archive.messages_processed, expresso_mail_archive.total_messages)); |
---|
[7146] | 535 | expresso_mail_archive.message_list.shift(); |
---|
| 536 | expresso_mail_archive.Archive(expresso_mail_archive.folder_origin, expresso_mail_archive.folder_destination, expresso_mail_archive.message_list); |
---|
| 537 | } |
---|
| 538 | else{ |
---|
[7184] | 539 | write_msg(get_lang("All done. End of archive messages operation")); |
---|
[7146] | 540 | expresso_mail_archive.resetObject(); |
---|
| 541 | expresso_mail_archive.archivefolder = null; |
---|
| 542 | window.setTimeout("eval('document.getElementById(\"main_title\").innerHTML =\"Expresso Mail\"')",3000); |
---|
| 543 | connector.purgeCache(); |
---|
| 544 | //ttreeBox.name_folder = "local_" + expresso_mail_archive.currentfolder; |
---|
[7183] | 545 | //ttreeBox.name_folder = "local_inbox"; |
---|
[7146] | 546 | draw_tree_local_folders(); |
---|
| 547 | //ttreeBox.update_folder(true); |
---|
[7449] | 548 | expresso_mail_archive.isArchiveOperation = false; |
---|
[7146] | 549 | } |
---|
[7183] | 550 | //close_lightbox(); |
---|
[7146] | 551 | } |
---|
| 552 | //Archive callback Fail |
---|
| 553 | MailArchiver.prototype.getArchiveOperationFailure = function(error_message){ |
---|
| 554 | window.alert('Hi! getArchiveOperationFailure comes with ' + error_message.getReturn()); |
---|
| 555 | window.setTimeout("eval('document.getElementById(\"main_title\").innerHTML =\"Expresso Mail\"')",3000); |
---|
| 556 | } |
---|
| 557 | |
---|
| 558 | /** |
---|
[7202] | 559 | *move Folder |
---|
| 560 | * |
---|
| 561 | *@author Thiago Rossetto Afonso [thiago@prognus.com.br] |
---|
| 562 | * |
---|
| 563 | *@param folder_to_move Current folder that will be moved to another folder |
---|
| 564 | *@param folder_to Folter that will receive the new folder |
---|
| 565 | */ |
---|
[7206] | 566 | MailArchiver.prototype.moveFolder = function(folder_to_move, folder_to){ |
---|
[7202] | 567 | try{ |
---|
| 568 | connector.showProgressBar(); |
---|
[7206] | 569 | ArchiveServices.moveFolder(expresso_mail_archive.moveFolderOK, expresso_mail_archive.moveFolderFailure, expresso_mail_archive.session.id, folder_to_move, folder_to); |
---|
[7202] | 570 | }catch(e){ |
---|
| 571 | expresso_mail_archive.getFaultInfo(); |
---|
| 572 | } |
---|
| 573 | } |
---|
[7206] | 574 | MailArchiver.prototype.moveFolderOK = function(message){ |
---|
| 575 | write_msg(get_lang("Your folder was moved!")); |
---|
[7202] | 576 | } |
---|
[7206] | 577 | MailArchiver.prototype.moveFolderFailure = function(error_message){ |
---|
[7202] | 578 | alert("Error: " + error_message.getReturn()); |
---|
| 579 | } |
---|
| 580 | |
---|
[8063] | 581 | MailArchiver.prototype.unarchieveToAttach = function (folder, new_folder, msgs_number, callback){ |
---|
[7907] | 582 | try{ |
---|
[7202] | 583 | |
---|
[8063] | 584 | if(typeof callback !== 'function') callback = function(){}; |
---|
| 585 | |
---|
[7907] | 586 | if(typeof(expresso_mail_archive.idMsgsToAttach) == "undefined"){ |
---|
| 587 | expresso_mail_archive.idMsgsToAttach = new Array(); |
---|
| 588 | } |
---|
| 589 | //write_msg(get_lang("Starting to unarchive messages")); |
---|
| 590 | expresso_mail_archive.isArchiveOperation = true; |
---|
| 591 | if(currentTab.toString().indexOf("_r") != -1){ |
---|
| 592 | msgs_number = currentTab.toString().substr(0,currentTab.toString().indexOf("_r")); |
---|
| 593 | } |
---|
[7202] | 594 | |
---|
[7907] | 595 | if(!msgs_number) |
---|
| 596 | msgs_number = get_selected_messages(); |
---|
| 597 | |
---|
| 598 | if (parseInt(msgs_number) > 0 || msgs_number.length > 0){ |
---|
| 599 | |
---|
| 600 | expresso_mail_archive.messageToAttach = msgs_number; |
---|
| 601 | if(expresso_mail_archive.messageToAttach) { |
---|
| 602 | |
---|
| 603 | expresso_mail_archive.unarchivecounter = 0; |
---|
| 604 | expresso_mail_archive.unarchive_error_counter=0; |
---|
[8112] | 605 | |
---|
| 606 | // tratado o caso do id da pasta vir com local_messages_ ou messages_ |
---|
| 607 | var local_folder_id = folder; |
---|
| 608 | if(local_folder_id){ |
---|
| 609 | if(local_folder_id.substr(0,5) == 'local'){ |
---|
| 610 | local_folder_id = local_folder_id.replace("local_messages_",""); |
---|
| 611 | } else if(local_folder_id.substr(0,8) == 'messages'){ |
---|
| 612 | local_folder_id = local_folder_id.replace("messages_",""); |
---|
| 613 | } |
---|
| 614 | } |
---|
| 615 | |
---|
| 616 | expresso_mail_archive.getFolderInfo(local_folder_id); |
---|
[7907] | 617 | expresso_mail_archive.unarchievefolder = expresso_mail_archive.folder.name; |
---|
| 618 | (new_folder != null)?expresso_mail_archive.unarchievenewfolder = new_folder:expresso_mail_archive.unarchievenewfolder='INBOX'; |
---|
| 619 | |
---|
[8063] | 620 | expresso_mail_archive.unarchieveToAttachHandler(callback); |
---|
[7907] | 621 | |
---|
| 622 | if(currentTab.toString().indexOf("_r") != -1){ |
---|
| 623 | delete_border(currentTab,'false'); |
---|
| 624 | } |
---|
| 625 | } |
---|
| 626 | else{ |
---|
| 627 | write_msg(get_lang('No selected message.')); |
---|
| 628 | } |
---|
| 629 | } |
---|
| 630 | else |
---|
| 631 | write_msg(get_lang('No selected message.')); |
---|
| 632 | |
---|
| 633 | clear_selected_messages(); |
---|
| 634 | } |
---|
| 635 | catch (e){ |
---|
| 636 | write_msg(get_lang('Unarchive error: ' + e)); |
---|
| 637 | } |
---|
| 638 | } |
---|
[7202] | 639 | |
---|
[8063] | 640 | MailArchiver.prototype.unarchieveToAttachHandler = function(uCallback){ |
---|
[7907] | 641 | try{ |
---|
[8063] | 642 | var email = mail_archive_protocol+'://'+mail_archive_host+':'+mail_archive_port+'/mail/' + expresso_mail_archive.session.id +'/'+ expresso_mail_archive.folder.path + '/'+ expresso_mail_archive.messageToAttach + '.eml'; |
---|
[7907] | 643 | |
---|
| 644 | //Creates a new object to unarchive messages. It's a CXF Add-on CORS component |
---|
| 645 | var UnarchiveReqHandler = new cxf_cors_request_object(); |
---|
| 646 | UnarchiveReqHandler.init(); |
---|
| 647 | |
---|
| 648 | //Both XDomainRequest and XMLHttpRequest L2 supports onload event |
---|
| 649 | UnarchiveReqHandler.handler.onload = function(){ |
---|
| 650 | for (var w=0; w < expresso_mail_archive.allcompletemessagesbyfolder.length; w++){ |
---|
| 651 | |
---|
| 652 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["msg_number"] == expresso_mail_archive.messageToAttach){ |
---|
| 653 | var timestamp = expresso_mail_archive.allcompletemessagesbyfolder[w]["timestamp"]; |
---|
| 654 | |
---|
| 655 | //Get local tagged message data |
---|
| 656 | var flags = new String(""); |
---|
| 657 | |
---|
| 658 | //Forwarded is special one: marks as "answered" and "draft" |
---|
| 659 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Forwarded"]){ |
---|
| 660 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Forwarded"] == 'F') |
---|
| 661 | flags += 'A:X'+':'; |
---|
| 662 | } |
---|
| 663 | else{ |
---|
| 664 | //Answered tag |
---|
| 665 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Answered"]) |
---|
| 666 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Answered"] == 'A') |
---|
| 667 | flags += 'A'+':'; |
---|
| 668 | else |
---|
| 669 | flags += ':'; |
---|
| 670 | else |
---|
| 671 | flags += ':'; |
---|
| 672 | |
---|
| 673 | //Draft tag |
---|
| 674 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Draft"]) |
---|
| 675 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Draft"] == 'X') |
---|
| 676 | flags += 'D'+':'; |
---|
| 677 | else |
---|
| 678 | flags += ':'; |
---|
| 679 | else |
---|
| 680 | flags += ':'; |
---|
| 681 | } |
---|
| 682 | |
---|
| 683 | //Flagged tag |
---|
| 684 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Flagged"]) |
---|
| 685 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Flagged"] == 'F') |
---|
| 686 | flags += 'F'+':'; |
---|
| 687 | else |
---|
| 688 | flags += ':'; |
---|
| 689 | else |
---|
| 690 | flags += ':'; |
---|
| 691 | |
---|
| 692 | //Unseen tag |
---|
| 693 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Unseen"]) |
---|
| 694 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Unseen"] == 'U') |
---|
| 695 | flags += 'U'; |
---|
| 696 | else |
---|
| 697 | flags += ''; |
---|
| 698 | else |
---|
| 699 | flags += ''; |
---|
| 700 | |
---|
| 701 | //Imap tag hash id |
---|
| 702 | flags += "#@#@#@"; |
---|
| 703 | |
---|
| 704 | break; |
---|
| 705 | } |
---|
| 706 | } |
---|
| 707 | var id = expresso_mail_archive.messageToAttach; |
---|
| 708 | var source = encodeURIComponent(UnarchiveReqHandler.handler.responseText) + "#@#@#@"; |
---|
| 709 | var params = |
---|
| 710 | "&folder=" + escape(expresso_mail_archive.unarchievenewfolder) + |
---|
| 711 | "&source=" + source + |
---|
| 712 | "×tamp=" + timestamp + |
---|
| 713 | "&madata=true" + |
---|
| 714 | "&flags=" + flags + |
---|
| 715 | "&id=" + id; |
---|
| 716 | |
---|
| 717 | |
---|
| 718 | var handler_unarchive = function(data){ |
---|
| 719 | expresso_mail_archive.unarchieveToAttachController(data); |
---|
| 720 | } |
---|
| 721 | write_msg(get_lang("Please, Wait the messages from archieve be ready.")); |
---|
| 722 | |
---|
| 723 | $.ajax({ |
---|
| 724 | url: "controller.php?action=$this.imap_functions.unarchive_mail", |
---|
| 725 | success: function(data){ |
---|
| 726 | data = connector.unserialize(data); |
---|
| 727 | expresso_mail_archive.idMsgsToAttach.push(data.idsMsg); |
---|
| 728 | handler_unarchive(data); |
---|
[8063] | 729 | uCallback(data); |
---|
[7907] | 730 | }, |
---|
| 731 | async: false, |
---|
| 732 | data: params, |
---|
| 733 | type: 'POST', |
---|
| 734 | |
---|
| 735 | }); |
---|
| 736 | |
---|
| 737 | } |
---|
| 738 | |
---|
| 739 | |
---|
| 740 | UnarchiveReqHandler.handler.open("GET", email, true); |
---|
| 741 | if(UnarchiveReqHandler.handler.overrideMimeType){ |
---|
| 742 | UnarchiveReqHandler.handler.overrideMimeType("message/rfc822; charset=windows-1252"); |
---|
| 743 | } |
---|
| 744 | UnarchiveReqHandler.handler.send(); |
---|
| 745 | } |
---|
| 746 | catch(e){ |
---|
| 747 | write_msg(get_lang('Unarchive error: ' + e)); |
---|
| 748 | } |
---|
| 749 | } |
---|
| 750 | |
---|
| 751 | MailArchiver.prototype.unarchieveToAttachController = function(data){ |
---|
| 752 | |
---|
| 753 | if (data){ |
---|
| 754 | if (data.error != "") { |
---|
| 755 | expresso_mail_archive.unarchive_error_counter++; |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | } |
---|
| 759 | } |
---|
| 760 | |
---|
| 761 | |
---|
[7202] | 762 | /** |
---|
[7146] | 763 | *Unarchieve Message |
---|
| 764 | * |
---|
| 765 | *@author Cassiano Dal Pizzol [cassiano.dalpizzol@serpro.gov.br] |
---|
| 766 | * |
---|
| 767 | *@param folder Original Folder of the message |
---|
| 768 | *@param new_folder The new folder of the message |
---|
| 769 | *@param msgs_number id of the messages |
---|
| 770 | */ |
---|
| 771 | MailArchiver.prototype.unarchieve = function (folder, new_folder, msgs_number){ |
---|
| 772 | try{ |
---|
[8067] | 773 | |
---|
| 774 | var aclShare = false; |
---|
| 775 | $.ajax({ |
---|
| 776 | url: 'controller.php?' + $.param( { action: '$this.imap_functions.verifyShareFolder', folder: new_folder } ), |
---|
| 777 | success: function( data ){ |
---|
| 778 | data = connector.unserialize( data ); |
---|
| 779 | if(data != null){ |
---|
| 780 | if(!data.status){ |
---|
| 781 | aclShare = true; |
---|
| 782 | } |
---|
| 783 | } |
---|
| 784 | |
---|
| 785 | }, |
---|
| 786 | async: false |
---|
| 787 | }); |
---|
| 788 | |
---|
| 789 | if(aclShare){ |
---|
| 790 | write_msg(get_lang("You don't have permission for this operation in this shared folder!")); |
---|
| 791 | return false; |
---|
| 792 | } |
---|
| 793 | |
---|
[7189] | 794 | write_msg(get_lang("Starting to unarchive messages")); |
---|
[7449] | 795 | expresso_mail_archive.isArchiveOperation = true; |
---|
[7146] | 796 | if(currentTab.toString().indexOf("_r") != -1){ |
---|
| 797 | msgs_number = currentTab.toString().substr(0,currentTab.toString().indexOf("_r")); |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | if(!msgs_number) |
---|
| 801 | msgs_number = get_selected_messages(); |
---|
| 802 | |
---|
| 803 | if (parseInt(msgs_number) > 0 || msgs_number.length > 0){ |
---|
| 804 | expresso_mail_archive.message_list = new Array(); |
---|
| 805 | expresso_mail_archive.CreateMessageList(msgs_number); |
---|
| 806 | if((expresso_mail_archive.message_list.length > 0) && (expresso_mail_archive.message_list[0] != '')) { |
---|
| 807 | expresso_mail_archive.unarchivecounter = 0; |
---|
| 808 | expresso_mail_archive.unarchive_error_counter=0; |
---|
[8112] | 809 | |
---|
| 810 | // tratado o caso do id da pasta vir com local_messages_ ou messages_ |
---|
| 811 | var local_folder_id = folder; |
---|
| 812 | if(local_folder_id){ |
---|
| 813 | if(local_folder_id.substr(0,5) == 'local'){ |
---|
| 814 | local_folder_id = local_folder_id.replace("local_messages_",""); |
---|
| 815 | } else if(local_folder_id.substr(0,8) == 'messages'){ |
---|
| 816 | local_folder_id = local_folder_id.replace("messages_",""); |
---|
| 817 | } |
---|
| 818 | } |
---|
| 819 | |
---|
| 820 | expresso_mail_archive.getFolderInfo(local_folder_id); |
---|
[7146] | 821 | expresso_mail_archive.unarchievefolder = expresso_mail_archive.folder.name; |
---|
| 822 | (new_folder != null)?expresso_mail_archive.unarchievenewfolder = new_folder:expresso_mail_archive.unarchievenewfolder='INBOX'; |
---|
[7224] | 823 | |
---|
[7146] | 824 | expresso_mail_archive.unarchieveHandler(); |
---|
[7224] | 825 | |
---|
[7204] | 826 | if(currentTab.toString().indexOf("_r") != -1){ |
---|
| 827 | delete_border(currentTab,'false'); |
---|
| 828 | } |
---|
[7146] | 829 | } |
---|
| 830 | else{ |
---|
| 831 | write_msg(get_lang('No selected message.')); |
---|
[7205] | 832 | } |
---|
| 833 | } |
---|
[7146] | 834 | else |
---|
| 835 | write_msg(get_lang('No selected message.')); |
---|
[7539] | 836 | |
---|
| 837 | clear_selected_messages(); |
---|
[7146] | 838 | } |
---|
| 839 | catch (e){ |
---|
| 840 | write_msg(get_lang('Unarchive error: ' + e)); |
---|
| 841 | } |
---|
| 842 | } |
---|
| 843 | |
---|
| 844 | /** |
---|
| 845 | * |
---|
| 846 | *Unarchieve Message Handler |
---|
| 847 | * |
---|
| 848 | *@author Cassiano Dal Pizzol [cassiano.dalpizzol@serpro.gov.br] |
---|
| 849 | * |
---|
| 850 | **/ |
---|
| 851 | MailArchiver.prototype.unarchieveHandler = function(){ |
---|
| 852 | try{ |
---|
| 853 | var email = mail_archive_protocol+'://'+mail_archive_host+':'+mail_archive_port+'/mail/' + expresso_mail_archive.session.id +'/'+ expresso_mail_archive.folder.path + '/'+ expresso_mail_archive.message_list[expresso_mail_archive.unarchivecounter] + '.eml'; |
---|
| 854 | |
---|
| 855 | //Creates a new object to unarchive messages. It's a CXF Add-on CORS component |
---|
| 856 | var UnarchiveReqHandler = new cxf_cors_request_object(); |
---|
| 857 | UnarchiveReqHandler.init(); |
---|
| 858 | |
---|
| 859 | //Both XDomainRequest and XMLHttpRequest L2 supports onload event |
---|
| 860 | UnarchiveReqHandler.handler.onload = function(){ |
---|
[7468] | 861 | for (var w=0; w < expresso_mail_archive.allcompletemessagesbyfolder.length; w++){ |
---|
[7146] | 862 | |
---|
[7468] | 863 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["msg_number"] == expresso_mail_archive.message_list[expresso_mail_archive.unarchivecounter]){ |
---|
| 864 | var timestamp = expresso_mail_archive.allcompletemessagesbyfolder[w]["timestamp"]; |
---|
[7146] | 865 | |
---|
| 866 | //Get local tagged message data |
---|
| 867 | var flags = new String(""); |
---|
| 868 | |
---|
| 869 | //Forwarded is special one: marks as "answered" and "draft" |
---|
[7468] | 870 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Forwarded"]){ |
---|
| 871 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Forwarded"] == 'F') |
---|
[7428] | 872 | flags += 'A:X'+':'; |
---|
[7146] | 873 | } |
---|
| 874 | else{ |
---|
| 875 | //Answered tag |
---|
[7468] | 876 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Answered"]) |
---|
| 877 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Answered"] == 'A') |
---|
[7428] | 878 | flags += 'A'+':'; |
---|
[7146] | 879 | else |
---|
| 880 | flags += ':'; |
---|
| 881 | else |
---|
| 882 | flags += ':'; |
---|
| 883 | |
---|
| 884 | //Draft tag |
---|
[7468] | 885 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Draft"]) |
---|
| 886 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Draft"] == 'X') |
---|
[7146] | 887 | flags += 'D'+':'; |
---|
| 888 | else |
---|
| 889 | flags += ':'; |
---|
| 890 | else |
---|
| 891 | flags += ':'; |
---|
| 892 | } |
---|
| 893 | |
---|
| 894 | //Flagged tag |
---|
[7468] | 895 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Flagged"]) |
---|
| 896 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Flagged"] == 'F') |
---|
[7146] | 897 | flags += 'F'+':'; |
---|
| 898 | else |
---|
| 899 | flags += ':'; |
---|
| 900 | else |
---|
| 901 | flags += ':'; |
---|
| 902 | |
---|
| 903 | //Unseen tag |
---|
[7468] | 904 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Unseen"]) |
---|
| 905 | if(expresso_mail_archive.allcompletemessagesbyfolder[w]["Unseen"] == 'U') |
---|
[7146] | 906 | flags += 'U'; |
---|
| 907 | else |
---|
| 908 | flags += ''; |
---|
| 909 | else |
---|
| 910 | flags += ''; |
---|
| 911 | |
---|
| 912 | //Imap tag hash id |
---|
| 913 | flags += "#@#@#@"; |
---|
| 914 | |
---|
| 915 | break; |
---|
| 916 | } |
---|
| 917 | } |
---|
| 918 | var id = expresso_mail_archive.message_list[expresso_mail_archive.unarchivecounter]; |
---|
| 919 | var source = encodeURIComponent(UnarchiveReqHandler.handler.responseText) + "#@#@#@"; |
---|
| 920 | var params = |
---|
| 921 | "&folder=" + escape(expresso_mail_archive.unarchievenewfolder) + |
---|
| 922 | "&source=" + source + |
---|
| 923 | "×tamp=" + timestamp + |
---|
| 924 | "&madata=true" + |
---|
| 925 | "&flags=" + flags + |
---|
| 926 | "&id=" + id; |
---|
[7458] | 927 | |
---|
[7146] | 928 | var handler_unarchive = function(data){ |
---|
| 929 | expresso_mail_archive.unarchieveController(data); |
---|
| 930 | } |
---|
[7189] | 931 | write_msg(get_lang('Unarchiving message %1 of %2', (expresso_mail_archive.unarchivecounter + 1), expresso_mail_archive.message_list.length)); |
---|
[7458] | 932 | |
---|
[7907] | 933 | //cExecute ("$this.imap_functions.unarchive_mail&", handler_unarchive, params); |
---|
| 934 | |
---|
| 935 | $.ajax({ |
---|
| 936 | url: "controller.php?action=$this.imap_functions.unarchive_mail", |
---|
| 937 | data: params, |
---|
| 938 | type: 'POST', |
---|
| 939 | async: false, |
---|
| 940 | success: function(data){ |
---|
| 941 | handler_unarchive(connector.unserialize(data)); |
---|
| 942 | }, |
---|
| 943 | }); |
---|
| 944 | |
---|
| 945 | |
---|
| 946 | |
---|
[7146] | 947 | } |
---|
| 948 | |
---|
| 949 | UnarchiveReqHandler.handler.open("GET", email, true); |
---|
| 950 | if(UnarchiveReqHandler.handler.overrideMimeType){ |
---|
| 951 | UnarchiveReqHandler.handler.overrideMimeType("message/rfc822; charset=windows-1252"); |
---|
| 952 | } |
---|
| 953 | |
---|
| 954 | UnarchiveReqHandler.handler.send(); |
---|
| 955 | } |
---|
| 956 | catch(e){ |
---|
| 957 | write_msg(get_lang('Unarchive error: ' + e)); |
---|
| 958 | } |
---|
| 959 | } |
---|
| 960 | |
---|
| 961 | /** |
---|
| 962 | * |
---|
| 963 | *Unarchieve Message Controller |
---|
| 964 | * |
---|
| 965 | *@author Cassiano Dal Pizzol [cassiano.dalpizzol@serpro.gov.br] |
---|
| 966 | * |
---|
| 967 | **/ |
---|
| 968 | MailArchiver.prototype.unarchieveController = function(data){ |
---|
| 969 | expresso_mail_archive.unarchivecounter++; |
---|
| 970 | |
---|
| 971 | if (data) |
---|
| 972 | { |
---|
[7227] | 973 | if (data.error != "") |
---|
[7146] | 974 | { |
---|
| 975 | expresso_mail_archive.unarchive_error_counter++; |
---|
| 976 | } |
---|
| 977 | |
---|
| 978 | if (data.archived && preferences.keep_archived_messages == "0") |
---|
| 979 | { |
---|
| 980 | // apaga |
---|
| 981 | expresso_mail_archive.deleteMessages(data.archived[0]); |
---|
| 982 | } |
---|
| 983 | |
---|
| 984 | } |
---|
| 985 | |
---|
| 986 | if (expresso_mail_archive.unarchivecounter < expresso_mail_archive.message_list.length){ |
---|
| 987 | expresso_mail_archive.unarchieveHandler(); |
---|
| 988 | } |
---|
| 989 | else |
---|
| 990 | { |
---|
| 991 | if (expresso_mail_archive.unarchive_error_counter == 0) |
---|
| 992 | { |
---|
| 993 | if (expresso_mail_archive.message_list.length==1){ |
---|
[7227] | 994 | write_msg(get_lang('Message successfully unarchived')); |
---|
[7146] | 995 | } |
---|
| 996 | else{ |
---|
[7227] | 997 | write_msg(get_lang('Messages successfully unarchived')); |
---|
[7146] | 998 | } |
---|
| 999 | } |
---|
| 1000 | else |
---|
[7227] | 1001 | { |
---|
| 1002 | if (expresso_mail_archive.message_list.length==1){ |
---|
| 1003 | write_msg(get_lang("Coudn't unarchive message")); |
---|
| 1004 | } |
---|
| 1005 | else if (expresso_mail_archive.unarchive_error_counter == expresso_mail_archive.message_list.length) |
---|
[7146] | 1006 | { |
---|
[7227] | 1007 | write_msg(get_lang('No messages were unarchived')); |
---|
[7146] | 1008 | } |
---|
[7227] | 1009 | else{ |
---|
| 1010 | write_msg(get_lang("Some messages weren't successfully unarchived")); |
---|
| 1011 | } |
---|
| 1012 | |
---|
| 1013 | } |
---|
[7146] | 1014 | //clear message list |
---|
| 1015 | expresso_mail_archive.message_list = new Array(); |
---|
[7449] | 1016 | expresso_mail_archive.isArchiveOperation = false; |
---|
[7146] | 1017 | } |
---|
| 1018 | } |
---|
| 1019 | |
---|
| 1020 | /** |
---|
| 1021 | *Archieve Delete Message |
---|
| 1022 | * |
---|
| 1023 | *@author Cassiano Dal Pizzol [cassiano.dalpizzol@serpro.gov.br] |
---|
| 1024 | * |
---|
| 1025 | *@param msgs_number Unique identification of the message |
---|
| 1026 | */ |
---|
| 1027 | MailArchiver.prototype.deleteMessages = function(msgs_number){ |
---|
| 1028 | try{ |
---|
| 1029 | // This is necessary 'couse we can get a delete operation while an unarchive operation |
---|
| 1030 | // is still executing |
---|
| 1031 | expresso_mail_archive._temp_list = expresso_mail_archive.message_list; |
---|
| 1032 | expresso_mail_archive.message_list = new Array(); |
---|
| 1033 | |
---|
| 1034 | expresso_mail_archive.CreateMessageList(msgs_number); |
---|
| 1035 | if((expresso_mail_archive.message_list.length > 0) && (expresso_mail_archive.message_list[0] != '')) { |
---|
| 1036 | ArchiveServices.deleteMessages(expresso_mail_archive.deleteMessagesOperationOK, |
---|
| 1037 | expresso_mail_archive.deleteMessagesOperationFailure, |
---|
| 1038 | expresso_mail_archive.session.id, |
---|
| 1039 | expresso_mail_archive.message_list); |
---|
| 1040 | } |
---|
| 1041 | else{ |
---|
| 1042 | write_msg(get_lang('No selected message.')); |
---|
| 1043 | } |
---|
| 1044 | } |
---|
| 1045 | catch (e){ |
---|
| 1046 | window.alert('Delete error: ' + e); |
---|
| 1047 | } |
---|
| 1048 | } |
---|
| 1049 | |
---|
| 1050 | /** |
---|
| 1051 | *Archieve Delete Message Ok |
---|
| 1052 | * |
---|
| 1053 | *@author Cassiano Dal Pizzol [cassiano.dalpizzol@serpro.gov.br] |
---|
| 1054 | * |
---|
| 1055 | */ |
---|
| 1056 | MailArchiver.prototype.deleteMessagesOperationOK = function(){ |
---|
| 1057 | /* var drawinginfo = {treeObject: tree_folders, treeName: 'tree_folders'}; |
---|
| 1058 | expresso_mail_archive.drawdata = drawinginfo; |
---|
| 1059 | expresso_mail_archive.drawFolderTree(); |
---|
| 1060 | expresso_mail_archive.listMessages(); |
---|
| 1061 | */ |
---|
| 1062 | connector.purgeCache(); |
---|
| 1063 | //ttreeBox.update_folder(true); |
---|
[7449] | 1064 | if(!expresso_mail_archive.isArchiveOperation){ |
---|
| 1065 | if(expresso_mail_archive.message_list.length > 1){ |
---|
| 1066 | write_msg(get_lang("The messages were deleted.")); |
---|
| 1067 | }else{ |
---|
| 1068 | write_msg(get_lang("The message was deleted.")); |
---|
| 1069 | } |
---|
| 1070 | } |
---|
[7146] | 1071 | expresso_mail_archive.update_counters = true; |
---|
| 1072 | expresso_mail_archive.messageslisted = new Array(); |
---|
[7224] | 1073 | expresso_mail_archive.message_list = new Array(); |
---|
[7195] | 1074 | |
---|
[8112] | 1075 | // tratado o caso do id da pasta vir com local_messages_ ou messages_ |
---|
| 1076 | var local_folder_id = folder; |
---|
| 1077 | if(local_folder_id){ |
---|
| 1078 | if(local_folder_id.substr(0,5) == 'local'){ |
---|
| 1079 | local_folder_id = local_folder_id.replace("local_messages_",""); |
---|
| 1080 | } else if(local_folder_id.substr(0,8) == 'messages'){ |
---|
| 1081 | local_folder_id = local_folder_id.replace("messages_",""); |
---|
| 1082 | } |
---|
| 1083 | } |
---|
[7224] | 1084 | |
---|
[8112] | 1085 | expresso_mail_archive.listMessages(local_folder_id); |
---|
[7224] | 1086 | |
---|
[7146] | 1087 | // This is necessary 'couse we can get a delete operation while an unarchive operation |
---|
| 1088 | // is still executing |
---|
| 1089 | expresso_mail_archive.message_list = expresso_mail_archive._temp_list; |
---|
| 1090 | expresso_mail_archive._temp_list = null; |
---|
| 1091 | } |
---|
| 1092 | |
---|
| 1093 | /** |
---|
| 1094 | *Archieve Delete Message Operation Failure |
---|
| 1095 | * |
---|
| 1096 | *@author Cassiano Dal Pizzol [cassiano.dalpizzol@serpro.gov.br] |
---|
| 1097 | * |
---|
| 1098 | */ |
---|
| 1099 | MailArchiver.prototype.deleteMessagesOperationFailure = function(error_message){ |
---|
| 1100 | if(expresso_mail_archive.message_list.length > 1){ |
---|
| 1101 | write_msg(get_lang("Error deleting messages.") + ' ' + error_message.getReturn()); |
---|
| 1102 | }else{ |
---|
| 1103 | write_msg(get_lang("Error deleting message.") + ' ' + error_message.getReturn()); |
---|
| 1104 | } |
---|
| 1105 | |
---|
| 1106 | // This is necessary 'couse we can get a delete operation while an unarchive operation |
---|
| 1107 | // is still executing |
---|
| 1108 | expresso_mail_archive.message_list = expresso_mail_archive._temp_list; |
---|
| 1109 | expresso_mail_archive._temp_list = null; |
---|
| 1110 | } |
---|
| 1111 | |
---|
| 1112 | /** |
---|
| 1113 | *Move message |
---|
| 1114 | * |
---|
| 1115 | *@param folder Folder where the message will be moved |
---|
| 1116 | *@param msgs_number Unique Id of the message |
---|
| 1117 | * |
---|
| 1118 | *@author Cassiano Dal Pizzol [cassiano.dalpizzol@serpro.gov.br] |
---|
| 1119 | * |
---|
| 1120 | */ |
---|
| 1121 | MailArchiver.prototype.moveMessages = function(folder, msgs_number){ |
---|
| 1122 | try{ |
---|
[7227] | 1123 | write_msg(get_lang("Starting to move messages")); |
---|
| 1124 | |
---|
[7146] | 1125 | expresso_mail_archive.CreateMessageList(msgs_number); |
---|
| 1126 | expresso_mail_archive.folder_destination = folder; |
---|
| 1127 | //window.alert('invocando o moveMessages com lista = ' + expresso_mail_archive.message_list.length + ' e folder destino =' + folder + '.\nFolder corrente ᅵ ' + expresso_mail_archive.currentfolder); |
---|
| 1128 | |
---|
| 1129 | if((expresso_mail_archive.message_list.length > 0) && (expresso_mail_archive.message_list[0] != '')) { |
---|
| 1130 | expresso_mail_archive.total_messages = expresso_mail_archive.message_list.length; |
---|
| 1131 | expresso_mail_archive.moveMessagesHandler(); |
---|
| 1132 | } |
---|
| 1133 | else{ |
---|
| 1134 | write_msg(get_lang('No selected message.')); |
---|
| 1135 | } |
---|
| 1136 | } |
---|
| 1137 | catch (e){ |
---|
| 1138 | expresso_mail_archive.getFaultInfo(); |
---|
| 1139 | } |
---|
| 1140 | } |
---|
| 1141 | |
---|
| 1142 | MailArchiver.prototype.moveMessagesHandler = function(){ |
---|
[7352] | 1143 | expresso_mail_archive.currentfolder = folder.substr(6, folder.length); |
---|
[7146] | 1144 | |
---|
| 1145 | if((expresso_mail_archive.message_list.length > 0) && (expresso_mail_archive.message_list[0] != '')) { |
---|
[7227] | 1146 | write_msg(get_lang('Moving message %1 of %2', expresso_mail_archive.messages_processed, expresso_mail_archive.total_messages)); |
---|
[7146] | 1147 | ArchiveServices.moveMessages(expresso_mail_archive.moveMessagesOperationOK, |
---|
| 1148 | expresso_mail_archive.moveMessagesOperationFailure, |
---|
| 1149 | expresso_mail_archive.session.id, |
---|
| 1150 | expresso_mail_archive.folder_destination, |
---|
| 1151 | new Array(expresso_mail_archive.message_list[parseInt(expresso_mail_archive.messages_processed)]) |
---|
| 1152 | ); |
---|
| 1153 | } |
---|
| 1154 | else{ |
---|
| 1155 | window.alert('Moving handler messagelist caught:\n ' + expresso_mail_archive.message_list.length); |
---|
| 1156 | } |
---|
| 1157 | } |
---|
| 1158 | |
---|
| 1159 | /** |
---|
| 1160 | *Move Message Ok |
---|
| 1161 | * |
---|
| 1162 | *@author Cassiano Dal Pizzol [cassiano.dalpizzol@serpro.gov.br] |
---|
| 1163 | * |
---|
| 1164 | */ |
---|
| 1165 | MailArchiver.prototype.moveMessagesOperationOK = function(){ |
---|
| 1166 | //archivement allready done, update controll data and interface |
---|
| 1167 | expresso_mail_archive.messages_processed++; |
---|
| 1168 | |
---|
| 1169 | if(parseInt(expresso_mail_archive.messages_processed) < parseInt(expresso_mail_archive.total_messages)){ |
---|
| 1170 | window.setTimeout(expresso_mail_archive.moveMessagesHandler,1); |
---|
| 1171 | } |
---|
| 1172 | else{ |
---|
[7227] | 1173 | write_msg(get_lang("All done. Message(s) moved successfully")); |
---|
[7146] | 1174 | |
---|
| 1175 | //Tag messages moved |
---|
| 1176 | for(var i=0; i<expresso_mail_archive.message_list.length; i++){ |
---|
| 1177 | var tlist = expresso_mail_archive.pattern.tagConfig(expresso_mail_archive.taglist, expresso_mail_archive.message_list[i], 0); |
---|
| 1178 | if(tlist != null){ |
---|
| 1179 | try{ |
---|
| 1180 | expresso_mail_archive.drawdata = null; |
---|
| 1181 | ArchiveServices.tagMessages(expresso_mail_archive.tagMessagesOperationOK, expresso_mail_archive.tagMessagesOperationFailure, expresso_mail_archive.session.id, tlist); |
---|
| 1182 | } |
---|
| 1183 | catch(e){ |
---|
| 1184 | expresso_mail_archive.getFaultInfo(); |
---|
| 1185 | } |
---|
| 1186 | } |
---|
| 1187 | } |
---|
| 1188 | |
---|
| 1189 | expresso_mail_archive.update_counters = true; |
---|
| 1190 | expresso_mail_archive.messageslisted = new Array(); |
---|
| 1191 | expresso_mail_archive.message_list = new Array(); |
---|
| 1192 | |
---|
[8112] | 1193 | // tratado o caso do id da pasta vir com local_messages_ ou messages_ |
---|
| 1194 | var local_folder_id = expresso_mail_archive.currentfolder; |
---|
| 1195 | if(local_folder_id){ |
---|
| 1196 | if(local_folder_id.substr(0,5) == 'local'){ |
---|
| 1197 | local_folder_id = local_folder_id.replace("local_messages_",""); |
---|
| 1198 | } else if(local_folder_id.substr(0,8) == 'messages'){ |
---|
| 1199 | local_folder_id = local_folder_id.replace("messages_",""); |
---|
| 1200 | } |
---|
| 1201 | } |
---|
| 1202 | |
---|
| 1203 | // tratado o caso do id da pasta vir com local_messages_ ou messages_ |
---|
| 1204 | var local_folder_id_destination = expresso_mail_archive.folder_destination; |
---|
| 1205 | if(local_folder_id_destination){ |
---|
| 1206 | if(local_folder_id_destination.substr(0,5) == 'local'){ |
---|
| 1207 | local_folder_id_destination = local_folder_id_destination.replace("local_messages_",""); |
---|
| 1208 | } else if(local_folder_id_destination.substr(0,8) == 'messages'){ |
---|
| 1209 | local_folder_id_destination = local_folder_id_destination.replace("messages_",""); |
---|
| 1210 | } |
---|
| 1211 | } |
---|
| 1212 | |
---|
| 1213 | expresso_mail_archive.getFolderInfo(local_folder_id); |
---|
| 1214 | expresso_mail_archive.getFolderInfo(local_folder_id_destination); |
---|
| 1215 | expresso_mail_archive.listMessages(local_folder_id); |
---|
[7146] | 1216 | |
---|
| 1217 | expresso_mail_archive.resetObject(); |
---|
| 1218 | } |
---|
| 1219 | } |
---|
| 1220 | |
---|
| 1221 | /** |
---|
| 1222 | *Move Message Failure |
---|
| 1223 | * |
---|
| 1224 | *@author Cassiano Dal Pizzol [cassiano.dalpizzol@serpro.gov.br] |
---|
| 1225 | * |
---|
| 1226 | */ |
---|
| 1227 | MailArchiver.prototype.moveMessagesOperationFailure = function(error_message){ |
---|
| 1228 | if(expresso_mail_archive.message_list.length > 1){ |
---|
| 1229 | write_msg(get_lang("Error moving messages.") + ' ' + error_message.getReturn()); |
---|
| 1230 | }else{ |
---|
| 1231 | write_msg(get_lang("Error moving message.") + ' ' + error_message.getReturn()); |
---|
| 1232 | } |
---|
| 1233 | } |
---|
| 1234 | |
---|
| 1235 | |
---|
| 1236 | //getFolderList Operation |
---|
| 1237 | MailArchiver.prototype.getFoldersList = function(basefolder){ |
---|
| 1238 | try{ |
---|
| 1239 | connector.showProgressBar(); |
---|
| 1240 | //window.alert('no expresso_mail_archive.getFoldersList com basefolder = ' + basefolder); |
---|
| 1241 | if(basefolder == 'local_root') |
---|
| 1242 | basefolder = ""; |
---|
| 1243 | //window.alert('folderlist com basefolder = ' + basefolder); |
---|
| 1244 | //ArchiveServices.listFolders(expresso_mail_archive.getFoldersListOperationOK, expresso_mail_archive.getFoldersListOperationFailure, sessid, basefolder); |
---|
| 1245 | ArchiveServices.listFolders(expresso_mail_archive.getFoldersListOperationOK, expresso_mail_archive.getFoldersListOperationFailure, expresso_mail_archive.session.id, basefolder); |
---|
| 1246 | |
---|
| 1247 | } |
---|
| 1248 | catch (e){ |
---|
| 1249 | expresso_mail_archive.getFaultInfo(); |
---|
| 1250 | } |
---|
| 1251 | } |
---|
| 1252 | |
---|
| 1253 | //getFolderList callback OK |
---|
| 1254 | MailArchiver.prototype.getFoldersListOperationOK = function(folderlist){ |
---|
| 1255 | //Internal variable used to map all XML data return from WS invokated |
---|
| 1256 | var lfolders = new Array(); |
---|
[7202] | 1257 | |
---|
[7146] | 1258 | |
---|
| 1259 | //Mapping XML data to a handler data structure |
---|
| 1260 | if(folderlist.getReturn().length > 0){ |
---|
| 1261 | var lfolders = new Array(); |
---|
| 1262 | for(i=0; i<folderlist.getReturn().length; i++){ |
---|
| 1263 | (folderlist.getReturn()[i].getFolderCount() > 0 ) ? folderChild = 1 : folderChild = 0; |
---|
| 1264 | |
---|
| 1265 | //Store folder data at this format: {folder name, number of messages contained, folder has child nodes, folder id, folder parent id, folder full path} |
---|
| 1266 | //var folderData = new Array(folderlist.getReturn()[i].getName(), folderlist.getReturn()[i].getMessageCount(), folderChild, folderlist.getReturn()[i].getId(), folderlist.getReturn()[i].getParentId(), folderlist.getReturn()[i].getPath()); |
---|
| 1267 | var folderData = {name: folderlist.getReturn()[i].getName(), messages: folderlist.getReturn()[i].getMessageCount(), haschild: folderChild, id: folderlist.getReturn()[i].getId(), parentid: folderlist.getReturn()[i].getParentId(), path: folderlist.getReturn()[i].getPath(), unseen: folderlist.getReturn()[i].getUnseenCount()}; |
---|
| 1268 | //window.alert('folder ' + folderData.name + ' tem ' + folderData.messages + ' mensagens, sendo ' + folderData.unseen + ' nï¿œo lidas'); |
---|
| 1269 | lfolders.push(folderData); |
---|
| 1270 | } |
---|
| 1271 | |
---|
| 1272 | //Sets folders property at main object |
---|
| 1273 | expresso_mail_archive.folders = lfolders; |
---|
| 1274 | |
---|
| 1275 | //Sets current folder, only if no one is setted |
---|
| 1276 | //if(expresso_mail_archive.currentfolder == null){ |
---|
| 1277 | if(expresso_mail_archive.folders[0]["parentid"] == "home"){ // change from "" to "home"(12/12/2011) |
---|
| 1278 | expresso_mail_archive.currentfolder = 'local_root'; |
---|
| 1279 | } |
---|
| 1280 | else |
---|
| 1281 | expresso_mail_archive.currentfolder = expresso_mail_archive.folders[0]["parentid"]; |
---|
| 1282 | //} |
---|
| 1283 | |
---|
| 1284 | |
---|
| 1285 | //Folders dumping :) |
---|
| 1286 | /*var strFolders = '---'; |
---|
| 1287 | for (var w=0; w < expresso_mail_archive.folders.length; w++){ |
---|
| 1288 | strFolders += '\nFolder ' + w + ' -->'; |
---|
| 1289 | for (x in expresso_mail_archive.folders[w]){ |
---|
| 1290 | strFolders += '\n----------' + x + ':= ' + expresso_mail_archive.folders[w][x]; |
---|
| 1291 | } |
---|
| 1292 | strFolders += '\n<---'; |
---|
| 1293 | } |
---|
| 1294 | strFolders += '\n---'; |
---|
| 1295 | alert(lfolders.length + ' folders mapeados, com default = ' + expresso_mail_archive.currentfolder + '\nfolders list:\n\n' + strFolders); |
---|
| 1296 | */ |
---|
| 1297 | //window.alert('foldersListOperationOK com drawdata:\n' + expresso_mail_archive.drawdata); |
---|
| 1298 | //If something UI related have been flagged, handle it |
---|
| 1299 | if (expresso_mail_archive.drawdata){ |
---|
| 1300 | //window.alert('com drawdata e treeName = ' + expresso_mail_archive.drawdata.treeName); |
---|
| 1301 | expresso_mail_archive.drawFolderTree(); |
---|
| 1302 | } |
---|
[7202] | 1303 | } else { |
---|
| 1304 | expresso_mail_archive.folders = 0; |
---|
[7146] | 1305 | } |
---|
| 1306 | connector.hideProgressBar(); |
---|
| 1307 | } |
---|
| 1308 | |
---|
| 1309 | //getFolderList callback Fail |
---|
| 1310 | MailArchiver.prototype.getFoldersListOperationFailure = function(error, http_msg){ |
---|
| 1311 | window.alert('List folders mistake:' + error + '\nhttp_error = ' + http_msg); |
---|
| 1312 | connector.hideProgressBar(); |
---|
| 1313 | } |
---|
| 1314 | |
---|
| 1315 | //drawFolderTree operation, if requested to |
---|
| 1316 | MailArchiver.prototype.drawFolderTree = function(){ |
---|
| 1317 | var localBaseName = 'local_'; |
---|
| 1318 | var objectTree = expresso_mail_archive.drawdata.treeObject; |
---|
| 1319 | var evalobjectTree = (typeof(expresso_mail_archive.drawdata.treeObject) == 'object') ? expresso_mail_archive.drawdata.treeObject: eval( '(' + expresso_mail_archive.drawdata.treeName + ')'); |
---|
| 1320 | |
---|
| 1321 | if((expresso_mail_archive.drawdata.treeName == 'search_folders') && (Element('dftree_search_folders'))) |
---|
| 1322 | evalobjectTree = folders_tree; |
---|
| 1323 | else{ |
---|
| 1324 | if((expresso_mail_archive.drawdata.treeName == 'folders_tree') && (Element('dftree_folders_tree'))) |
---|
| 1325 | evalobjectTree = folders_tree; |
---|
| 1326 | } |
---|
| 1327 | |
---|
| 1328 | //Add nodes to tree |
---|
| 1329 | if(typeof(evalobjectTree) == 'object'){ |
---|
| 1330 | //window.alert('caiu pra dentro, com ' + expresso_mail_archive.folders.length + ' folders.'); |
---|
| 1331 | evalobjectTree._drawn = true; |
---|
| 1332 | if(expresso_mail_archive.folders.length > 0){ |
---|
| 1333 | for(i=0; i<expresso_mail_archive.folders.length; i++){ |
---|
| 1334 | var folder_caption; |
---|
| 1335 | //window.alert('iterando nodo ' + expresso_mail_archive.folders[i]["name"]); |
---|
| 1336 | |
---|
| 1337 | //Special folders treatment: Inbox, Outbox, Drafts, Sent and Trash folders |
---|
| 1338 | if((expresso_mail_archive.folders[i]["name"] == 'Inbox') || (expresso_mail_archive.folders[i]["name"] == 'Outbox') || (expresso_mail_archive.folders[i]["name"] == 'Drafts') || (expresso_mail_archive.folders[i]["name"] == 'Sent') || (expresso_mail_archive.folders[i]["name"] == 'Trash')){ |
---|
| 1339 | folder_caption = get_lang(expresso_mail_archive.folders[i]["name"]); |
---|
| 1340 | } |
---|
| 1341 | else{ |
---|
| 1342 | folder_caption = expresso_mail_archive.folders[i]["name"]; |
---|
| 1343 | } |
---|
| 1344 | |
---|
| 1345 | var onClickVar = ''; |
---|
| 1346 | if((evalobjectTree.name != "folders_tree") && (evalobjectTree.name != "search_folders")){ |
---|
| 1347 | onClickVar = "change_folder('"+ localBaseName + expresso_mail_archive.folders[i]["id"] +"','"+ localBaseName + expresso_mail_archive.folders[i]["id"]+"', '" + expresso_mail_archive.drawdata.treeName + "')"; |
---|
| 1348 | if(expresso_mail_archive.folders[i]["unseen"] != "0") |
---|
| 1349 | folder_caption = folder_caption + '<font style=color:red> (</font><span id="dftree_local_'+expresso_mail_archive.folders[i]["id"]+'_unseen" style=color:red>'+expresso_mail_archive.folders[i]["unseen"]+'</span><font style=color:red>)</font>' |
---|
| 1350 | } |
---|
| 1351 | |
---|
| 1352 | var n_demo = new dNode({id: localBaseName + expresso_mail_archive.folders[i]["id"], caption: folder_caption, onClick: onClickVar, plusSign:expresso_mail_archive.folders[i]["haschild"]}); |
---|
| 1353 | //var n_demo = new dNode({id: localBaseName + expresso_mail_archive.folders[i]["name"], caption: folder_caption, onClick: "change_folder('"+ localBaseName + expresso_mail_archive.folders[i]["name"] +"','"+ localBaseName + expresso_mail_archive.folders[i]["name"]+"', '" + expresso_mail_archive.drawdata.treeName + "')", plusSign:expresso_mail_archive.folders[i]["haschild"]}); |
---|
| 1354 | |
---|
| 1355 | //Adjust the id node names |
---|
| 1356 | if(expresso_mail_archive.currentfolder){ |
---|
| 1357 | if(expresso_mail_archive.currentfolder.substr(0,5) != 'local'){ |
---|
| 1358 | evalobjectTree.add(n_demo, localBaseName + expresso_mail_archive.currentfolder); |
---|
| 1359 | } |
---|
| 1360 | else{ |
---|
| 1361 | evalobjectTree.add(n_demo,expresso_mail_archive.currentfolder); |
---|
| 1362 | } |
---|
| 1363 | } |
---|
| 1364 | else { |
---|
| 1365 | expresso_mail_archive.currentfolder = 'local_root'; |
---|
| 1366 | evalobjectTree.add(n_demo,expresso_mail_archive.currentfolder); |
---|
| 1367 | } |
---|
| 1368 | } |
---|
| 1369 | } |
---|
| 1370 | //Set special folders icons |
---|
| 1371 | if (document.getElementById('llocal_senttree_folders')){ |
---|
| 1372 | document.getElementById('llocal_senttree_folders').style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_sent.png)"; |
---|
| 1373 | } |
---|
| 1374 | if (document.getElementById('llocal_trashtree_folders')){ |
---|
| 1375 | document.getElementById('llocal_trashtree_folders').style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_trash.png)"; |
---|
| 1376 | } |
---|
| 1377 | if (document.getElementById('llocal_draftstree_folders')){ |
---|
| 1378 | document.getElementById('llocal_draftstree_folders').style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_draft.png)"; |
---|
| 1379 | } |
---|
| 1380 | if (document.getElementById('llocal_outboxtree_folders')){ |
---|
| 1381 | document.getElementById('llocal_outboxtree_folders').style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_sent.png)"; |
---|
| 1382 | } |
---|
| 1383 | } |
---|
| 1384 | else { |
---|
| 1385 | //does nothing |
---|
| 1386 | } |
---|
| 1387 | } |
---|
| 1388 | |
---|
| 1389 | //getFaultInfo operation |
---|
| 1390 | MailArchiver.prototype.getFaultInfo = function(){ |
---|
| 1391 | try{ |
---|
| 1392 | //ArchiveServices.getFaultInfo(expresso_mail_archive.getFaultInfoOperationOK, expresso_mail_archive.getFaultInfoOperationFailure, sessid); |
---|
| 1393 | ArchiveServices.getFaultInfo(expresso_mail_archive.getFaultInfoOperationOK, expresso_mail_archive.getFaultInfoOperationFailure, expresso_mail_archive.session.id); |
---|
| 1394 | connector.hideProgressBar(); |
---|
| 1395 | } |
---|
| 1396 | catch(e){ |
---|
[7270] | 1397 | if (!expresso_mail_archive.enabled) |
---|
[7146] | 1398 | write_msg(get_lang('MailArchiver does not seems to be running or installed at this workstation, local messages are disabled. Check it out!'),false); |
---|
| 1399 | else{ |
---|
| 1400 | window.clearInterval(expresso_mail_archive.timer); |
---|
[7270] | 1401 | write_msg(get_lang('There is something wrong with MailArchiver environment. Contact you support'), false); |
---|
[7146] | 1402 | expresso_mail_archive.enabled = false; |
---|
| 1403 | expresso_mail_archive.turnOffLocalTreeStructure(); |
---|
| 1404 | } |
---|
| 1405 | connector.hideProgressBar(); |
---|
| 1406 | } |
---|
| 1407 | } |
---|
| 1408 | |
---|
| 1409 | //getFaultInfo callback OK |
---|
| 1410 | MailArchiver.prototype.getFaultInfoOperationOK = function(faultinfo){ |
---|
| 1411 | try{ |
---|
[7270] | 1412 | write_msg(get_lang('MailArchiver remote service reports the following error:', false) + faultinfo.getReturn().getSoapFaultString()); |
---|
[7146] | 1413 | } catch(e){ |
---|
[7270] | 1414 | write_msg(get_lang('The archive service reports a unknown error. Try to refresh your browser screen', false)); |
---|
[7146] | 1415 | } |
---|
| 1416 | expresso_mail_archive.resetObject(); |
---|
| 1417 | expresso_mail_archive.archivefolder = null; |
---|
| 1418 | window.setTimeout("eval('document.getElementById(\"main_title\").innerHTML =\"Expresso Mail\"')",3000); |
---|
| 1419 | connector.purgeCache(); |
---|
[7270] | 1420 | expresso_mail_archive.turnOffLocalTreeStructure(); |
---|
[7146] | 1421 | } |
---|
| 1422 | |
---|
| 1423 | //getFaultInfo callback Fail |
---|
| 1424 | MailArchiver.prototype.getFaultInfoOperationFailure = function(errorCode, errorDesc){ |
---|
| 1425 | try{ |
---|
[7270] | 1426 | write_msg(get_lang('SoapFault capture fails at:' + errorCode + ' | ' + errorDesc, false)); |
---|
[7146] | 1427 | } catch(e){ |
---|
[7270] | 1428 | write_msg(get_lang('Service error mapping', false)); |
---|
[7146] | 1429 | } |
---|
| 1430 | } |
---|
| 1431 | |
---|
| 1432 | //createFolder operation |
---|
| 1433 | MailArchiver.prototype.createFolder = function(parentFolder, folderName){ |
---|
[7450] | 1434 | if(typeof(folderName) == "undefined"){ |
---|
| 1435 | return false; |
---|
| 1436 | } |
---|
[7146] | 1437 | |
---|
| 1438 | try{ |
---|
| 1439 | //ArchiveServices.createFolder(expresso_mail_archive.createFolderOperationOK, expresso_mail_archive.createFolderOperationFailure, sessid, parentFolder, folderName); |
---|
| 1440 | ArchiveServices.createFolder(expresso_mail_archive.createFolderOperationOK, expresso_mail_archive.createFolderOperationFailure, expresso_mail_archive.session.id, parentFolder, folderName); |
---|
| 1441 | } |
---|
| 1442 | catch (e){ |
---|
| 1443 | expresso_mail_archive.getFaultInfo(); |
---|
| 1444 | } |
---|
| 1445 | |
---|
| 1446 | } |
---|
| 1447 | |
---|
| 1448 | //createFolder callback OK |
---|
| 1449 | MailArchiver.prototype.createFolderOperationOK = function (folderObject){ |
---|
| 1450 | //window.alert('callback de createfolderoperationok'); |
---|
| 1451 | draw_tree_local_folders(); |
---|
[7270] | 1452 | //expresso_mail_archive.drawdata.treeObject._drawn = true; |
---|
[7202] | 1453 | //ttreeBox.update_folder(); |
---|
[7146] | 1454 | } |
---|
| 1455 | |
---|
| 1456 | //createFolder callback Fail |
---|
| 1457 | MailArchiver.prototype.createFolderOperationFailure = function (message){ |
---|
| 1458 | window.alert('Folder creation fails...\n->' + message.getReturn()); |
---|
| 1459 | } |
---|
| 1460 | |
---|
| 1461 | //deleteFolder operation |
---|
[7459] | 1462 | MailArchiver.prototype.deleteFolder = function(folderId, folderName){ |
---|
| 1463 | try{expresso_mail_archive.drawdata.folderName = folderName; |
---|
| 1464 | ArchiveServices.deleteFolder(expresso_mail_archive.deleteFolderOperationOK, expresso_mail_archive.deleteFolderOperationFailure, expresso_mail_archive.session.id, folderId, true); |
---|
[7146] | 1465 | } |
---|
| 1466 | catch (e){ |
---|
| 1467 | expresso_mail_archive.getFaultInfo(); |
---|
| 1468 | } |
---|
| 1469 | |
---|
| 1470 | } |
---|
| 1471 | |
---|
| 1472 | //deleteFolder callback OK |
---|
| 1473 | MailArchiver.prototype.deleteFolderOperationOK = function (folderObject){ |
---|
[7459] | 1474 | write_msg(get_lang("The local folder %1 was successfully removed", expresso_mail_archive.drawdata.folderName)); |
---|
[7146] | 1475 | connector.purgeCache(); |
---|
[7450] | 1476 | //ttreeBox.name_folder = "root"; |
---|
| 1477 | //ttreeBox.update_folder(); |
---|
[7146] | 1478 | draw_tree_local_folders(); |
---|
[7450] | 1479 | //ttreeBox.update_folder(); |
---|
[7146] | 1480 | } |
---|
| 1481 | |
---|
| 1482 | //deleteFolder callback Fail |
---|
| 1483 | MailArchiver.prototype.deleteFolderOperationFailure = function (message){ |
---|
| 1484 | expresso_mail_archive.getFaultInfo(); |
---|
| 1485 | } |
---|
| 1486 | |
---|
| 1487 | //renameFolder operation |
---|
| 1488 | MailArchiver.prototype.renameFolder = function(folderId, newFolderName){ |
---|
| 1489 | try{ |
---|
| 1490 | //ArchiveServices.renameFolder(expresso_mail_archive.renameFolderOperationOK, expresso_mail_archive.renameFolderOperationFailure, sessid, folderId, newFolderName); |
---|
| 1491 | ArchiveServices.renameFolder(expresso_mail_archive.renameFolderOperationOK, expresso_mail_archive.renameFolderOperationFailure, expresso_mail_archive.session.id, folderId, newFolderName); |
---|
| 1492 | } |
---|
| 1493 | catch (e){ |
---|
| 1494 | expresso_mail_archive.getFaultInfo(); |
---|
| 1495 | } |
---|
| 1496 | |
---|
| 1497 | } |
---|
| 1498 | |
---|
| 1499 | //renameFolder callback OK |
---|
| 1500 | MailArchiver.prototype.renameFolderOperationOK = function (returnService){ |
---|
| 1501 | var evalobjectTree = eval(expresso_mail_archive.drawdata.treeName); |
---|
| 1502 | evalobjectTree.update_folder(); |
---|
| 1503 | } |
---|
| 1504 | |
---|
| 1505 | //renameFolder callback Fail |
---|
| 1506 | MailArchiver.prototype.renameFolderOperationFailure = function (ServiceFault){ |
---|
| 1507 | expresso_mail_archive.getFaultInfo(); |
---|
| 1508 | } |
---|
| 1509 | |
---|
| 1510 | //getFolderInfo operation |
---|
| 1511 | MailArchiver.prototype.getFolderInfo = function (folderId){ |
---|
| 1512 | try{ |
---|
| 1513 | if(folderId == 'local_root') |
---|
| 1514 | folderId = ""; |
---|
| 1515 | ArchiveServices.getFolderInfo(expresso_mail_archive.getFolderInfoOperationOK, expresso_mail_archive.getFolderInfoOperationFailure, expresso_mail_archive.session.id, folderId); |
---|
| 1516 | } |
---|
| 1517 | catch (e){ |
---|
| 1518 | expresso_mail_archive.getFaultInfo(); |
---|
| 1519 | } |
---|
| 1520 | } |
---|
| 1521 | |
---|
| 1522 | //getFolderInfo callback OK |
---|
| 1523 | MailArchiver.prototype.getFolderInfoOperationOK = function(returnService){ |
---|
| 1524 | var folder_info = {id : returnService.getReturn().getId(), name : returnService.getReturn().getName(), parent : returnService.getReturn().getParentId(), numfolders: returnService.getReturn().getFolderCount(), nummessages: returnService.getReturn().getMessageCount(), unseen: returnService.getReturn().getUnseenCount(), path: returnService.getReturn().getPath()}; |
---|
| 1525 | expresso_mail_archive.folder = folder_info; |
---|
| 1526 | expresso_mail_archive.updateCounter(); |
---|
| 1527 | } |
---|
| 1528 | |
---|
| 1529 | //getFolderInfo callback Fail |
---|
| 1530 | MailArchiver.prototype.getFolderInfoOperationFailure = function (ServiceFault){ |
---|
| 1531 | window.alert('getFolderInfo service fails...\n->' + ServiceFault.getReturn()); |
---|
| 1532 | expresso_mail_archive.folder_data = true; |
---|
| 1533 | } |
---|
| 1534 | |
---|
| 1535 | function foo(){ |
---|
| 1536 | var a = 0; |
---|
| 1537 | a++; |
---|
| 1538 | } |
---|
| 1539 | |
---|
[7234] | 1540 | |
---|
| 1541 | /** |
---|
| 1542 | *delete All Messages |
---|
| 1543 | * |
---|
| 1544 | *@author Thiago Rossetto Afonso [thiago@prognus.com.br] |
---|
| 1545 | * |
---|
| 1546 | *@param folderId - folder id to get all messages that it has |
---|
| 1547 | */ |
---|
| 1548 | |
---|
| 1549 | MailArchiver.prototype.deleteAllMessages = function(folderId){ |
---|
| 1550 | try{ |
---|
[8112] | 1551 | |
---|
| 1552 | // tratado o caso do id da pasta vir com local_messages_ ou messages_ |
---|
| 1553 | var local_folder_id = folderid; |
---|
| 1554 | if(local_folder_id){ |
---|
| 1555 | if(local_folder_id.substr(0,5) == 'local'){ |
---|
| 1556 | local_folder_id = local_folder_id.replace("local_messages_",""); |
---|
| 1557 | } else if(local_folder_id.substr(0,8) == 'messages'){ |
---|
| 1558 | local_folder_id = local_folder_id.replace("messages_",""); |
---|
| 1559 | } |
---|
| 1560 | } |
---|
| 1561 | |
---|
[7234] | 1562 | var objfolder = new Object(); |
---|
[8112] | 1563 | objfolder.folder = local_folder_id; |
---|
[7234] | 1564 | |
---|
| 1565 | var query_data = expresso_mail_archive.queryconfig.query(objfolder); |
---|
| 1566 | |
---|
| 1567 | ArchiveServices.listMessages(expresso_mail_archive.deleteMsgsOperationOK, expresso_mail_archive.deleteMsgsOperationFailure, expresso_mail_archive.session.id, query_data); |
---|
| 1568 | }catch(e){ |
---|
| 1569 | expresso_mail_archive.getFaultInfo(); |
---|
| 1570 | } |
---|
| 1571 | } |
---|
| 1572 | MailArchiver.prototype.deleteMsgsOperationOK = function(returnService){ |
---|
| 1573 | var msgsArray = new Array(); |
---|
| 1574 | var msgs = ""; |
---|
| 1575 | for(var i=0; i< returnService.getReturn().length; i++){ |
---|
| 1576 | msgsArray.push(returnService.getReturn()[i]._id); |
---|
| 1577 | } |
---|
| 1578 | msgs = msgsArray.join(","); |
---|
| 1579 | |
---|
| 1580 | MailArchiver.prototype.deleteMessages(msgs); |
---|
| 1581 | } |
---|
| 1582 | MailArchiver.prototype.deleteMsgsOperationFailure = function(){ |
---|
| 1583 | alert("Your Messages weren't deleted."); |
---|
| 1584 | } |
---|
| 1585 | |
---|
[7146] | 1586 | //listMessages operation |
---|
| 1587 | //OLD local_messages.prototype.get_local_range_msgs = function(folder,msg_range_begin,emails_per_page,sort,sort_reverse,search,preview_msg_subject,preview_msg_tip) { |
---|
| 1588 | //ONLINE messages_proxy.prototype.messages_list = function(folder,msg_range_begin,emails_per_page,sort_box_type,search_box_type,sort_box_reverse,preview_msg_subject,preview_msg_tip,call_back,tree_name) { |
---|
| 1589 | //sys call = proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort,search,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box); |
---|
[7261] | 1590 | MailArchiver.prototype.listMessages = function(folderId){ |
---|
[7146] | 1591 | try{ |
---|
| 1592 | connector.showProgressBar(); |
---|
| 1593 | var getcurrent = get_current_folder(); |
---|
| 1594 | //tree_folders.getNodeById(get_current_folder())._select(); |
---|
[7261] | 1595 | var folderid; |
---|
| 1596 | if(typeof(folderId) != "undefined"){ |
---|
| 1597 | folderid = folderId; |
---|
| 1598 | } else { |
---|
| 1599 | folderid = this.currentfolder; |
---|
| 1600 | } |
---|
[8112] | 1601 | |
---|
| 1602 | // tratado o caso do id da pasta vir com local_messages_ ou messages_ |
---|
| 1603 | var local_folder_id = folderid; |
---|
| 1604 | if(local_folder_id){ |
---|
| 1605 | if(local_folder_id.substr(0,5) == 'local'){ |
---|
| 1606 | local_folder_id = local_folder_id.replace("local_messages_",""); |
---|
| 1607 | } else if(local_folder_id.substr(0,8) == 'messages'){ |
---|
| 1608 | local_folder_id = local_folder_id.replace("messages_",""); |
---|
| 1609 | } |
---|
| 1610 | } |
---|
| 1611 | |
---|
[7146] | 1612 | var objfolder = new Object(); |
---|
[8112] | 1613 | objfolder.folder = local_folder_id; |
---|
[7146] | 1614 | //var testing_data_xml = '<?xml version="1.0" encoding="UTF-8"?><query lowerIndex="0" upperIndex="50"><folder id="'+folderid+'"/><order asc="date"/><order desc="subject"/></query>'; |
---|
| 1615 | //var testing_data_json_mapped = '{"query":{"@lowerIndex":"0", "@upperIndex":"50", "folder":[{"@id":"'+folderid+'"}], "order":[{"@asc":"date", "@desc":"subject"}]}}'; |
---|
| 1616 | var query_data = expresso_mail_archive.queryconfig.query(objfolder); |
---|
[8112] | 1617 | |
---|
| 1618 | expresso_mail_archive.getFolderInfo(local_folder_id); |
---|
[7146] | 1619 | expresso_mail_archive.currentfolder = folderid; |
---|
| 1620 | |
---|
[7408] | 1621 | |
---|
[7146] | 1622 | //ArchiveServices.listMessages(expresso_mail_archive.listMessagesOperationOK, expresso_mail_archive.listMessagesOperationFailure, sessid, query_data); |
---|
| 1623 | ArchiveServices.listMessages(expresso_mail_archive.listMessagesOperationOK, expresso_mail_archive.listMessagesOperationFailure, expresso_mail_archive.session.id, query_data); |
---|
| 1624 | } |
---|
| 1625 | catch (e){ |
---|
| 1626 | expresso_mail_archive.getFaultInfo(); |
---|
| 1627 | } |
---|
| 1628 | } |
---|
| 1629 | |
---|
| 1630 | //listMessages callback OK |
---|
| 1631 | MailArchiver.prototype.listMessagesOperationOK = function(returnService){ |
---|
| 1632 | var msglist = new Array(); |
---|
| 1633 | expresso_mail_archive.ServiceReturnObjectList = new Array(); |
---|
| 1634 | //window.alert('messages data\n\n' + print_r(returnService.getReturn().length)); |
---|
| 1635 | /*window.alert('Dados da mensagem:\n->From ' + returnService.getReturn()[0].getFrom() |
---|
| 1636 | +'\n->To ' + returnService.getReturn()[0].getTo() |
---|
| 1637 | +'\n->Subject ' + returnService.getReturn()[0].getSubject() |
---|
| 1638 | +'\n->Date ' + returnService.getReturn()[0].getDate() |
---|
| 1639 | +'\n->Date ' + returnService.getReturn()[0].getSize() |
---|
| 1640 | +'\n->ID ' + returnService.getReturn()[0].getId()); |
---|
| 1641 | */ |
---|
| 1642 | for(var i=0; i< returnService.getReturn().length; i++){ |
---|
| 1643 | var ExpSerialized = expresso_mail_archive.pattern.toExpressoHeader(returnService.getReturn()[i]); |
---|
| 1644 | var msgitem = connector.unserialize(ExpSerialized); |
---|
[7608] | 1645 | |
---|
[7146] | 1646 | // correção para por no padrao certo, se nao fizer isso buga a listagem |
---|
[7608] | 1647 | msgitem.msg_sample = { "body": msgitem.msg_sample }; |
---|
| 1648 | |
---|
[7146] | 1649 | msglist.push(msgitem);//usando connector.unserialize sobre o header mapeado no layout abaixo |
---|
| 1650 | expresso_mail_archive.ServiceReturnObjectList.push(returnService.getReturn()[i]); //add each one service return data into this embeded object array |
---|
| 1651 | } |
---|
| 1652 | //msglist["num_msgs"] = returnService.getReturn().length; |
---|
| 1653 | //window.alert('service return length = ' + returnService.getReturn().length + '\nfolder.nummessages = ' + expresso_mail_archive.folder.nummessages); |
---|
| 1654 | |
---|
| 1655 | //window.alert('folder counters:\n' + print_r(tab_counters)); |
---|
| 1656 | |
---|
| 1657 | //msglist["num_msgs"] = expresso_mail_archive.folder.nummessages; |
---|
| 1658 | //window.alert('num msgs'); |
---|
| 1659 | //(expresso_mail_archive.folder.unseen) ? msglist["tot_unseen"] = expresso_mail_archive.folder.unseen : msglist["tot_unseen"] = 0; |
---|
| 1660 | // window.alert('num unseen'); |
---|
| 1661 | //window.alert('print_r\n\n' + print_r(msglist)); |
---|
| 1662 | |
---|
| 1663 | //expresso_mail_archive.updateCounter(returnService.getReturn().length, msg_unseen_count); |
---|
| 1664 | expresso_mail_archive.messageslisted = msglist; |
---|
| 1665 | expresso_mail_archive.drawdata = {messagesList:msglist}; |
---|
[7455] | 1666 | expresso_mail_archive.drawMessagesList(); |
---|
[7146] | 1667 | //expresso_mail_archive.drawMessagesList(returnService.getReturn().length, msg_unseen_count); |
---|
| 1668 | //expresso_mail_archive.drawMessagesList(msglist["num_msgs"], msg_unseen_count); |
---|
[7455] | 1669 | //expresso_mail_archive.drawMessagesList(expresso_mail_archive.tot_msgs_tab, expresso_mail_archive.tot_unseen_msgs_tab); |
---|
[7146] | 1670 | connector.hideProgressBar(); |
---|
| 1671 | } |
---|
| 1672 | |
---|
| 1673 | //listMessages callback Fail |
---|
| 1674 | MailArchiver.prototype.listMessagesOperationFailure = function(ServiceFault){ |
---|
| 1675 | window.alert('listmessages FALHOU!\n' + ServiceFault.getReturn()); |
---|
| 1676 | } |
---|
| 1677 | |
---|
[7907] | 1678 | |
---|
| 1679 | MailArchiver.prototype.getMessagesByFolder = function(folderid, searchType){ |
---|
| 1680 | try{ |
---|
| 1681 | if(searchType == "ALL") |
---|
| 1682 | var query_messages = '{"query":{"folder":[{"@id":"'+folderid+'"}], "order":[{"@asc":"date"}]}}'; |
---|
| 1683 | else |
---|
| 1684 | var query_messages = '{"query":{"folder":[{"@id":"'+folderid+'"}], "tags":[{"@contains":"'+searchType+'"}], "order":[{"@asc":"date"}]}}'; |
---|
| 1685 | ArchiveServices.listMessages(expresso_mail_archive.getMessagesByFolderOperationOK, expresso_mail_archive.getMessagesByFolderOperationFailure, expresso_mail_archive.session.id, query_messages); |
---|
| 1686 | } |
---|
| 1687 | catch (e){ |
---|
| 1688 | expresso_mail_archive.getFaultInfo(); |
---|
| 1689 | } |
---|
| 1690 | } |
---|
| 1691 | |
---|
| 1692 | MailArchiver.prototype.getMessagesByFolderOperationOK = function(returnService){ |
---|
| 1693 | var msglist = new Array(); |
---|
| 1694 | var msglistcomplete = new Array(); |
---|
| 1695 | var msgAll = new Array(); |
---|
| 1696 | for(var i=0; i< returnService.getReturn().length; i++){ |
---|
| 1697 | //Array montado apenas com ids para tratamento de seleção de mensagens independente de paginação |
---|
| 1698 | msglist.push(returnService.getReturn()[i]._id); |
---|
| 1699 | |
---|
| 1700 | msgAll.push(returnService.getReturn()[i]); |
---|
| 1701 | |
---|
| 1702 | //Incremento de contadores para atualização da aba de listagem |
---|
| 1703 | if(returnService.getReturn()[i]._tags.indexOf("unseen") != -1){ |
---|
| 1704 | expresso_mail_archive.tot_unseen_msgs_tab++; |
---|
| 1705 | } |
---|
| 1706 | expresso_mail_archive.tot_msgs_tab++; |
---|
| 1707 | //Array montado para operação de desarquivamento |
---|
| 1708 | var ExpSerialized = expresso_mail_archive.pattern.toExpressoHeader(returnService.getReturn()[i]); |
---|
| 1709 | msglistcomplete.push(connector.unserialize(ExpSerialized)); |
---|
| 1710 | } |
---|
| 1711 | expresso_mail_archive.allmessagesbyfolder = msglist; |
---|
| 1712 | expresso_mail_archive.allcompletemessagesbyfolder = msglistcomplete; |
---|
| 1713 | expresso_mail_archive.msgAll = msgAll; |
---|
| 1714 | } |
---|
| 1715 | |
---|
| 1716 | MailArchiver.prototype.getMessagesByFolderOperationFailure = function(ServiceFault){ |
---|
| 1717 | window.alert('listAllmessagesByFolder FALHOU!\n' + ServiceFault.getReturn()); |
---|
| 1718 | } |
---|
| 1719 | |
---|
| 1720 | |
---|
[7409] | 1721 | //List all messages by folder given and set a array with all messages ids |
---|
[7455] | 1722 | MailArchiver.prototype.listAllMessagesByFolder = function(folderid, searchType){ |
---|
[7409] | 1723 | try{ |
---|
[7455] | 1724 | if(searchType == "ALL") |
---|
| 1725 | var query_messages = '{"query":{"folder":[{"@id":"'+folderid+'"}], "order":[{"@asc":"date"}]}}'; |
---|
| 1726 | else |
---|
| 1727 | var query_messages = '{"query":{"folder":[{"@id":"'+folderid+'"}], "tags":[{"@contains":"'+searchType+'"}], "order":[{"@asc":"date"}]}}'; |
---|
[7409] | 1728 | ArchiveServices.listMessages(expresso_mail_archive.listAllMessagesByFolderOperationOK, expresso_mail_archive.listAllMessagesByFolderOperationFailure, expresso_mail_archive.session.id, query_messages); |
---|
| 1729 | } |
---|
| 1730 | catch (e){ |
---|
| 1731 | expresso_mail_archive.getFaultInfo(); |
---|
| 1732 | } |
---|
| 1733 | } |
---|
| 1734 | |
---|
[7411] | 1735 | //listAllMessagesByFolder callback OK |
---|
[7409] | 1736 | MailArchiver.prototype.listAllMessagesByFolderOperationOK = function(returnService){ |
---|
| 1737 | var msglist = new Array(); |
---|
[7468] | 1738 | var msglistcomplete = new Array(); |
---|
[7409] | 1739 | for(var i=0; i< returnService.getReturn().length; i++){ |
---|
[7468] | 1740 | //Array montado apenas com ids para tratamento de seleção de mensagens independente de paginação |
---|
[7409] | 1741 | msglist.push(returnService.getReturn()[i]._id); |
---|
[7468] | 1742 | //Incremento de contadores para atualização da aba de listagem |
---|
[7455] | 1743 | if(returnService.getReturn()[i]._tags.indexOf("unseen") != -1){ |
---|
| 1744 | expresso_mail_archive.tot_unseen_msgs_tab++; |
---|
| 1745 | } |
---|
| 1746 | expresso_mail_archive.tot_msgs_tab++; |
---|
[7468] | 1747 | //Array montado para operação de desarquivamento |
---|
| 1748 | var ExpSerialized = expresso_mail_archive.pattern.toExpressoHeader(returnService.getReturn()[i]); |
---|
| 1749 | msglistcomplete.push(connector.unserialize(ExpSerialized)); |
---|
[7409] | 1750 | } |
---|
| 1751 | expresso_mail_archive.allmessagesbyfolder = msglist; |
---|
[7468] | 1752 | expresso_mail_archive.allcompletemessagesbyfolder = msglistcomplete; |
---|
[7409] | 1753 | } |
---|
| 1754 | |
---|
[7411] | 1755 | //listAllMessagesByFolder callback Fail |
---|
[7409] | 1756 | MailArchiver.prototype.listAllMessagesByFolderOperationFailure = function(ServiceFault){ |
---|
| 1757 | window.alert('listAllmessagesByFolder FALHOU!\n' + ServiceFault.getReturn()); |
---|
| 1758 | } |
---|
| 1759 | |
---|
[7146] | 1760 | MailArchiver.prototype.getFolderMessagesNumber = function(){ |
---|
| 1761 | var n = 0; |
---|
| 1762 | for(var i=0; i < expresso_mail_archive.folders.length; i++){ |
---|
| 1763 | if(expresso_mail_archive.folders[i]["id"] == expresso_mail_archive.currentfolder){ |
---|
| 1764 | n = expresso_mail_archive.folders[i]["messages"]; |
---|
| 1765 | } |
---|
| 1766 | } |
---|
| 1767 | return(n); |
---|
| 1768 | } |
---|
| 1769 | |
---|
[7455] | 1770 | MailArchiver.prototype.drawMessagesList = function(){ |
---|
[7146] | 1771 | //window.alert('no drawMessagesList com folder = ' + expresso_mail_archive.currentfolder + '\nudatecounters = ' + expresso_mail_archive.udatecounters); |
---|
| 1772 | var data_to_draw = expresso_mail_archive.drawdata.messagesList; |
---|
| 1773 | //window.alert('data to draw = ' + data_to_draw.length + '\ndata_to_draw[0].from.full = ' + print_r(data_to_draw)); |
---|
| 1774 | //window.alert('Current folder = ' + expresso_mail_archive.currentfolder + ' com ' + expresso_mail_archive.folders.length + ' folders.'); |
---|
| 1775 | var fcaption = expresso_mail_archive.currentfolder; |
---|
| 1776 | |
---|
| 1777 | /*for (var w=0; w < expresso_mail_archive.folders.length; w++){ |
---|
| 1778 | //window.alert('comparando folder "' + expresso_mail_archive.folders[w]["id"] + '" com o corrente "' + expresso_mail_archive.currentfolder + '"\nEnquanto que o folder.name obtido do getfolderinfo é "' + expresso_mail_archive.folder.name + '"'); |
---|
| 1779 | if(expresso_mail_archive.folders[w]["id"] == expresso_mail_archive.currentfolder){ |
---|
| 1780 | fcaption = expresso_mail_archive.folders[w]["name"]; |
---|
| 1781 | window.alert('folder found!\n -> ' + fcaption); |
---|
| 1782 | break; |
---|
| 1783 | } |
---|
| 1784 | }*/ |
---|
| 1785 | |
---|
| 1786 | var fcaption = expresso_mail_archive.folder.name; |
---|
| 1787 | |
---|
| 1788 | /*window.alert('fcaption = ' + fcaption); |
---|
| 1789 | var udate_tree_folder = expresso_mail_archive.drawdata.treefolder; |
---|
| 1790 | window.alert('atualizar contador da ï¿œrvore : ' + udate_tree_folder); |
---|
| 1791 | var udate_tab_folder = expresso_mail_archive.drawdata.tabfolder; |
---|
| 1792 | window.alert('atualizar contador da tab : ' + udate_tab_folder);*/ |
---|
| 1793 | //var folder_num_msgs = expresso_mail_archive.getFolderMessagesNumber(); |
---|
| 1794 | var folder_num_msgs = expresso_mail_archive.folder.nummessages; |
---|
| 1795 | //window.alert('num = ' + folder_num_msgs); |
---|
[7172] | 1796 | |
---|
[7146] | 1797 | Element("border_id_0").innerHTML = " " + lang_folder(fcaption) + ' <font face="Verdana" size="1" color="#505050">[<span id="new_m"> </span> / <span id="tot_m"></span>]</font>'; |
---|
| 1798 | draw_box(data_to_draw, 'local_' + expresso_mail_archive.currentfolder, true); |
---|
| 1799 | //draw_paging(expresso_mail_archive.drawdata.messagesList.length); |
---|
| 1800 | //draw_paging(preferences.max_email_per_page); |
---|
[7455] | 1801 | draw_paging(expresso_mail_archive.tot_msgs_tab); |
---|
| 1802 | Element("tot_m").innerHTML = expresso_mail_archive.tot_msgs_tab; //folder_num_msgs; |
---|
| 1803 | Element('new_m').innerHTML = '<font color="RED">'+expresso_mail_archive.tot_unseen_msgs_tab+'</font>'; |
---|
[7146] | 1804 | } |
---|
| 1805 | |
---|
| 1806 | MailArchiver.prototype.getMessageHeaders = function(msgId){ |
---|
| 1807 | var msgfound = false; |
---|
| 1808 | var headerMsg; |
---|
| 1809 | |
---|
| 1810 | //Get message header info, from message list operation previously invoked |
---|
| 1811 | for (var w=0; w < expresso_mail_archive.messageslisted.length; w++){ |
---|
| 1812 | if(expresso_mail_archive.messageslisted[w]["msg_number"] == msgId){ |
---|
| 1813 | headerMsg = expresso_mail_archive.messageslisted[w]; |
---|
| 1814 | msgfound = true; |
---|
| 1815 | break; |
---|
| 1816 | } |
---|
| 1817 | } |
---|
| 1818 | |
---|
| 1819 | //Message does not exists at default message list previouslly invoked. Then, will be tryed to get it at possible search criteria existing tab. |
---|
| 1820 | if(!msgfound){ |
---|
| 1821 | //Try to discover if desired message is at a search local data tab |
---|
| 1822 | if(currentTab.toString().indexOf("search_local") != -1){ |
---|
| 1823 | var msgId2 = msgId.substr(0,msgId.indexOf("_s")); |
---|
| 1824 | for (var w=0; w < expresso_mail_archive.search_message_list.length; w++){ |
---|
| 1825 | if(expresso_mail_archive.search_message_list[w]["msg_number"] == msgId2){ |
---|
| 1826 | headerMsg = expresso_mail_archive.search_message_list[w]; |
---|
| 1827 | msgfound = true; |
---|
| 1828 | break; |
---|
| 1829 | } |
---|
| 1830 | } |
---|
| 1831 | |
---|
| 1832 | } |
---|
| 1833 | } |
---|
| 1834 | |
---|
| 1835 | //The message was found, as well the her headers |
---|
| 1836 | if(msgfound){ |
---|
| 1837 | expresso_mail_archive.currentheaders = headerMsg; |
---|
[7907] | 1838 | expresso_mail_archive.subjectPreview = headerMsg.subject; |
---|
[7146] | 1839 | return(headerMsg); |
---|
| 1840 | } |
---|
| 1841 | //The message was not found |
---|
| 1842 | else{ |
---|
| 1843 | headerMsg = null; |
---|
| 1844 | expresso_mail_archive.currentheaders = headerMsg; |
---|
| 1845 | return; |
---|
| 1846 | } |
---|
| 1847 | } |
---|
| 1848 | |
---|
[7529] | 1849 | MailArchiver.prototype.getMessageBodies = function(msgdata){ |
---|
| 1850 | try{ |
---|
| 1851 | var temp; |
---|
| 1852 | var bodies = Array(); |
---|
| 1853 | var callback = function(data){ |
---|
| 1854 | temp = data; |
---|
| 1855 | }; |
---|
| 1856 | for(var i=0; i<msgdata.length; i++){ |
---|
| 1857 | expresso_mail_archive.currentmessage = expresso_mail_archive.getMessageHeaders(msgdata[i])["msg_number"]; |
---|
| 1858 | ArchiveServices.getMessageBody(callback, expresso_mail_archive.getMessageOperationFailure,expresso_mail_archive.session.id, expresso_mail_archive.currentmessage); |
---|
| 1859 | bodies.push(temp); |
---|
| 1860 | } |
---|
[7907] | 1861 | expresso_mail_archive.bodyPreview = temp.getReturn(); |
---|
[7529] | 1862 | return bodies; |
---|
| 1863 | } |
---|
| 1864 | catch(e){ |
---|
| 1865 | expresso_mail_archive.getFaultInfo(); |
---|
| 1866 | } |
---|
| 1867 | } |
---|
[7340] | 1868 | |
---|
[7907] | 1869 | |
---|
| 1870 | MailArchiver.prototype.getPreviewToAttach = function(id){ |
---|
| 1871 | expresso_mail_archive.getMessageInfo(id); |
---|
| 1872 | expresso_mail_archive.getMessageBodies([id]); |
---|
| 1873 | } |
---|
| 1874 | |
---|
[7340] | 1875 | MailArchiver.prototype.getSomeMsgs = function(msgIds){ |
---|
| 1876 | try{ |
---|
| 1877 | expresso_mail_archive.getSomeMsg = new Array(); |
---|
| 1878 | for(var i=0; i < msgIds.length; i++){ |
---|
| 1879 | expresso_mail_archive.getSomeMsg.push(expresso_mail_archive.getMessageHeaders(msgIds[i])); |
---|
| 1880 | } |
---|
| 1881 | |
---|
| 1882 | }catch(e){ |
---|
[7608] | 1883 | alert("Erro ao obter mensagens"); |
---|
[7340] | 1884 | } |
---|
| 1885 | } |
---|
| 1886 | |
---|
[7623] | 1887 | |
---|
| 1888 | //** Esse metodo é responsavel da iteração com o ContextMenu pois o getMessageMenu está com um show_msg, wtf??? LOL!!! *// |
---|
| 1889 | MailArchiver.prototype.getMessageMenu = function(msgdata){ |
---|
| 1890 | try{ |
---|
| 1891 | if((msgdata.length <= 0) || (msgdata == null)){ |
---|
| 1892 | return; |
---|
| 1893 | } |
---|
| 1894 | expresso_mail_archive.currentmessage = expresso_mail_archive.getMessageHeaders(msgdata)["msg_number"]; |
---|
| 1895 | ArchiveServices.getMessageBody(expresso_mail_archive.getMessageMenuOperationOK, expresso_mail_archive.getMessageMenuOperationFailure, expresso_mail_archive.session.id, expresso_mail_archive.currentmessage); |
---|
| 1896 | } |
---|
| 1897 | catch(e){ |
---|
| 1898 | expresso_mail_archive.getFaultInfo(); |
---|
| 1899 | } |
---|
| 1900 | } |
---|
| 1901 | |
---|
| 1902 | MailArchiver.prototype.getMessageMenuOperationOK = function(returnService){ |
---|
| 1903 | if(returnService.getReturn().length <= 0){ |
---|
| 1904 | window.alert('Oh no: service return data is zero length...'); |
---|
| 1905 | return; |
---|
| 1906 | } |
---|
| 1907 | var msgBody = returnService.getReturn(); |
---|
| 1908 | //var msgHeaders = expresso_mail_archive.getMessageHeaders(expresso_mail_archive.currentmessage); |
---|
| 1909 | var msgHeaders = expresso_mail_archive.currentheaders; |
---|
| 1910 | var expSerializedMessage = expresso_mail_archive.pattern.toExpressoMail(msgHeaders, msgBody); |
---|
| 1911 | |
---|
| 1912 | // Unset \\Unseen flag |
---|
| 1913 | for (i=0; i < expresso_mail_archive.messageslisted.length; i++) |
---|
| 1914 | { |
---|
| 1915 | if (expresso_mail_archive.messageslisted[i].msg_number == expresso_mail_archive.currentmessage) |
---|
| 1916 | { |
---|
| 1917 | expresso_mail_archive.messageslisted[i]['Unseen'] = ''; |
---|
| 1918 | } |
---|
| 1919 | } |
---|
| 1920 | |
---|
| 1921 | //window.alert('Serialized data\n\n' + print_r(expSerializedMessage)); |
---|
| 1922 | //expresso_mail_archive.showEmbededImage(msgBody); |
---|
| 1923 | |
---|
| 1924 | expresso_mail_archive.fromMenu = expSerializedMessage; |
---|
| 1925 | } |
---|
| 1926 | MailArchiver.prototype.getMessageMenuOperationFailure = function(ServiceFault){ |
---|
| 1927 | window.alert('Message fails do be loaded.'); |
---|
| 1928 | } |
---|
| 1929 | |
---|
| 1930 | |
---|
[7146] | 1931 | MailArchiver.prototype.getMessage = function(msgdata){ |
---|
| 1932 | try{ |
---|
| 1933 | if((msgdata.length <= 0) || (msgdata == null)){ |
---|
| 1934 | return; |
---|
| 1935 | } |
---|
| 1936 | expresso_mail_archive.currentmessage = expresso_mail_archive.getMessageHeaders(msgdata)["msg_number"]; |
---|
| 1937 | ArchiveServices.getMessageBody(expresso_mail_archive.getMessageOperationOK, expresso_mail_archive.getMessageOperationFailure, expresso_mail_archive.session.id, expresso_mail_archive.currentmessage); |
---|
| 1938 | } |
---|
| 1939 | catch(e){ |
---|
| 1940 | expresso_mail_archive.getFaultInfo(); |
---|
| 1941 | } |
---|
| 1942 | } |
---|
| 1943 | |
---|
| 1944 | MailArchiver.prototype.getMessageOperationOK = function(returnService){ |
---|
| 1945 | if(returnService.getReturn().length <= 0){ |
---|
| 1946 | window.alert('Oh no: service return data is zero length...'); |
---|
| 1947 | return; |
---|
| 1948 | } |
---|
[7907] | 1949 | expresso_mail_archive.te = returnService.getReturn(); |
---|
[7146] | 1950 | var msgBody = returnService.getReturn(); |
---|
| 1951 | //var msgHeaders = expresso_mail_archive.getMessageHeaders(expresso_mail_archive.currentmessage); |
---|
| 1952 | var msgHeaders = expresso_mail_archive.currentheaders; |
---|
| 1953 | var expSerializedMessage = expresso_mail_archive.pattern.toExpressoMail(msgHeaders, msgBody); |
---|
| 1954 | |
---|
| 1955 | // Unset \\Unseen flag |
---|
| 1956 | for (i=0; i < expresso_mail_archive.messageslisted.length; i++) |
---|
| 1957 | { |
---|
| 1958 | if (expresso_mail_archive.messageslisted[i].msg_number == expresso_mail_archive.currentmessage) |
---|
| 1959 | { |
---|
| 1960 | expresso_mail_archive.messageslisted[i]['Unseen'] = ''; |
---|
| 1961 | } |
---|
| 1962 | } |
---|
| 1963 | |
---|
| 1964 | //window.alert('Serialized data\n\n' + print_r(expSerializedMessage)); |
---|
| 1965 | //expresso_mail_archive.showEmbededImage(msgBody); |
---|
[7623] | 1966 | |
---|
[7618] | 1967 | //É necessário fazer o encode com Base64 no destinatário para ser possivel enviar e-mail |
---|
[7685] | 1968 | if(expSerializedMessage.DispositionNotificationTo != null){ |
---|
| 1969 | expSerializedMessage.DispositionNotificationTo = Base64.encode(expSerializedMessage.DispositionNotificationTo); |
---|
| 1970 | } |
---|
[7627] | 1971 | |
---|
[7146] | 1972 | show_msg(expSerializedMessage); |
---|
| 1973 | window.setTimeout("expresso_mail_archive.setEmbeddedLink()", 1); |
---|
| 1974 | } |
---|
| 1975 | MailArchiver.prototype.getMessageOperationFailure = function(ServiceFault){ |
---|
| 1976 | window.alert('Message fails do be loaded.'); |
---|
| 1977 | } |
---|
| 1978 | |
---|
| 1979 | /* |
---|
| 1980 | *getMessageServiceObjet: search for a remote webservice object in memory to use |
---|
| 1981 | *draw interface. Look at messages list first, then, search list. Returns desired |
---|
| 1982 | *object, or null (if not found) |
---|
| 1983 | **/ |
---|
| 1984 | MailArchiver.prototype.getMessageServiceObject = function(msgid){ |
---|
| 1985 | var flag_found = false; |
---|
| 1986 | var rtn_obj = null; |
---|
| 1987 | |
---|
| 1988 | //Message list |
---|
| 1989 | if(expresso_mail_archive.ServiceReturnObjectList != null){ |
---|
| 1990 | for(var i=0; i < expresso_mail_archive.ServiceReturnObjectList.length; i++){ |
---|
| 1991 | if (expresso_mail_archive.ServiceReturnObjectList[i].getId() == msgid){ |
---|
| 1992 | flag_found = true; |
---|
| 1993 | rtn_obj = expresso_mail_archive.ServiceReturnObjectList[i]; |
---|
| 1994 | } |
---|
| 1995 | } |
---|
| 1996 | } |
---|
| 1997 | |
---|
| 1998 | //Search list |
---|
| 1999 | if(!flag_found){ |
---|
| 2000 | if(expresso_mail_archive.ServiceReturnObjectSearch != null){ |
---|
| 2001 | for(var i=0; i < expresso_mail_archive.ServiceReturnObjectSearch.length; i++){ |
---|
| 2002 | if (expresso_mail_archive.ServiceReturnObjectSearch[i].getId() == msgid){ |
---|
| 2003 | flag_found = true; |
---|
| 2004 | rtn_obj = expresso_mail_archive.ServiceReturnObjectSearch[i]; |
---|
| 2005 | } |
---|
| 2006 | } |
---|
| 2007 | } |
---|
| 2008 | } |
---|
| 2009 | return(rtn_obj); |
---|
| 2010 | } |
---|
| 2011 | |
---|
| 2012 | |
---|
| 2013 | MailArchiver.prototype.tagMessage = function(taglist){ |
---|
| 2014 | try{ |
---|
| 2015 | if(!taglist) |
---|
| 2016 | taglist = expresso_mail_archive.taglist; |
---|
| 2017 | //ArchiveServices.tagMessages(expresso_mail_archive.tagMessagesOperationOK, expresso_mail_archive.tagMessagesOperationFailure, sessid, taglist); |
---|
| 2018 | ArchiveServices.tagMessages(expresso_mail_archive.tagMessagesOperationOK, expresso_mail_archive.tagMessagesOperationFailure, expresso_mail_archive.session.id, taglist); |
---|
| 2019 | } catch (e){ |
---|
| 2020 | //window.alert('TagMessage fails at: ' + (e.description)?e.description:e); |
---|
| 2021 | expresso_mail_archive.getFaultInfo(); |
---|
| 2022 | } |
---|
| 2023 | } |
---|
| 2024 | |
---|
| 2025 | MailArchiver.prototype.tagMessagesOperationOK = function(serviceData){ |
---|
| 2026 | //ajustar os contadores de lida/nao lida etc... |
---|
| 2027 | if((expresso_mail_archive.currenttag != '') && (expresso_mail_archive.tagmsg == true)){ |
---|
| 2028 | write_msg(get_lang('Messages marked as "%1"', get_lang(expresso_mail_archive.currenttag))); |
---|
| 2029 | expresso_mail_archive.tagmsg = false; |
---|
| 2030 | } |
---|
| 2031 | |
---|
| 2032 | expresso_mail_archive.currenttag = ""; |
---|
| 2033 | expresso_mail_archive.taglist = ""; |
---|
| 2034 | |
---|
[7573] | 2035 | if((expresso_mail_archive.drawdata) && (get_current_folder() == expresso_mail_archive.folder_origin)){ |
---|
| 2036 | expresso_mail_archive.drawFolderTree(); |
---|
| 2037 | //expresso_mail_archive.drawdata = null; |
---|
| 2038 | window.clearTimeout(expresso_mail_archive.progressbar); |
---|
| 2039 | } |
---|
| 2040 | if(!expresso_mail_archive.isArchiveOperation){ |
---|
| 2041 | expresso_mail_archive.listMessages(); |
---|
| 2042 | } |
---|
[7146] | 2043 | } |
---|
| 2044 | |
---|
| 2045 | MailArchiver.prototype.tagMessagesOperationFailure = function(serviceData){ |
---|
| 2046 | var str_tag_fail = serviceData.getReturn(); |
---|
| 2047 | expresso_mail_archive.getFaultInfo(); |
---|
| 2048 | } |
---|
| 2049 | |
---|
| 2050 | MailArchiver.prototype.download_all_msg_attachments = function(msgid){ |
---|
| 2051 | var default_format = 'zip'; //tar, jar, gzip, bz2 supports too |
---|
| 2052 | var url = expresso_mail_archive.pattern.download_compressed_attachments(msgid, default_format); |
---|
| 2053 | //window.open(url,"mywindow","width=1,height=1,scrollbars=no"); |
---|
| 2054 | location.href = url; |
---|
| 2055 | } |
---|
| 2056 | |
---|
| 2057 | MailArchiver.prototype.download_msg_source = function (format){ |
---|
| 2058 | //Default export format is zip |
---|
| 2059 | if(!format) |
---|
| 2060 | format = 'zip'; |
---|
| 2061 | |
---|
| 2062 | expresso_mail_archive.exportformat = format; |
---|
| 2063 | |
---|
| 2064 | if (openTab.type[currentTab] > 1){ |
---|
| 2065 | var msgs_id = currentTab.substring(0,currentTab.length-2,currentTab); |
---|
| 2066 | }else{ |
---|
| 2067 | var msgs_id = get_selected_messages(); |
---|
| 2068 | } |
---|
| 2069 | |
---|
| 2070 | var vetmsg = msgs_id.split(","); |
---|
| 2071 | if(vetmsg.length > 0){ |
---|
| 2072 | var arr_msg = new Array(); |
---|
| 2073 | for(var k=0; k<vetmsg.length; k++){ |
---|
| 2074 | arr_msg.push(vetmsg[k]); |
---|
| 2075 | } |
---|
| 2076 | } |
---|
| 2077 | else var arr_msg = new Array(msgs_id); |
---|
| 2078 | |
---|
| 2079 | var messages_array = {"format": format, "type": 'messages', "messages": arr_msg}; |
---|
| 2080 | var texp = expresso_mail_archive.pattern.zipConfig(messages_array); |
---|
| 2081 | |
---|
| 2082 | if(texp != null){ |
---|
| 2083 | try{ |
---|
| 2084 | //ArchiveServices.zipMessages(expresso_mail_archive.download_mgs_sourceOperationOK, expresso_mail_archive.download_msg_sourceOperationFailure, sessid, texp); |
---|
| 2085 | ArchiveServices.zipMessages(expresso_mail_archive.download_mgs_sourceOperationOK, expresso_mail_archive.download_msg_sourceOperationFailure, expresso_mail_archive.session.id, texp); |
---|
| 2086 | } |
---|
| 2087 | catch(e){ |
---|
| 2088 | //window.alert('Export local messages fails: ' + (e.description)?e.description:e); |
---|
| 2089 | expresso_mail_archive.getFaultInfo(); |
---|
| 2090 | } |
---|
| 2091 | } |
---|
| 2092 | } |
---|
| 2093 | |
---|
| 2094 | MailArchiver.prototype.download_mgs_sourceOperationOK = function(serviceData){ |
---|
| 2095 | if(serviceData.getReturn().length > 0){ |
---|
| 2096 | window.location.href = mail_archive_protocol + "://" + mail_archive_host + ":" + mail_archive_port + "/temp/mails_" + serviceData.getReturn() + '.' + expresso_mail_archive.exportformat; |
---|
| 2097 | } |
---|
| 2098 | else{ |
---|
| 2099 | |
---|
| 2100 | } |
---|
| 2101 | } |
---|
| 2102 | |
---|
| 2103 | MailArchiver.prototype.download_mgs_sourceOperationFailure = function(serviceFail){ |
---|
| 2104 | window.alert('ZipMessages FAIL:' + serviceFail.getReturn()); |
---|
| 2105 | } |
---|
| 2106 | |
---|
| 2107 | MailArchiver.prototype.export_local_messages = function(folderid, recursive, format){ |
---|
| 2108 | //Default export format is zip |
---|
| 2109 | if(!format) |
---|
| 2110 | format = 'zip'; |
---|
| 2111 | |
---|
| 2112 | expresso_mail_archive.exportformat = format; |
---|
| 2113 | if(folderid == 'root')//export root local folder |
---|
| 2114 | var messages_array = {"format": format, "type": 'folder', "recursive" : true, "messages": ""}; |
---|
| 2115 | else//export local folder entry |
---|
| 2116 | var messages_array = {"format": format, "type": 'folder', "recursive" : recursive, "messages": folderid}; |
---|
| 2117 | var texp = expresso_mail_archive.pattern.zipConfig(messages_array); |
---|
| 2118 | |
---|
| 2119 | if(texp != null){ |
---|
| 2120 | try{ |
---|
| 2121 | ArchiveServices.zipMessages(expresso_mail_archive.download_mgs_sourceOperationOK, expresso_mail_archive.download_msg_sourceOperationFailure, expresso_mail_archive.session.id, texp); |
---|
| 2122 | } |
---|
| 2123 | catch(e){ |
---|
| 2124 | //window.alert('Export local messages fails: ' + (e.description)?e.description:e); |
---|
| 2125 | expresso_mail_archive.getFaultInfo(); |
---|
| 2126 | } |
---|
| 2127 | } |
---|
| 2128 | } |
---|
| 2129 | |
---|
| 2130 | MailArchiver.prototype.updateCounter = function(a,b){ |
---|
| 2131 | //window.alert('updateCounter reached'); |
---|
[7408] | 2132 | |
---|
[7146] | 2133 | if(((a) && (b)) || ((parseInt(a)==0)&&(parseInt(b)==0))){ |
---|
[7408] | 2134 | //Element("tot_m").innerHTML = a; |
---|
| 2135 | Element('new_m').innerHTML = (b >= 0) ? '<font color="RED">'+b+'</font>' : 0; |
---|
[7146] | 2136 | return; |
---|
| 2137 | } |
---|
| 2138 | |
---|
| 2139 | if(expresso_mail_archive.update_counters == true){ |
---|
| 2140 | connector.purgeCache(); |
---|
| 2141 | var elm_tree = Element('llocal_'+expresso_mail_archive.folder.id+'tree_folders'); |
---|
| 2142 | |
---|
| 2143 | if(elm_tree){ |
---|
| 2144 | |
---|
| 2145 | //search appropriate "unseen" span to handle with |
---|
| 2146 | for(var j=0; j<elm_tree.childNodes.length; j++){ |
---|
| 2147 | if (elm_tree.childNodes[j].nodeName.toLowerCase() == 'span'){ |
---|
| 2148 | var elm = elm_tree.childNodes[j]; |
---|
| 2149 | break; |
---|
| 2150 | } |
---|
| 2151 | } |
---|
| 2152 | |
---|
| 2153 | if(expresso_mail_archive.folder.unseen > 0){ |
---|
| 2154 | if (elm){ |
---|
| 2155 | elm.innerHTML = expresso_mail_archive.folder.unseen; |
---|
| 2156 | } |
---|
| 2157 | else{ |
---|
| 2158 | var htm_el = document.createElement('font'); |
---|
| 2159 | htm_el.style.color = 'red'; |
---|
| 2160 | document.getElementById('llocal_'+expresso_mail_archive.folder.id+'tree_folders').appendChild(htm_el); |
---|
| 2161 | htm_el.innerHTML = ' ('; |
---|
| 2162 | |
---|
| 2163 | var spn_el = document.createElement('span'); |
---|
| 2164 | spn_el.id = 'dftree_'+expresso_mail_archive.folder.id+'_unseen'; |
---|
| 2165 | spn_el.style.color = 'red'; |
---|
| 2166 | document.getElementById('llocal_'+expresso_mail_archive.folder.id+'tree_folders').appendChild(spn_el); |
---|
| 2167 | spn_el.innerHTML = expresso_mail_archive.folder.unseen; |
---|
| 2168 | |
---|
| 2169 | var htm2_el = document.createElement('font'); |
---|
| 2170 | htm2_el.style.color = 'red'; |
---|
| 2171 | document.getElementById('llocal_'+expresso_mail_archive.folder.id+'tree_folders').appendChild(htm2_el); |
---|
| 2172 | htm2_el.innerHTML = ')'; |
---|
| 2173 | } |
---|
| 2174 | } |
---|
| 2175 | else{ |
---|
| 2176 | if(elm){ |
---|
| 2177 | var spn = elm.parentNode.parentNode; |
---|
| 2178 | elm.parentNode.removeChild(elm.previousSibling); |
---|
| 2179 | elm.parentNode.removeChild(elm.nextSibling); |
---|
| 2180 | elm.parentNode.removeChild(elm); |
---|
| 2181 | } |
---|
| 2182 | } |
---|
| 2183 | |
---|
| 2184 | //reset pointer to re-do working to move messages (2 folders envolved) |
---|
| 2185 | if (expresso_mail_archive.folder_destination != null){ |
---|
| 2186 | if(expresso_mail_archive.currentfolder == expresso_mail_archive.folder_destination){ |
---|
| 2187 | expresso_mail_archive.update_counters = false; |
---|
| 2188 | } |
---|
| 2189 | else{ |
---|
| 2190 | //window.alert('aqui, queima o folder_destination'); |
---|
| 2191 | //expresso_mail_archive.folder_destination = null; |
---|
| 2192 | } |
---|
| 2193 | } |
---|
| 2194 | else{ |
---|
| 2195 | expresso_mail_archive.update_counters = false; |
---|
| 2196 | } |
---|
| 2197 | } |
---|
| 2198 | } |
---|
| 2199 | //no counter needs |
---|
| 2200 | else return; |
---|
| 2201 | } |
---|
| 2202 | |
---|
| 2203 | MailArchiver.prototype.getBase64PartData = function(partid, field){ |
---|
| 2204 | var spid = new String(partid); |
---|
| 2205 | if(parseInt(spid.length) > 0){ |
---|
| 2206 | expresso_mail_archive.tmp_att_datasource = field; |
---|
| 2207 | try{ |
---|
| 2208 | //ArchiveServices.getRawBinaryBody(expresso_mail_archive.getBase64PartDataOK, expresso_mail_archive.getBase64PartDataFailure, sessid, partid); |
---|
| 2209 | ArchiveServices.getRawBinaryBody(expresso_mail_archive.getBase64PartDataOK, expresso_mail_archive.getBase64PartDataFailure, expresso_mail_archive.session.id, partid); |
---|
| 2210 | } |
---|
| 2211 | catch(e){ |
---|
| 2212 | //window.alert('Fail to getRawBinaryBody data from part id ' + partid + ':\n' + (e.description)?e.description:e); |
---|
| 2213 | expresso_mail_archive.getFaultInfo(); |
---|
| 2214 | } |
---|
| 2215 | } |
---|
| 2216 | else { |
---|
| 2217 | return(null); |
---|
| 2218 | } |
---|
| 2219 | } |
---|
| 2220 | |
---|
| 2221 | MailArchiver.prototype.getBase64PartDataOK = function(serviceData){ |
---|
| 2222 | var encdata = serviceData.getReturn(); |
---|
| 2223 | if(encdata.length <= 0){ |
---|
| 2224 | window.alert('Oh no: service return data is zero length...'); |
---|
| 2225 | this.tmp_att_data = null; |
---|
| 2226 | } |
---|
| 2227 | else{ |
---|
| 2228 | expresso_mail_archive.tmp_att_datasource.value = encdata; |
---|
| 2229 | } |
---|
| 2230 | } |
---|
| 2231 | |
---|
| 2232 | MailArchiver.prototype.getBase64PartDataFailure = function(serviceReturn){ |
---|
| 2233 | window.alert('There are erros on getting binary data part:' + serviceReturn.getReturn()); |
---|
| 2234 | } |
---|
| 2235 | |
---|
| 2236 | MailArchiver.prototype.search = function(folders,fields){ |
---|
| 2237 | try{ |
---|
| 2238 | connector.showProgressBar(); |
---|
| 2239 | if((folders) && (fields)){ |
---|
| 2240 | expresso_mail_archive.search_queryconfig.reset(); |
---|
| 2241 | var folderlist = expresso_mail_archive.search_queryconfig.pharseFolders(folders); |
---|
| 2242 | var filters = eval('(' + expresso_mail_archive.queryconfig.pharseSearchFields(fields) + ')'); |
---|
| 2243 | |
---|
[7948] | 2244 | |
---|
| 2245 | |
---|
[7146] | 2246 | if(folderlist.indexOf("#") != -1) |
---|
| 2247 | filters.folder = folderlist.substr(0, folderlist.indexOf("#")); |
---|
| 2248 | else |
---|
| 2249 | filters.folder = folderlist; |
---|
| 2250 | if(folderlist.toLowerCase().indexOf("#recursive") != -1) |
---|
| 2251 | expresso_mail_archive.search_queryconfig.folder_recursive = true; |
---|
| 2252 | else |
---|
| 2253 | expresso_mail_archive.search_queryconfig.folder_recursive = false; |
---|
| 2254 | |
---|
| 2255 | expresso_mail_archive.querydata = expresso_mail_archive.search_queryconfig.query(filters); |
---|
[7948] | 2256 | |
---|
| 2257 | |
---|
| 2258 | |
---|
[7146] | 2259 | //var query_data = '<?xml version="1.0" encoding="UTF-8"?><query subject="teste"><folder id="inbox"/><order asc="date"/></query>'; |
---|
| 2260 | ArchiveServices.listMessages(expresso_mail_archive.searchOperationOK, expresso_mail_archive.searchOperationFailure, expresso_mail_archive.session.id, expresso_mail_archive.querydata); |
---|
| 2261 | } |
---|
| 2262 | //changing order view criteria (sorting result) |
---|
| 2263 | else{ |
---|
| 2264 | ArchiveServices.listMessages(expresso_mail_archive.searchOperationOK, expresso_mail_archive.searchOperationFailure, expresso_mail_archive.session.id, expresso_mail_archive.querydata); |
---|
| 2265 | } |
---|
| 2266 | }catch (e){ |
---|
| 2267 | expresso_mail_archive.getFaultInfo(); |
---|
| 2268 | } |
---|
| 2269 | } |
---|
| 2270 | |
---|
| 2271 | MailArchiver.prototype.searchOperationOK = function(returnService){ |
---|
| 2272 | if(returnService.getReturn().length > 0){ |
---|
| 2273 | var msglist = new Array(); |
---|
| 2274 | var msglist2 = new Array(); |
---|
| 2275 | expresso_mail_archive.ServiceReturnObjectSearch = new Array(); |
---|
| 2276 | |
---|
| 2277 | for(var i=0; i< returnService.getReturn().length; i++){ |
---|
| 2278 | var ExpSerialized = expresso_mail_archive.pattern.toExpressoSearchHeader(returnService.getReturn()[i]); |
---|
| 2279 | var ExpSerialized2 = expresso_mail_archive.pattern.toExpressoHeader(returnService.getReturn()[i]); |
---|
| 2280 | var msgitem = connector.unserialize(ExpSerialized); |
---|
| 2281 | var msgitem2 = connector.unserialize(ExpSerialized2); |
---|
| 2282 | |
---|
| 2283 | msglist.push(msgitem);//usando connector.unserialize sobre o header mapeado no layout abaixo |
---|
| 2284 | msglist2.push(msgitem2); |
---|
| 2285 | expresso_mail_archive.ServiceReturnObjectSearch.push(returnService.getReturn()[i]); //add each one service return data into this embeded object array |
---|
| 2286 | |
---|
| 2287 | } |
---|
| 2288 | msglist["num_msgs"] = returnService.getReturn().length; |
---|
| 2289 | msglist2["num_msgs"] = returnService.getReturn().length; |
---|
| 2290 | |
---|
| 2291 | //expresso_mail_archive.queryresult = msglist; |
---|
[7948] | 2292 | expresso_mail_archive.search_queryresult = msglist; |
---|
[7146] | 2293 | //expresso_mail_archive.messageslisted = msglist2; |
---|
| 2294 | expresso_mail_archive.search_message_list = msglist2; |
---|
| 2295 | //window.alert('temos ' + expresso_mail_archive.search_message_list.length + ' mensagens de resultado da pesquisa mapeadas em memï¿œria'); |
---|
| 2296 | } |
---|
[7353] | 2297 | else{ |
---|
| 2298 | expresso_mail_archive.ServiceReturnObjectSearch = null; |
---|
| 2299 | expresso_mail_archive.search_queryresult = null; |
---|
| 2300 | expresso_mail_archive.search_message_list = null; |
---|
| 2301 | expresso_mail_archive.messageslisted = null; |
---|
| 2302 | expresso_mail_archive.queryresult = null; |
---|
[7146] | 2303 | } |
---|
| 2304 | connector.hideProgressBar(); |
---|
| 2305 | } |
---|
| 2306 | |
---|
| 2307 | MailArchiver.prototype.searchOperationFailure = function(){ |
---|
| 2308 | write_msg(get_lang('MailArchiver search operation fails', true)); |
---|
[7353] | 2309 | expresso_mail_archive.ServiceReturnObjectSearch = null; |
---|
| 2310 | expresso_mail_archive.search_queryresult = null; |
---|
| 2311 | expresso_mail_archive.search_message_list = null; |
---|
| 2312 | expresso_mail_archive.messageslisted = null; |
---|
| 2313 | expresso_mail_archive.queryresult = null; |
---|
[7146] | 2314 | connector.hideProgressBar(); |
---|
| 2315 | } |
---|
| 2316 | |
---|
| 2317 | MailArchiver.prototype.getAuthId = function(){ |
---|
| 2318 | var handler_get_logon = function(data){ |
---|
| 2319 | if(data){ |
---|
| 2320 | expresso_mail_archive.balancerid = data[0]; |
---|
| 2321 | expresso_mail_archive.sessionid = data[1]; |
---|
| 2322 | expresso_mail_archive.logonid = new Array(data[2],data[3]); |
---|
| 2323 | expresso_mail_archive.login(); |
---|
| 2324 | } |
---|
| 2325 | else{ |
---|
| 2326 | window.alert('Login credentials call failure'); |
---|
| 2327 | expresso_mail_archive.session = null; |
---|
| 2328 | } |
---|
| 2329 | } |
---|
| 2330 | cExecute("$this.user.get_mailarchiver_authid",handler_get_logon); |
---|
| 2331 | } |
---|
| 2332 | |
---|
| 2333 | MailArchiver.prototype.login = function(){ |
---|
| 2334 | try{ |
---|
| 2335 | ArchiveServices.login(expresso_mail_archive.loginOperationOK, expresso_mail_archive.loginOperationFailure, expresso_mail_archive.logonid[0], expresso_mail_archive.logonid[1], expresso_mail_archive.sessionid, expresso_mail_archive.balancerid); |
---|
| 2336 | } |
---|
| 2337 | catch(e){ |
---|
| 2338 | expresso_mail_archive.getFaultInfo(); |
---|
| 2339 | } |
---|
| 2340 | } |
---|
| 2341 | |
---|
| 2342 | MailArchiver.prototype.loginOperationOK = function(returnService){ |
---|
| 2343 | if((typeof(returnService.getReturn()) == 'object') && (returnService.getReturn() != null)){ |
---|
| 2344 | expresso_mail_archive.session = new Object(); |
---|
| 2345 | expresso_mail_archive.session.expiration = returnService.getReturn().getExpiration(); |
---|
| 2346 | expresso_mail_archive.session.id = returnService.getReturn().getId(); |
---|
| 2347 | expresso_mail_archive.session.permissions = returnService.getReturn().getPermissions(); |
---|
| 2348 | expresso_mail_archive.CreateDefaultStructrure(); |
---|
| 2349 | } |
---|
| 2350 | else{ |
---|
| 2351 | //not logged in MailArchiver |
---|
| 2352 | expresso_mail_archive.session = null; |
---|
| 2353 | write_msg(get_lang('MailArchiver user login fail', true)); |
---|
| 2354 | expresso_mail_archive.enabled = false; |
---|
| 2355 | expresso_mail_archive.timer=null; |
---|
| 2356 | expresso_mail_archive.interval = 500; |
---|
| 2357 | ArchiveServices = null; |
---|
| 2358 | connector.purgeCache(); |
---|
| 2359 | draw_tree_folders(); |
---|
| 2360 | //expresso_mail_archive.DeactivateStatusListener(expresso_mail_archive); |
---|
| 2361 | } |
---|
| 2362 | } |
---|
| 2363 | |
---|
| 2364 | MailArchiver.prototype.getFolderCounters = function(){ |
---|
| 2365 | var vetreturn = new Array(); |
---|
| 2366 | /*for(var k=0; k<expresso_mail_archive.folders.length; k++){ |
---|
| 2367 | if(expresso_mail_archive.folders[k]["id"] == expresso_mail_archive.currentfolder){ |
---|
| 2368 | vetreturn.push(expresso_mail_archive.folders[k]["messages"], expresso_mail_archive.folders[k]["unseen"]); |
---|
| 2369 | break; |
---|
| 2370 | } |
---|
| 2371 | }*/ |
---|
| 2372 | vetreturn.push(expresso_mail_archive.folder.nummessages, expresso_mail_archive.folder.unseen); |
---|
| 2373 | return(vetreturn); |
---|
| 2374 | } |
---|
| 2375 | |
---|
| 2376 | MailArchiver.prototype.setEmbeddedLink = function(){ |
---|
| 2377 | var img_objects = document.getElementsByTagName('img'); |
---|
| 2378 | for(var k = 0; k < img_objects.length; k++){ |
---|
| 2379 | if(img_objects[k].name.indexOf('embedded_img_') != -1) { |
---|
| 2380 | var obj_link = img_objects[k].name.split('embedded_img_'); |
---|
| 2381 | var txt_link = obj_link[1]; |
---|
| 2382 | var img_base_link = mail_archive_protocol + "://" + mail_archive_host + ":" + mail_archive_port + "/temp/" + txt_link; |
---|
| 2383 | img_objects[k].src = img_base_link; |
---|
| 2384 | } |
---|
| 2385 | } |
---|
| 2386 | } |
---|
| 2387 | /* |
---|
| 2388 | MailArchiver.prototype.getFolderPath = function(folder){ |
---|
| 2389 | try{ |
---|
| 2390 | ArchiveServices.getFolderInfo(expresso_mail_archive.getFolderPathOperationOK, expresso_mail_archive.getFolderPathOperationFailure, expresso_mail_archive.session.id, folder); |
---|
| 2391 | } |
---|
| 2392 | catch(e){ |
---|
| 2393 | window.alert('getFolderPath fails'); |
---|
| 2394 | } |
---|
| 2395 | } |
---|
| 2396 | |
---|
| 2397 | MailArchiver.prototype.getFolderPathOperationOK = function(serviceReturn){ |
---|
| 2398 | window.alert('service return from getFolderPathOperationOK = ' + serviceReturn().getFolderPath()); |
---|
| 2399 | if(serviceReturn().length>0){ |
---|
| 2400 | window.alert('ok'); |
---|
| 2401 | } |
---|
| 2402 | else{ |
---|
| 2403 | window.alert('nope'); |
---|
| 2404 | } |
---|
| 2405 | } |
---|
| 2406 | |
---|
| 2407 | MailArchiver.prototype.getFolderPathOperationFailure = function(serviceFault){ |
---|
| 2408 | window.alert('fails at gettting folder path'); |
---|
| 2409 | } |
---|
| 2410 | */ |
---|
| 2411 | |
---|
| 2412 | MailArchiver.prototype.getMessageInfo = function(msgId){ |
---|
| 2413 | try{ |
---|
| 2414 | ArchiveServices.getMessageInfo(expresso_mail_archive.getMessageInfoOperationOK, expresso_mail_archive.getMessageInfoOperationFailure, expresso_mail_archive.session.id, msgId); |
---|
| 2415 | } |
---|
| 2416 | catch(e){ |
---|
| 2417 | window.alert('getMessageInfo fails'); |
---|
| 2418 | } |
---|
| 2419 | } |
---|
| 2420 | |
---|
| 2421 | MailArchiver.prototype.getMessageInfoOperationOK = function(serviceReturn){ |
---|
| 2422 | //window.alert('service return from getMessageInfoOperationOK = ' + serviceReturn.getReturn() + '\n' + typeof(serviceReturn.getReturn()) + '\n' + print_r(serviceReturn.getReturn())); |
---|
| 2423 | if(typeof(serviceReturn.getReturn() == 'object')){ |
---|
| 2424 | var ExpSerialized2 = expresso_mail_archive.pattern.toExpressoHeader(serviceReturn.getReturn()); |
---|
| 2425 | var msgitem2 = connector.unserialize(ExpSerialized2); |
---|
[7948] | 2426 | if(!expresso_mail_archive.messageslisted){ |
---|
| 2427 | expresso_mail_archive.messageslisted = []; |
---|
| 2428 | } |
---|
[7146] | 2429 | expresso_mail_archive.messageslisted.push(msgitem2); |
---|
| 2430 | expresso_mail_archive.getMessageHeaders(serviceReturn.getReturn().getId()); |
---|
[7907] | 2431 | |
---|
[7146] | 2432 | } |
---|
| 2433 | else{ |
---|
| 2434 | window.alert('getMessageInfoOperationOK nope'); |
---|
| 2435 | } |
---|
| 2436 | } |
---|
| 2437 | |
---|
| 2438 | MailArchiver.prototype.turnOffLocalTreeStructure = function (){ |
---|
[7270] | 2439 | draw_new_tree_folder(); |
---|
[7146] | 2440 | } |
---|
| 2441 | |
---|
| 2442 | MailArchiver.prototype.getMessageInfoOperationFailure = function(serviceFault){ |
---|
| 2443 | window.alert('fails at gettting message info'); |
---|
| 2444 | } |
---|
| 2445 | |
---|
| 2446 | MailArchiver.prototype.loginOperationFailure = function(ServiceFaillure){ |
---|
| 2447 | write_msg(get_lang('MailArchiver login operation fail', true)); |
---|
| 2448 | } |
---|
| 2449 | |
---|
| 2450 | MailArchiver.prototype.logout = function(){ |
---|
| 2451 | write_msg(get_lang('MailArchiver user logged out', true)); |
---|
| 2452 | } |
---|
| 2453 | /* |
---|
| 2454 | *The all pourpose JavaScript variable, used by all related functionalityes at |
---|
| 2455 | *Expresso Mail to handle this object at user gui. |
---|
| 2456 | */ |
---|
| 2457 | |
---|
| 2458 | var expresso_mail_archive; |
---|
| 2459 | expresso_mail_archive = new MailArchiver(); |
---|
[7248] | 2460 | --> |
---|