diff --git a/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js b/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js index a49a7227faa..a77949f4bd4 100644 --- a/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js +++ b/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js @@ -117,6 +117,8 @@ var gReceiptOptionChanged; var gAttachVCardOptionChanged; var gMailSession; +var gAutoSaveInterval; +var gAutoSaveTimeout; const kComposeAttachDirPrefName = "mail.compose.attach.dir"; @@ -249,6 +251,8 @@ var gComposeRecyclingListener = { var event = document.createEvent('Events'); event.initEvent('compose-window-close', false, true); document.getElementById("msgcomposeWindow").dispatchEvent(event); + if (gAutoSaveTimeout) + clearTimeout(gAutoSaveTimeout); }, onReopen: function(params) { @@ -1374,6 +1378,12 @@ function ComposeStartup(recycled, aParams) } } } + gAutoSaveInterval = sPrefs.getBoolPref("mail.compose.autosave") + ? sPrefs.getIntPref("mail.compose.autosaveinterval") * 60000 + : 0; + + if (gAutoSaveInterval) + gAutoSaveTimeout = setTimeout("AutoSave()", gAutoSaveInterval); } // The new, nice, simple way of getting notified when a new editor has been created @@ -1489,6 +1499,8 @@ function ComposeUnload() RemoveDirectorySettingsObserver(gCurrentAutocompleteDirectory); if (gMsgCompose) gMsgCompose.UnregisterStateListener(stateListener); + if (gAutoSaveTimeout) + clearTimeout(gAutoSaveTimeout); } function SetDocumentCharacterSet(aCharset) @@ -1749,6 +1761,7 @@ function GenericSendMessage( msgType ) msgType == nsIMsgCompDeliverMode.Later || msgType == nsIMsgCompDeliverMode.Save || msgType == nsIMsgCompDeliverMode.SaveAsDraft || + msgType == nsIMsgCompDeliverMode.AutoSaveAsDraft || msgType == nsIMsgCompDeliverMode.SaveAsTemplate) { var fallbackCharset = new Object; @@ -3020,3 +3033,12 @@ function loadHTMLMsgPrefs() { } +function AutoSave() +{ + dump("in autosave\n"); + if (gMsgCompose.editor && (gContentChanged || gMsgCompose.bodyModified)) + GenericSendMessage(nsIMsgCompDeliverMode.AutoSaveAsDraft); + + gAutoSaveTimeout = setTimeout("AutoSave()", gAutoSaveInterval); +} +