This file is indexed.

/usr/share/GNUstep/SOGo/WebServerResources/SOGoMailDataSource.js is in sogo-common 2.2.17a-1.1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/* -*- Mode: js2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

SOGoMailDataSource = Class.create({

        initialize: function(dataTable, url) {
            // Instance variables
            this.dataTable = dataTable;
            this.id = url;
            this.url = url;

            this.uids = new Array();
            this.threaded = false;
            this.cache = new Hash();

            this.loaded = false;
            this.delayedGetData = false;
            this.ajaxGetData = false;

            // Constants
            this.overflow = 50;   // must be higher or equal to the overflow of the data table class
        },

        destroy: function() {
            this.uids.clear();
            var keys = this.cache.keys();
            for (var i = 0; i < keys.length; i++)
                this.cache.unset(keys[i]);
        },

        invalidate: function(uid) {
            this.cache.unset(uid);
            var index = this.indexOf(uid);
//            log ("MailDataSource.invalidate(" + uid + ") at index " + index);

            return index;
        },

        remove: function(uid) {
//            log ("MailDataSource.remove(" + uid + ")");
            var index = this.invalidate(uid);
            if (index >= 0) {
                this.uids.splice(index, 1);
            }

            return index;
        },

        init: function(uids, threaded, headers, quotas) {
            this.uids = uids;
            if (typeof threaded != "undefined") {
                this.threaded = threaded;
                if (threaded)
                    this.uids.shift(); // drop key fields
            }
//            log ("MailDataSource.init() " + this.uids.length + " uids loaded");

            if (quotas && Object.isFunction(updateQuotas))
                updateQuotas(quotas);

            if (headers) {
                var keys = headers[0];
                for (var i = 1; i < headers.length; i++) {
                    var header = [];
                    for (var j = 0; j < keys.length; j++)
                        header[keys[j]] = headers[i][j];
                    this.cache.set(header["uid"], header);
                }
//                log ("MailDataSource.init() " + this.cache.keys().length + " headers loaded");
            }

            this.loaded = true;
//            log ("MailDataSource.init() " + this.uids.length + " UIDs, " + this.cache.keys().length + " headers");
        },

        load: function(content) {
            this.loaded = false;
            triggerAjaxRequest(this.url + "/uids",
                               this._loadCallback.bind(this),
                               null,
                               content,
                               { "content-type": "application/json" });
        },

        _loadCallback: function(http) {
            if (http.status == 200) {
                if (http.responseText.length > 0) {
                    var data = http.responseText.evalJSON(true);
                    if (data.uids)
                        this.init(data.uids, data.threaded, data.headers, data.quotas);
                    else
                        this.init(data);
                    if (this.delayedGetData) {
                        this.delayedGetData();
                        this.delayedGetData = false;
                    }
                }
            }
            else {
                log("SOGoMailDataSource._loadCallback Error " + http.status + ": " + http.responseText);
            }
        },

        getData: function(id, index, count, callbackFunction, delay) {
            if (this.loaded == false) {
                // UIDs are not yet loaded -- delay the call until loading the data is completed.
//                log ("MailDataSource.getData() delaying data fetching while waiting for UIDs");
                this.delayedGetData = this.getData.bind(this, id, index, count, callbackFunction, delay);
                return;
            }

            var start, end;

            if (count > 1) {
                // Compute last index depending on number of UIDs
                start = index - (this.overflow/2);
                if (start < 0) start = 0;
                end = index + count + this.overflow - (index - start);
                if (end > this.uids.length) {
                    start -= end - this.uids.length;
                    end = this.uids.length;
                    if (start < 0) start = 0;
                }
            }
            else {
                // Count is 1; don't fetch more data since the caller is
                // SOGoDataTable.invalide() and asks for only one data row.
                start = index;
                end = index + count;
            }
//            log ("MailDataSource._getData() from " + index + " to " + (index + count) + " boosted from " + start + " to " + end);

            var missingUids = [];
            for (var j = start; j < end; j++) {
                var uid = this.threaded? this.uids[j][0] : this.uids[j];
                if (!this.cache.get(uid)) {
//                    log ("MailDataSource._getData missing headers of uid " + uid + " at index " + j + (this.threaded? " (":" (non-") + "threaded)");
                    missingUids.push(uid);
                }
            }

            if (this.delayed_getRemoteData) window.clearTimeout(this.delayed_getRemoteData);
            if (missingUids.length > 0) {
                var params = "uids=" + missingUids.join(",");
                this.delayed_getRemoteData = this._getRemoteData.bind(this,
                                                                      { callbackFunction: callbackFunction,
                                                                        start: start, end: end,
                                                                        id: id },
                                                                      params).delay(delay);
            }
            else if (callbackFunction)
                this._returnData(callbackFunction, id, start, end);
        },

        _getRemoteData: function(callbackData, urlParams) {
            if (this.ajaxGetData) {
                this.ajaxGetData.aborted = true;
                this.ajaxGetData.abort();
//                 log ("MailDataSource._getRemoteData() aborted previous AJAX request");
            }
//            log ("MailDataSource._getRemoteData() fetching headers of " + urlParams);
            this.ajaxGetData = triggerAjaxRequest(this.url + "/headers",
                                                  this._getRemoteDataCallback.bind(this),
                                                  callbackData,
                                                  urlParams,
                                                  { "Content-type": "application/x-www-form-urlencoded" });
        },

        _getRemoteDataCallback: function(http) {
            if (http.status == 200) {
                if (http.responseText.length > 0) {
                    // We receives an array of hashes
                    var headers = $A(http.responseText.evalJSON(true));
                    var data = http.callbackData;
                    var keys = headers[0];
                    for (var i = 1; i < headers.length; i++) {
                        var header = [];
                        for (var j = 0; j < keys.length; j++)
                            header[keys[j]] = headers[i][j];
                        this.cache.set(header["uid"], header);
                    }

                    if (data["callbackFunction"])
                        this._returnData(data["callbackFunction"], data["id"], data["start"], data["end"]);
                }
            }
            else {
                log("SOGoMailDataSource._getRemoteDataCallback Error " + http.status + ": " + http.responseText);
            }
        },

        _returnData: function(callbackFunction, id, start, end) {
            var i, j;
            var data = new Array();
            for (i = start, j = 0; i < end; i++, j++) {
                if (this.threaded) {
                    data[j] = this.cache.get(this.uids[i][0]);

                    // Add thread-related data
                    if (parseInt(this.uids[i][2]) > 0) {
                        var mailbox = Mailer.currentMailbox;
                        if ((UserSettings.Mail.threadsCollapsed != undefined) &&
                            (UserSettings.Mail.threadsCollapsed[Mailer.currentMailbox] != undefined) &&
                            (UserSettings.Mail.threadsCollapsed[Mailer.currentMailbox].indexOf((this.uids[i][0]).toString())) != -1) {
                                  data[j]['Thread'] = '<img class="messageThread" src="' + ResourcesURL + '/arrow-right.png">';
                        }
                        else
                            data[j]['Thread'] = '<img class="messageThread" src="' + ResourcesURL + '/arrow-down.png">';
                    }
                    else if (data[j]['Thread'])
                        delete data[j]['Thread'];
                    if (parseInt(this.uids[i][1]) > -1)
                        data[j]['ThreadLevel'] = this.uids[i][1];
                    else
                        delete data[j]['ThreadLevel'];
                }
                else {
                    data[j] = this.cache.get(this.uids[i]);
                }
            }
            callbackFunction(id, start, this.uids.length, data);
        },

        indexOf: function(uid) {
            var index = -1;
            if (this.threaded) {
                for (var i = 0; i < this.uids.length; i++)
                    if (this.uids[i][0] == uid) {
                        index = i;
                        break;
                    }
            }
            else
                index = this.uids.indexOf(parseInt(uid));

            return index;
        },

        uidAtIndex: function(index) {
            if (this.threaded)
                return this.uids[index][0];
            else
                return this.uids[index];
        }
});