!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Frank Schönheit <frank.schoenheit@gmx.de>
19 * Portions created by the Initial Developer are Copyright (C) 2003
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Frank Schönheit <frank.schoenheit@gmx.de>
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 const MILLISECONDS_PER_HOUR = 60 * 60 * 1000;
40 const MICROSECONDS_PER_DAY = 1000 * MILLISECONDS_PER_HOUR * 24;
41
onLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
42 function onLoad()
43 {
44 var upperDateBox = document.getElementById("upperDate");
45 // focus the upper bound control - this is where we expect most users to enter
46 // a date
47 upperDateBox.focus();
48
49 // and give it an initial date - "yesterday"
50 var initialDate = new Date();
51 initialDate.setHours( 0 );
52 initialDate.setTime( initialDate.getTime() - MILLISECONDS_PER_HOUR );
53 // note that this is sufficient - though it is at the end of the previous day,
54 // we convert it to a date string, and then the time part is truncated
55 upperDateBox.value = convertDateToString( initialDate );
56 upperDateBox.select(); // allows to start overwriting immediately
57 }
58
onAccept
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
59 function onAccept()
60 {
61 // get the times as entered by the user
62 var lowerDateString = document.getElementById( "lowerDate" ).value;
63 // the fallback for the lower bound, if not entered, is the "beginning of
64 // time" (1970-01-01), which actually is simply 0 :)
65 var prLower = lowerDateString ? convertStringToPRTime( lowerDateString ) : 0;
66
67 var upperDateString = document.getElementById( "upperDate" ).value;
68 var prUpper;
69 if ( upperDateString == "" )
70 {
71 // for the upper bound, the fallback is "today".
72 var dateThisMorning = new Date();
73 dateThisMorning.setMilliseconds( 0 );
74 dateThisMorning.setSeconds( 0 );
75 dateThisMorning.setMinutes( 0 );
76 dateThisMorning.setHours( 0 );
77 // Javascript time is in milliseconds, PRTime is in microseconds
78 prUpper = dateThisMorning.getTime() * 1000;
79 }
80 else
81 prUpper = convertStringToPRTime( upperDateString );
82
83 // for the upper date, we have to do a correction:
84 // if the user enters a date, then she means (hopefully) that all messages sent
85 // at this day should be marked, too, but the PRTime calculated from this would
86 // point to the beginning of the day. So we need to increment it by
87 // [number of micro seconds per day]. This will denote the first microsecond of
88 // the next day then, which is later used as exclusive boundary
89 prUpper += MICROSECONDS_PER_DAY;
90
91 markInDatabase( prLower, prUpper );
92
93 return true; // allow closing
94 }
95
96 /** marks all headers in the database, whose time is between the two
97 given times, as read.
98 @param lower
99 PRTime for the lower bound - this boundary is inclusive
100 @param upper
101 PRTime for the upper bound - this boundary is exclusive
102 */
markInDatabase
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
103 function markInDatabase( lower, upper )
104 {
105 var messageFolder;
106 var messageDatabase;
107 // extract the database
108 if ( window.arguments && window.arguments[0] )
109 {
110 messageFolder = window.arguments[0];
111 messageDatabase = messageFolder.getMsgDatabase( null );
112 }
113
114 if ( !messageDatabase )
115 {
116 dump( "markByDate::markInDatabase: there /is/ no database to operate on!\n" );
117 return;
118 }
119
120 // the headers which are going to be marked
121 var headers = Components.classes["@mozilla.org/supports-array;1"].createInstance( Components.interfaces.nsISupportsArray );
122
123 // create an enumerator for all messages in the database
124 var enumerator = messageDatabase.EnumerateMessages();
125 if ( enumerator )
126 {
127 while ( enumerator.hasMoreElements() )
128 {
129 var header = enumerator.getNext();
130 if ( header instanceof Components.interfaces.nsIMsgDBHdr )
131 {
132 if ( !header.isRead ) // don't do anything until really necessary
133 {
134 var messageDate = header.date;
135
136 if ( ( lower <= messageDate ) && ( messageDate < upper ) )
137 headers.AppendElement( header );
138 }
139 }
140 else
141 dump("markByDate::markInDatabase: unexpected: the database gave us a header which is no nsIMsgDBHdr!\n" );
142 }
143 }
144
145 if ( headers.Count() )
146 messageFolder.markMessagesRead( headers, true );
147 }