]+)>[^,]*/g,"$1$2");
50 |
51 | return mailAddrs;
52 | }
53 |
54 | function isValidFilePath(sSurbPath)
55 | {
56 | // TODO: Use system char for path separator
57 | var iIndex = sSurbPath.indexOf('/');
58 | // checking whether the path begins with file system root.
59 | if(iIndex == 0){
60 | return true;
61 | }
62 | else{
63 | return false;
64 | }
65 | }
66 |
67 | /*
68 | Returns the plaintex from "node" if "findStr" has
69 | been found in "node". Empty otherwise.
70 | It has been taken from Enigmail.
71 | */
72 | function getDeepText(node, findStr) {
73 |
74 | if (findStr) {
75 | if (node.innerHTML.replace(/ /g, " ").indexOf(findStr) < 0) {
76 | // exit immediately if findStr is not found at all
77 | return "";
78 | }
79 | }
80 |
81 | // EnigDumpHTML(node);
82 |
83 | var plainText = MixParseChildNodes(node);
84 | // Replace non-breaking spaces with plain spaces
85 | plainText = plainText.replace(/\xA0/g," ");
86 |
87 | if (findStr) {
88 | if (plainText.indexOf(findStr) < 0) {
89 | return "";
90 | }
91 | }
92 | return plainText;
93 | }
94 |
95 | /*
96 | Returns: an array of type III reply blocks.
97 | */
98 | function extractReplyBlock( sInputText){
99 | //var sExtracted = extractText(sInputText, "^-----BEGIN TYPE III REPLY BLOCK-----", "^-----END TYPE III REPLY BLOCK-----");
100 | var sExtracted = mixExtractText(sInputText, "-----BEGIN TYPE III REPLY BLOCK-----", "-----END TYPE III REPLY BLOCK-----");
101 |
102 | return sExtracted;
103 |
104 | }
105 |
106 | /*
107 | Tests whether the input string contains anonymous crypted messages.
108 | */
109 | function isAnonCryptMessage( sInputText){
110 | var sAnonText = extractAnonMessage( sInputText);
111 | var sCryptPattern = new RegExp("Message-type: encrypted\nDecoding-handle:");
112 |
113 | return sCryptPattern.test(sAnonText);
114 | }
115 |
116 | /*
117 | Tests whether the input string contains a surb.
118 | */
119 | function containsSurb( sInputText){
120 | var sAnonText = extractReplyBlock( sInputText);
121 | var sBeginPattern = new RegExp("-----BEGIN TYPE III REPLY BLOCK-----");
122 | var sEndPattern = new RegExp("-----END TYPE III REPLY BLOCK-----");
123 |
124 | return sBeginPattern.test(sAnonText) && sEndPattern.test(sAnonText);
125 | }
126 |
127 | /*
128 | Extracts a type III anonymous messages.
129 | Returns: an array of type III anonymous messages.
130 | */
131 | function extractAnonMessage( sInputText){
132 | var sExtracted = mixExtractText(sInputText, "-----BEGIN TYPE III ANONYMOUS MESSAGE-----", "-----END TYPE III ANONYMOUS MESSAGE-----");
133 |
134 | return sExtracted;
135 |
136 | }
137 |
138 | /*
139 | Returns an array of strings, containing all the occurrences of text found in
140 | sInputText starting from sBegin until sEnd included(if not found until the end
141 | of the input).
142 | Inspired by pemar.
143 | */
144 | function extractText(sInputText, sBegin, sEnd) {
145 | // array of reply blocks.
146 | var asReturn = [];
147 | var iSurbCounter = 0;
148 | var textRows = sInputText.split("\n");
149 | var myreplyblock="";
150 | var collect=false;
151 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
152 | // TODO: these do not work, check it.
153 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
154 | // var myRegStart = new RegExp(sBegin);
155 | // var myRegEnd = new RegExp(sEnd);
156 | for (var count=0; count < textRows.length; count++)
157 | {
158 | if (textRows[count].match("/"+sBegin+"/")) {
159 | collect=true;
160 | }
161 | if (collect)
162 | {
163 | myreplyblock +=textRows[count] + "\n";
164 | }
165 | if (textRows[count].match("/"+sEnd+"/")) {
166 | collect=false;
167 | // Storing the parsed reply block.
168 | asReturn[iSurbCounter++] = myreplyblock;
169 | }
170 | }
171 | return asReturn;
172 | }
173 |
174 | /*
175 | Returns an array of strings, containing all the occurrences of text found in
176 | sInputText starting from sBegin until sEnd included(if not found until the end
177 | of the input).
178 | Inspired by pemar.
179 | */
180 | function mixExtractText(sInputText, sBegin, sEnd) {
181 | // array of reply blocks.
182 | var asReturn = [];
183 | var iSurbCounter = 0;
184 | var textRows = sInputText.split("\n");
185 | var myreplyblock="";
186 | var collect=false;
187 | var myRegStart = new RegExp(sBegin);
188 | var myRegEnd = new RegExp(sEnd);
189 | for (var count=0; count < textRows.length; count++)
190 | {
191 | if (myRegStart.test(textRows[count])) {
192 | collect=true;
193 | }
194 | if (collect)
195 | {
196 | myreplyblock +=textRows[count] + "\n";
197 | }
198 | if (myRegEnd.test(textRows[count])) {
199 | collect=false;
200 | // Storing the parsed reply block.
201 | asReturn[iSurbCounter++] = myreplyblock;
202 | }
203 | }
204 | return asReturn;
205 | }
206 |
207 | /*
208 | Returns the current profile email.
209 | */
210 | function getCurrProfileEmail(){
211 |
212 | var identityElement = document.getElementById("msgIdentity");
213 |
214 | var gAccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
215 | if (identityElement) {
216 | var idKey = identityElement.value;
217 | var gCurrentIdentity = gAccountManager.getIdentity(idKey);
218 | return gCurrentIdentity.email;
219 | }
220 | return "";
221 | }
222 |
223 | /*
224 | Returns an array with the email (as a string) of each known profile.
225 | */
226 | function getAllProfilesEmail(){
227 |
228 | var gAccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
229 | var asEmails = [];
230 | var aoIds = gAccountManager.allIdentities;
231 | var iIdsCounter = aoIds.Count();
232 | for(var iIdNr = 0; iIdNr< iIdsCounter; iIdNr++){
233 | var oCurrId = aoIds.QueryElementAt(iIdNr, Components.interfaces.nsIMsgIdentity);
234 | asEmails[iIdNr] = oCurrId.email;
235 | }
236 |
237 | return asEmails;
238 | }
239 |
240 | /*
241 | Checks whether sPath is a actual file path and whether
242 | it leads to an actual file.
243 |
244 | sPath: the path to be checked.
245 |
246 | returns: true if the path leads to an existing file, false otherwise.
247 | */
248 | function pathExists(sPath){
249 | try{
250 | var oTmpFile = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
251 | oTmpFile.initWithPath(sPath);
252 | if(oTmpFile.exists()){
253 | return true;
254 | }
255 | else{
256 | return false;
257 | }
258 | }catch(oEx){
259 | return false;
260 | }
261 | }
262 |
263 | function showPrefs()
264 | {
265 | var oReturn = {in: null, out:null};
266 | var oPrefs = window.openDialog("chrome://gui/content/mixPreferences.xul", "Mixminion Preferences",
267 | "modal, toolbar,location=yes, menubar=no,top=100, left=100px,width=100cm",oReturn);
268 | return oReturn.out.bValue;
269 | }
270 |
271 | function getLogFile(){
272 |
273 | var directoryService = Components.classes["@mozilla.org/file/directory_service;1"]
274 | .getService(Components.interfaces.nsIProperties);
275 | var oLogFile = directoryService.get("ProfD", Components.interfaces.nsIFile);
276 | oLogFile.append(gLogFileName);
277 |
278 | if (!oLogFile.exists()){
279 | // if log file does not exist, create one.
280 | oLogFile.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
281 | }
282 | return oLogFile;
283 |
284 | }
285 |
286 | // TODO: add log levels.
287 | function writeLog(sLogMessage){
288 | var oLogFile = getLogFile();
289 |
290 | var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
291 | createInstance(Components.interfaces.nsIFileOutputStream);
292 |
293 | // use 0x02 | 0x10 to open file in append mode.
294 | foStream.init(oLogFile, 0x02 | 0x10, 0666, 0);
295 |
296 | var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].
297 | createInstance(Components.interfaces.nsIConverterOutputStream);
298 | converter.init(foStream, "UTF-8", 0, 0);
299 | converter.writeString("" + sLogMessage);
300 | converter.close(); // this closes foStream
301 | }
302 |
303 | /*
304 | Returns a temp file path after writing sBody to it.
305 | sBody (string)
306 | */
307 | function getTempFilePath(sBody){
308 | var oTmpFile = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
309 | oTmpFile.append("msg.tmp");
310 | oTmpFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
311 | // do whatever you need to the created file
312 |
313 | var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
314 | createInstance(Components.interfaces.nsIFileOutputStream);
315 |
316 | // use 0x02 | 0x10 to open file for appending.
317 | foStream.init(oTmpFile, 0x02 | 0x08 | 0x20, 0666, 0);
318 | // write, create, truncate
319 | // In a c file operation, we have no need to set file mode with or operation,
320 | // directly using "r" or "w" usually.
321 |
322 | // if you are sure there will never ever be any non-ascii text in data you can
323 | // also call foStream.writeData directly
324 | var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].
325 | createInstance(Components.interfaces.nsIConverterOutputStream);
326 | converter.init(foStream, "UTF-8", 0, 0);
327 | converter.writeString(sBody);
328 | converter.close(); // this closes foStream
329 |
330 | return oTmpFile;
331 | }
332 |
333 | function removeFile(sTmpFilePath){
334 | try{
335 | var oTmpFile = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
336 | oTmpFile.initWithPath(sTmpFilePath);
337 | if(oTmpFile.exists()){
338 | oTmpFile.remove(false);
339 | }
340 | }catch(oEx){
341 | // alert(oEx.name + " " + oEx.message);
342 | }
343 | }
344 |
345 | /*
346 | Opens a file picker
347 |
348 | sText: File picker title.
349 |
350 | sDestinationId: Id of the textbox whose value
351 | the selected path will be set to.
352 | */
353 | function SelectFile(sText, sDestinationId){
354 |
355 | SelectFile(sText, sDestinationId,false);
356 | // const nsIFilePicker = Components.interfaces.nsIFilePicker;
357 |
358 | // var fp = Components.classes["@mozilla.org/filepicker;1"]
359 | // .createInstance(nsIFilePicker);
360 | // fp.init(window, sText, nsIFilePicker.modeOpen);
361 | // fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
362 |
363 | // var rv = fp.show();
364 | // if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
365 | // var file = fp.file;
366 | // // Get the path as string. Note that you usually won't
367 | // // need to work with the string paths.
368 | // var sFilePath = fp.file.path;
369 | // // work with returned nsILocalFile...
370 | // // TODO: this should refere to a function in a util file,
371 | // // se how to import an external file.
372 | // if(sDestinationId != null){
373 | // var oDomEl = window.document.getElementById(sDestinationId);
374 | // if(oDomEl != null){
375 | // window.document.getElementById(sDestinationId).value = sFilePath;
376 | // }
377 | // }
378 | // }
379 | }
380 |
381 | /*
382 | Opens a file picker
383 |
384 | sText: File picker title.
385 |
386 | sDestinationId: Id of the textbox whose value
387 | the selected path will be set to.
388 |
389 | bSaveMode: if true user can specify new files, if false user can
390 | select just existing files.
391 | */
392 | function SelectFile(sText, sDestinationId, bSaveMode){
393 |
394 | const nsIFilePicker = Components.interfaces.nsIFilePicker;
395 |
396 | var fp = Components.classes["@mozilla.org/filepicker;1"]
397 | .createInstance(nsIFilePicker);
398 | var oOpenMode;
399 | if(bSaveMode){
400 | // setting save mode.
401 | oOpenMode = nsIFilePicker.modeSave;
402 | }
403 | else{
404 | // setting open mode.
405 | oOpenMode = nsIFilePicker.modeOpen;
406 | }
407 |
408 | fp.init(window, sText, oOpenMode);
409 | fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
410 | if(bSaveMode){
411 | fp.appendFilters(nsIFilePicker.modeSave);
412 | }
413 |
414 | var rv = fp.show();
415 | if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
416 | var file = fp.file;
417 | // Get the path as string. Note that you usually won't
418 | // need to work with the string paths.
419 | var sFilePath = fp.file.path;
420 | // work with returned nsILocalFile...
421 | // TODO: this should refere to a function in a util file,
422 | // se how to import an external file.
423 | if(sDestinationId != null){
424 | var oDomEl = window.document.getElementById(sDestinationId);
425 | if(oDomEl != null){
426 | window.document.getElementById(sDestinationId).value = sFilePath;
427 | }
428 | }
429 | }
430 | }
431 |
432 | /*
433 | Retrieves the path of mixminion executable fom Thunderbird
434 | preferences.
435 | Returns: a string containing the path of mixminion.
436 | */
437 | function getMixPathToPrefs(){
438 |
439 | // Getting extension preferences.
440 | var prefs = Components.classes["@mozilla.org/preferences-service;1"]
441 | .getService(Components.interfaces.nsIPrefService).getBranch("extensions.");
442 | // prefs.savePrefFile(null);
443 |
444 | // prefs is an nsIPrefBranch.
445 | // Look in the above section for examples of getting one.
446 | var sPath = "";
447 | if(prefs.prefHasUserValue("mixminionPath")) {
448 | // If the preference has bben set
449 | // getting mixminion path preference.
450 | sPath = prefs.getCharPref("mixminionPath");
451 | }else{
452 | // set an empty mixminion path preference.
453 | setMixPathToPrefs(sPath);
454 | }
455 | return sPath;
456 | }
457 |
458 | function setMixPathToPrefs(sMixPath){
459 |
460 | var prefs = Components.classes["@mozilla.org/preferences-service;1"]
461 | .getService(Components.interfaces.nsIPrefService).getBranch("extensions.");
462 |
463 | // prefs is an nsIPrefBranch.
464 | // Look in the above section for examples of getting one.
465 | prefs.setCharPref("mixminionPath", sMixPath); // set a pref (accessibility.typeaheadfind)
466 | }
467 |
468 | var gLogFileName = "mixlog.html";
469 |
470 | function posIntValidation(oEvent){
471 |
472 | // backspace and cancel
473 | if(oEvent.keyCode == 46 || oEvent.keyCode == 8)
474 | return true;
475 | if ((oEvent.charCode >= 48) && (oEvent.charCode <= 57))
476 | return true;
477 | return false;
478 |
479 | }
480 | function validateEmail(elementValue){
481 | var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
482 | return emailPattern.test(elementValue);
483 | }
484 |
485 | /*
486 | Function quoted from function EnigAddRecipients(mailAddrs)
487 | in enigmailCommon.js
488 | */
489 | function MixAddRecipients(toAddrList, recList) {
490 | for (var i=0; i]+)>[^,]*/g,"$1$2");
517 |
518 | return mailAddrs;
519 | }
520 |
521 | function isValidFilePath(sSurbPath)
522 | {
523 | // TODO: Use system char for path separator
524 | var iIndex = sSurbPath.indexOf('/');
525 | // checking whether the path begins with file system root.
526 | if(iIndex == 0){
527 | return true;
528 | }
529 | else{
530 | return false;
531 | }
532 | }
533 |
534 | /*
535 | Returns the plaintex from "node" if "findStr" has
536 | been found in "node". Empty otherwise.
537 | It has been taken from Enigmail.
538 | */
539 | function getDeepText(node, findStr) {
540 |
541 | if (findStr) {
542 | if (node.innerHTML.replace(/ /g, " ").indexOf(findStr) < 0) {
543 | // exit immediately if findStr is not found at all
544 | return "";
545 | }
546 | }
547 |
548 | // EnigDumpHTML(node);
549 |
550 | var plainText = MixParseChildNodes(node);
551 | // Replace non-breaking spaces with plain spaces
552 | plainText = plainText.replace(/\xA0/g," ");
553 |
554 | if (findStr) {
555 | if (plainText.indexOf(findStr) < 0) {
556 | return "";
557 | }
558 | }
559 | return plainText;
560 | }
561 |
562 | /*
563 | Returns: an array of type III reply blocks.
564 | */
565 | function extractReplyBlock( sInputText){
566 | //var sExtracted = extractText(sInputText, "^-----BEGIN TYPE III REPLY BLOCK-----", "^-----END TYPE III REPLY BLOCK-----");
567 | var sExtracted = mixExtractText(sInputText, "-----BEGIN TYPE III REPLY BLOCK-----", "-----END TYPE III REPLY BLOCK-----");
568 |
569 | return sExtracted;
570 |
571 | }
572 |
573 | /*
574 | Tests whether the input string contains anonymous crypted messages.
575 | */
576 | function isAnonCryptMessage( sInputText){
577 | var sAnonText = extractAnonMessage( sInputText);
578 | var sCryptPattern = new RegExp("Message-type: encrypted\nDecoding-handle:");
579 |
580 | return sCryptPattern.test(sAnonText);
581 | }
582 |
583 | /*
584 | Tests whether the input string contains a surb.
585 | */
586 | function containsSurb( sInputText){
587 | var sAnonText = extractReplyBlock( sInputText);
588 | var sBeginPattern = new RegExp("-----BEGIN TYPE III REPLY BLOCK-----");
589 | var sEndPattern = new RegExp("-----END TYPE III REPLY BLOCK-----");
590 |
591 | return sBeginPattern.test(sAnonText) && sEndPattern.test(sAnonText);
592 | }
593 |
594 | /*
595 | Extracts a type III anonymous messages.
596 | Returns: an array of type III anonymous messages.
597 | */
598 | function extractAnonMessage( sInputText){
599 | var sExtracted = mixExtractText(sInputText, "-----BEGIN TYPE III ANONYMOUS MESSAGE-----", "-----END TYPE III ANONYMOUS MESSAGE-----");
600 |
601 | return sExtracted;
602 |
603 | }
604 |
605 | /*
606 | Returns an array of strings, containing all the occurrences of text found in
607 | sInputText starting from sBegin until sEnd included(if not found until the end
608 | of the input).
609 | Inspired by pemar.
610 | */
611 | function extractText(sInputText, sBegin, sEnd) {
612 | // array of reply blocks.
613 | var asReturn = [];
614 | var iSurbCounter = 0;
615 | var textRows = sInputText.split("\n");
616 | var myreplyblock="";
617 | var collect=false;
618 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
619 | // TODO: these do not work, check it.
620 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
621 | // var myRegStart = new RegExp(sBegin);
622 | // var myRegEnd = new RegExp(sEnd);
623 | for (var count=0; count < textRows.length; count++)
624 | {
625 | if (textRows[count].match("/"+sBegin+"/")) {
626 | collect=true;
627 | }
628 | if (collect)
629 | {
630 | myreplyblock +=textRows[count] + "\n";
631 | }
632 | if (textRows[count].match("/"+sEnd+"/")) {
633 | collect=false;
634 | // Storing the parsed reply block.
635 | asReturn[iSurbCounter++] = myreplyblock;
636 | }
637 | }
638 | return asReturn;
639 | }
640 |
641 | /*
642 | Returns an array of strings, containing all the occurrences of text found in
643 | sInputText starting from sBegin until sEnd included(if not found until the end
644 | of the input).
645 | Inspired by pemar.
646 | */
647 | function mixExtractText(sInputText, sBegin, sEnd) {
648 | // array of reply blocks.
649 | var asReturn = [];
650 | var iSurbCounter = 0;
651 | var textRows = sInputText.split("\n");
652 | var myreplyblock="";
653 | var collect=false;
654 | var myRegStart = new RegExp(sBegin);
655 | var myRegEnd = new RegExp(sEnd);
656 | for (var count=0; count < textRows.length; count++)
657 | {
658 | if (myRegStart.test(textRows[count])) {
659 | collect=true;
660 | }
661 | if (collect)
662 | {
663 | myreplyblock +=textRows[count] + "\n";
664 | }
665 | if (myRegEnd.test(textRows[count])) {
666 | collect=false;
667 | // Storing the parsed reply block.
668 | asReturn[iSurbCounter++] = myreplyblock;
669 | }
670 | }
671 | return asReturn;
672 | }
673 |
674 | /*
675 | Returns the current profile email.
676 | */
677 | function getCurrProfileEmail(){
678 |
679 | var identityElement = document.getElementById("msgIdentity");
680 |
681 | var gAccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
682 | if (identityElement) {
683 | var idKey = identityElement.value;
684 | var gCurrentIdentity = gAccountManager.getIdentity(idKey);
685 | return gCurrentIdentity.email;
686 | }
687 | return "";
688 | }
689 |
690 | /*
691 | Returns an array with the email (as a string) of each known profile.
692 | */
693 | function getAllProfilesEmail(){
694 |
695 | var gAccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
696 | var asEmails = [];
697 | var aoIds = gAccountManager.allIdentities;
698 | var iIdsCounter = aoIds.Count();
699 | for(var iIdNr = 0; iIdNr< iIdsCounter; iIdNr++){
700 | var oCurrId = aoIds.QueryElementAt(iIdNr, Components.interfaces.nsIMsgIdentity);
701 | asEmails[iIdNr] = oCurrId.email;
702 | }
703 |
704 | return asEmails;
705 | }
706 |
707 | /*
708 | Checks whether sPath is a actual file path and whether
709 | it leads to an actual file.
710 |
711 | sPath: the path to be checked.
712 |
713 | returns: true if the path leads to an existing file, false otherwise.
714 | */
715 | function pathExists(sPath){
716 | try{
717 | var oTmpFile = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
718 | oTmpFile.initWithPath(sPath);
719 | if(oTmpFile.exists()){
720 | return true;
721 | }
722 | else{
723 | return false;
724 | }
725 | }catch(oEx){
726 | return false;
727 | }
728 | }
729 |
730 | function showPrefs()
731 | {
732 | var oReturn = {in: null, out:null};
733 | var oPrefs = window.openDialog("chrome://gui/content/mixPreferences.xul", "Mixminion Preferences",
734 | "modal, toolbar,location=yes, menubar=no,top=100, left=100px,width=100cm",oReturn);
735 | return oReturn.out.bValue;
736 | }
737 |
738 | function getLogFile(){
739 |
740 | var directoryService = Components.classes["@mozilla.org/file/directory_service;1"]
741 | .getService(Components.interfaces.nsIProperties);
742 | var oLogFile = directoryService.get("ProfD", Components.interfaces.nsIFile);
743 | oLogFile.append(gLogFileName);
744 |
745 | if (!oLogFile.exists()){
746 | // if log file does not exist, create one.
747 | oLogFile.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
748 | }
749 | return oLogFile;
750 |
751 | }
752 |
753 | // TODO: add log levels.
754 | function writeLog(sLogMessage){
755 | var oLogFile = getLogFile();
756 |
757 | var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
758 | createInstance(Components.interfaces.nsIFileOutputStream);
759 |
760 | // use 0x02 | 0x10 to open file in append mode.
761 | foStream.init(oLogFile, 0x02 | 0x10, 0666, 0);
762 |
763 | var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].
764 | createInstance(Components.interfaces.nsIConverterOutputStream);
765 | converter.init(foStream, "UTF-8", 0, 0);
766 | converter.writeString("" + sLogMessage);
767 | converter.close(); // this closes foStream
768 | }
769 |
770 | /*
771 | Returns a temp file path after writing sBody to it.
772 | sBody (string)
773 | */
774 | function getTempFilePath(sBody){
775 | var oTmpFile = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
776 | oTmpFile.append("msg.tmp");
777 | oTmpFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
778 | // do whatever you need to the created file
779 |
780 | var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
781 | createInstance(Components.interfaces.nsIFileOutputStream);
782 |
783 | // use 0x02 | 0x10 to open file for appending.
784 | foStream.init(oTmpFile, 0x02 | 0x08 | 0x20, 0666, 0);
785 | // write, create, truncate
786 | // In a c file operation, we have no need to set file mode with or operation,
787 | // directly using "r" or "w" usually.
788 |
789 | // if you are sure there will never ever be any non-ascii text in data you can
790 | // also call foStream.writeData directly
791 | var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].
792 | createInstance(Components.interfaces.nsIConverterOutputStream);
793 | converter.init(foStream, "UTF-8", 0, 0);
794 | converter.writeString(sBody);
795 | converter.close(); // this closes foStream
796 |
797 | return oTmpFile;
798 | }
799 |
800 | function removeFile(sTmpFilePath){
801 | try{
802 | var oTmpFile = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
803 | oTmpFile.initWithPath(sTmpFilePath);
804 | if(oTmpFile.exists()){
805 | oTmpFile.remove(false);
806 | }
807 | }catch(oEx){
808 | // alert(oEx.name + " " + oEx.message);
809 | }
810 | }
811 |
812 | /*
813 | Opens a file picker
814 |
815 | sText: File picker title.
816 |
817 | sDestinationId: Id of the textbox whose value
818 | the selected path will be set to.
819 | */
820 | function SelectFile(sText, sDestinationId){
821 |
822 | SelectFile(sText, sDestinationId,false);
823 | // const nsIFilePicker = Components.interfaces.nsIFilePicker;
824 |
825 | // var fp = Components.classes["@mozilla.org/filepicker;1"]
826 | // .createInstance(nsIFilePicker);
827 | // fp.init(window, sText, nsIFilePicker.modeOpen);
828 | // fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
829 |
830 | // var rv = fp.show();
831 | // if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
832 | // var file = fp.file;
833 | // // Get the path as string. Note that you usually won't
834 | // // need to work with the string paths.
835 | // var sFilePath = fp.file.path;
836 | // // work with returned nsILocalFile...
837 | // // TODO: this should refere to a function in a util file,
838 | // // se how to import an external file.
839 | // if(sDestinationId != null){
840 | // var oDomEl = window.document.getElementById(sDestinationId);
841 | // if(oDomEl != null){
842 | // window.document.getElementById(sDestinationId).value = sFilePath;
843 | // }
844 | // }
845 | // }
846 | }
847 |
848 | /*
849 | Opens a file picker
850 |
851 | sText: File picker title.
852 |
853 | sDestinationId: Id of the textbox whose value
854 | the selected path will be set to.
855 |
856 | bSaveMode: if true user can specify new files, if false user can
857 | select just existing files.
858 | */
859 | function SelectFile(sText, sDestinationId, bSaveMode){
860 |
861 | const nsIFilePicker = Components.interfaces.nsIFilePicker;
862 |
863 | var fp = Components.classes["@mozilla.org/filepicker;1"]
864 | .createInstance(nsIFilePicker);
865 | var oOpenMode;
866 | if(bSaveMode){
867 | // setting save mode.
868 | oOpenMode = nsIFilePicker.modeSave;
869 | }
870 | else{
871 | // setting open mode.
872 | oOpenMode = nsIFilePicker.modeOpen;
873 | }
874 |
875 | fp.init(window, sText, oOpenMode);
876 | fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
877 | if(bSaveMode){
878 | fp.appendFilters(nsIFilePicker.modeSave);
879 | }
880 |
881 | var rv = fp.show();
882 | if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
883 | var file = fp.file;
884 | // Get the path as string. Note that you usually won't
885 | // need to work with the string paths.
886 | var sFilePath = fp.file.path;
887 | // work with returned nsILocalFile...
888 | // TODO: this should refere to a function in a util file,
889 | // se how to import an external file.
890 | if(sDestinationId != null){
891 | var oDomEl = window.document.getElementById(sDestinationId);
892 | if(oDomEl != null){
893 | window.document.getElementById(sDestinationId).value = sFilePath;
894 | }
895 | }
896 | }
897 | }
898 |
899 | /*
900 | Retrieves the path of mixminion executable fom Thunderbird
901 | preferences.
902 | Returns: a string containing the path of mixminion.
903 | */
904 | function getMixPathToPrefs(){
905 |
906 | // Getting extension preferences.
907 | var prefs = Components.classes["@mozilla.org/preferences-service;1"]
908 | .getService(Components.interfaces.nsIPrefService).getBranch("extensions.");
909 | // prefs.savePrefFile(null);
910 |
911 | // prefs is an nsIPrefBranch.
912 | // Look in the above section for examples of getting one.
913 | var sPath = "";
914 | if(prefs.prefHasUserValue("mixminionPath")) {
915 | // If the preference has bben set
916 | // getting mixminion path preference.
917 | sPath = prefs.getCharPref("mixminionPath");
918 | }else{
919 | // set an empty mixminion path preference.
920 | setMixPathToPrefs(sPath);
921 | }
922 | return sPath;
923 | }
924 |
925 | // ~/MixMinion/enigmail/ui/content/enigmailCommon.js
926 | function MixGetFrame(win, frameName) {
927 | for (var j=0; j elements
962 | plainText = plainText.concat(MixParseChildNodes(child));
963 | }
964 | child = child.nextSibling;
965 | }
966 | }
967 |
968 | return plainText;
969 | }
970 |
971 | /*
972 | Writes the given surbs (string[]) in a temp file.
973 | Returns the path of the file containning the given surbs.
974 | */
975 | function surbsToGlobalFile(asSurb, goSurbFilea){
976 |
977 | // TODO: sanitize SURB.
978 | var sSurbsText = "";
979 | for(iSurb in asSurb){
980 | var sSurbBegin = "-----BEGIN TYPE III REPLY BLOCK-----";
981 | var sSurbEnd = "-----END TYPE III REPLY BLOCK-----";
982 |
983 | var sBeginPattern = new RegExp("- " + sSurbBegin);
984 | var sEndPattern = new RegExp("- " + sSurbEnd);
985 | var sSurb = asSurb[iSurb];
986 | sSurb = sSurb.replace(sBeginPattern, sSurbBegin);
987 | sSurb = sSurb.replace(sEndPattern, sSurbEnd);
988 |
989 |
990 | sSurbsText +=sSurb + "\n";
991 | }
992 | var goSurbFile = getTempFilePath(sSurbsText);
993 | return goSurbFile.path;
994 | }
995 |
996 |
997 | function getPwd(){
998 | var oPwdParam = {in: null, out:null};
999 | window.openDialog("chrome://gui/content/mixPwdDialog.xul", "Passphrase",
1000 | "modal, toolbar,location=yes, menubar=no,top=100",oPwdParam);
1001 | if(oPwdParam == null){
1002 | return null;
1003 | }
1004 | if(oPwdParam.out == null){
1005 | return null;
1006 | }
1007 | return oPwdParam.out.sPassword;
1008 | }
--------------------------------------------------------------------------------