"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "imapfilter-2.0.10/deprecated.lua" of archive imapfilter-2.0.10.tar.gz:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 -- The old and deprecated interface, provided for compatibility.
2
3 function check(account, mbox)
4 _check_required(account, 'table')
5 _check_required(mbox, 'string')
6
7 _check_required(account.server, 'string')
8 _check_required(account.username, 'string')
9 _check_required(account.password, 'string')
10
11 if (ifcore.login(account) ~= true) then
12 return
13 end
14
15 local _, exist, recent, unseen = ifcore.status(account, mbox)
16
17 if (type(options) == 'table' and options.info == true) then
18 print(string.format("%d messages, %d recent, %d unseen, in %s@%s/%s.",
19 exist, recent, unseen, account.username,
20 account.server, mbox))
21 end
22
23 return exist, recent, unseen
24 end
25
26
27 function match(account, mbox, criteria)
28 _check_required(account, 'table')
29 _check_required(mbox, 'string')
30 _check_required(criteria, 'table')
31
32 _check_required(account.server, 'string')
33 _check_required(account.username, 'string')
34 _check_required(account.password, 'string')
35
36 if (ifcore.login(account) ~= true) then
37 return
38 end
39
40 if (_cached_select(account, mbox) ~= true) then
41 return {}
42 end
43
44 local charset = ''
45 if (type(options) == 'table' and type(options.charset) == 'string') then
46 charset = options.charset
47 end
48
49 local _, results = ifcore.search(account, _make_query(criteria), charset)
50
51 if (type(options) == 'table' and options.close == true) then
52 _cached_close(account)
53 end
54
55 if (results == nil) then
56 return {}
57 end
58
59 local t = {}
60 for n in string.gmatch(results, '%d+') do
61 table.insert(t, tonumber(n))
62 end
63
64 return t
65 end
66
67
68 function flag(account, mbox, mode, flags, messages)
69 _check_required(account, 'table')
70 _check_required(mbox, 'string')
71 _check_required(mode, 'string')
72 _check_required(flags, 'table')
73 _check_required(messages, 'table')
74
75 _check_required(account.server, 'string')
76 _check_required(account.username, 'string')
77 _check_required(account.password, 'string')
78
79 local r = flag_aux(account, mbox, mode, flags, messages)
80
81 if (type(options) == 'table' and options.info == true and
82 messages ~= nil and r == true) then
83 print(string.format("%d messages flagged in %s@%s/%s.",
84 #messages, account.username,
85 account.server, mbox))
86 end
87
88 return r
89 end
90
91 function flag_aux(account, mbox, mode, flags, messages)
92 if (#messages == 0) then
93 return
94 end
95
96 if (mode ~= 'add' and mode ~= 'remove' and mode ~= 'replace') then
97 error('"add", "remove" or "replace" expected for mode', 3)
98 end
99
100
101 if (ifcore.login(account) ~= true) then
102 return
103 end
104
105 if (_cached_select(account, mbox) ~= true) then
106 return
107 end
108
109 local f = ''
110 if (#flags ~= 0) then
111 if (flags.keywords ~= true) then
112 for k, v in ipairs(flags) do
113 if (string.lower(v) == 'answered' or
114 string.lower(v) == 'deleted' or
115 string.lower(v) == 'draft' or
116 string.lower(v) == 'flagged' or
117 string.lower(v) == 'seen') then
118 f = f .. '\\' .. v .. ' '
119 end
120 end
121 f = string.gsub(f, '(.+) ', '%1')
122 else
123 f = table.concat(flags, ' ')
124 end
125 end
126
127 local m = _make_range(messages)
128 n = #m
129 local r = false
130 for i = 1, n, 50 do
131 j = i + 49
132 if (n < j) then
133 j = n
134 end
135 r = ifcore.store(account, table.concat(m, ',', i, j), mode, f)
136 if r == false then
137 break
138 end
139 end
140
141 if (type(options) == 'table' and options.close == true) then
142 _cached_close(account)
143 end
144
145 return r
146 end
147
148
149 function copy(srcaccount, srcmbox, dstaccount, dstmbox, messages)
150 _check_required(srcaccount, 'table')
151 _check_required(srcmbox, 'string')
152 _check_required(dstaccount, 'table')
153 _check_required(dstmbox, 'string')
154 _check_required(messages, 'table')
155
156 _check_required(srcaccount.server, 'string')
157 _check_required(srcaccount.username, 'string')
158 _check_required(srcaccount.password, 'string')
159
160 _check_required(dstaccount.server, 'string')
161 _check_required(dstaccount.username, 'string')
162 _check_required(dstaccount.password, 'string')
163
164 local r = copy_aux(srcaccount, srcmbox, dstaccount, dstmbox, messages)
165
166 if (type(options) == 'table' and options.info == true and
167 messages ~= nil and r == true) then
168 print(string.format("%d messages copied from %s@%s/%s to %s@%s/%s.",
169 #messages, srcaccount.username,
170 srcaccount.server, srcmbox, dstaccount.username,
171 dstaccount.server, dstmbox))
172 end
173
174 return r
175 end
176
177 function copy_aux(srcaccount, srcmbox, dstaccount, dstmbox, messages)
178 if (#messages == 0) then
179 return
180 end
181
182 if (ifcore.login(srcaccount) ~= true) then
183 return
184 end
185
186 local r = false
187 if (srcaccount == dstaccount) then
188 if (_cached_select(srcaccount, srcmbox) ~= true) then
189 return
190 end
191
192 local m = _make_range(messages)
193 n = #m
194 for i = 1, n, 50 do
195 j = i + 49
196 if (n < j) then
197 j = n
198 end
199 r = ifcore.copy(srcaccount, table.concat(m, ',', i, j), dstmbox)
200 if r == false then
201 break
202 end
203 end
204
205 if (type(options) == 'table' and options.close == true) then
206 _cached_close(srcaccount)
207 end
208 else
209 local fast = fetchfast(srcaccount, srcmbox, messages)
210 local msgs = fetchmessage(srcaccount, srcmbox, messages)
211
212 if (ifcore.login(dstaccount) ~= true) then
213 return
214 end
215
216 for i in pairs(fast) do
217 for k, v in ipairs(fast[i]['flags']) do
218 if (string.lower(v) == '\\recent') then
219 table.remove(fast[i]['flags'], k)
220 end
221 end
222
223 r = ifcore.append(dstaccount, dstmbox, msgs[i],
224 table.concat(fast[i]['flags'], ' '), fast[i]['date'])
225 end
226 end
227
228 return r
229 end
230
231
232 function delete(account, mbox, messages)
233 _check_required(account, 'table')
234 _check_required(mbox, 'string')
235 _check_required(messages, 'table')
236
237 _check_required(account.server, 'string')
238 _check_required(account.username, 'string')
239 _check_required(account.password, 'string')
240
241 local r = flag_aux(account, mbox, 'add', { 'Deleted' }, messages)
242
243 if (type(options) == 'table' and options.info == true and
244 messages ~= nil and r == true) then
245 print(string.format("%d messages deleted in %s@%s/%s.",
246 #messages, account.username,
247 account.server, mbox))
248 end
249
250 return r
251 end
252
253
254 function move(srcaccount, srcmbox, dstaccount, dstmbox, messages)
255 _check_required(srcaccount, 'table')
256 _check_required(srcmbox, 'string')
257 _check_required(dstaccount, 'table')
258 _check_required(dstmbox, 'string')
259 _check_required(messages, 'table')
260
261 _check_required(srcaccount.server, 'string')
262 _check_required(srcaccount.username, 'string')
263 _check_required(srcaccount.password, 'string')
264
265 _check_required(dstaccount.server, 'string')
266 _check_required(dstaccount.username, 'string')
267 _check_required(dstaccount.password, 'string')
268
269 local rc = copy_aux(srcaccount, srcmbox, dstaccount, dstmbox, messages)
270 local rf = false
271 if (rc == true) then
272 rf = flag_aux(srcaccount, srcmbox, 'add', { 'Deleted' }, messages)
273 end
274
275 if (type(options) == 'table' and options.info == true and
276 messages ~= nil and rc == true and rf == true) then
277 print(string.format("%d messages moved from %s@%s/%s to %s@%s/%s.",
278 #messages, srcaccount.username,
279 srcaccount.server, srcmbox, dstaccount.username,
280 dstaccount.server, dstmbox))
281 end
282
283 return rc == true and rf == true
284 end
285
286
287 function fetchheader(account, mbox, messages)
288 _check_required(account, 'table')
289 _check_required(mbox, 'string')
290 _check_required(messages, 'table')
291
292 _check_required(account.server, 'string')
293 _check_required(account.username, 'string')
294 _check_required(account.password, 'string')
295
296 if (#messages == 0) then
297 return
298 end
299
300 if (ifcore.login(account) ~= true) then
301 return
302 end
303
304 if (_cached_select(account, mbox) ~= true) then
305 return
306 end
307
308 local results = {}
309 for i, v in ipairs(messages) do
310 local _, header = ifcore.fetchheader(account, tostring(v))
311
312 if (header ~= nil) then
313 results[tonumber(v)] = header
314 end
315 end
316
317 if (type(options) == 'table' and options.close == true) then
318 _cached_close(account)
319 end
320
321 return results
322 end
323
324 function fetchbody(account, mbox, messages)
325 _check_required(account, 'table')
326 _check_required(mbox, 'string')
327 _check_required(messages, 'table')
328
329 _check_required(account.server, 'string')
330 _check_required(account.username, 'string')
331 _check_required(account.password, 'string')
332
333 if (#messages == 0) then
334 return
335 end
336
337 if (ifcore.login(account) ~= true) then
338 return
339 end
340
341 if (_cached_select(account, mbox) ~= true) then
342 return
343 end
344
345 local results = {}
346 for i, v in ipairs(messages) do
347 local _, body = ifcore.fetchbody(account, tostring(v))
348
349 if (body ~= nil) then
350 results[tonumber(v)] = body
351 end
352 end
353
354 if (type(options) == 'table' and options.close == true) then
355 _cached_close(account)
356 end
357
358 return results
359 end
360
361 function fetchmessage(account, mbox, messages)
362 _check_required(account, 'table')
363 _check_required(mbox, 'string')
364 _check_required(messages, 'table')
365
366 _check_required(account.server, 'string')
367 _check_required(account.username, 'string')
368 _check_required(account.password, 'string')
369
370 if (#messages == 0) then
371 return
372 end
373
374 if (ifcore.login(account) ~= true) then
375 return
376 end
377
378 if (_cached_select(account, mbox) ~= true) then
379 return
380 end
381
382 local results = {}
383 for i, v in ipairs(messages) do
384 local _, header = ifcore.fetchheader(account, tostring(v))
385 local _, body = ifcore.fetchbody(account, tostring(v))
386
387 if (header ~= nil and body ~= nil) then
388 results[tonumber(v)] = header .. body
389 end
390 end
391
392 if (type(options) == 'table' and options.close == true) then
393 _cached_close(account)
394 end
395
396 return results
397 end
398
399 fetchtext = fetchmessage
400
401 function fetchfields(account, mbox, fields, messages)
402 _check_required(account, 'table')
403 _check_required(mbox, 'string')
404 _check_required(fields, 'table')
405 _check_required(messages, 'table')
406
407 _check_required(account.server, 'string')
408 _check_required(account.username, 'string')
409 _check_required(account.password, 'string')
410
411 if (#messages == 0) then
412 return
413 end
414
415 if (ifcore.login(account) ~= true) then
416 return
417 end
418
419 if (_cached_select(account, mbox) ~= true) then
420 return
421 end
422
423 local results = {}
424 for i, v in ipairs(messages) do
425 local _, headerfields = ifcore.fetchfields(account, tostring(v),
426 table.concat(fields, ' '))
427
428 if (headerfields ~= nil) then
429 results[tonumber(v)] = headerfields
430 end
431 end
432
433 if (type(options) == 'table' and options.close == true) then
434 _cached_close(account)
435 end
436
437 return results
438 end
439
440 fetchheaders = fetchfields
441
442 function fetchfast(account, mbox, messages)
443 _check_required(account, 'table')
444 _check_required(mbox, 'string')
445 _check_required(messages, 'table')
446
447 _check_required(account.server, 'string')
448 _check_required(account.username, 'string')
449 _check_required(account.password, 'string')
450
451 if (#messages == 0) then
452 return
453 end
454
455 if (ifcore.login(account) ~= true) then
456 return
457 end
458
459 if (_cached_select(account, mbox) ~= true) then
460 return
461 end
462
463 local results = {}
464 for i, v in ipairs(messages) do
465 local _, flags, date, size = ifcore.fetchfast(account, tostring(v))
466 if (flags ~= nil and date ~= nil and size ~= nil ) then
467 local f = {}
468 for s in string.gmatch(flags, '%S+') do
469 table.insert(f, s)
470 end
471 results[tonumber(v)] = {}
472 results[tonumber(v)]['flags'] = f
473 results[tonumber(v)]['date'] = date
474 results[tonumber(v)]['size'] = size
475 end
476 end
477
478 if (type(options) == 'table' and options.close == true) then
479 _cached_close(account)
480 end
481
482 return results
483 end
484
485
486 function list(account, name)
487 _check_required(account, 'table')
488 _check_optional(name, 'string')
489
490 _check_required(account.server, 'string')
491 _check_required(account.username, 'string')
492 _check_required(account.password, 'string')
493
494 if (name == nil) then
495 name = ''
496 else
497 if (type(options) == 'table' and options.namespace == true) then
498 if (name == '/') then
499 name = ''
500 end
501 if (name ~= '') then
502 name = name .. '/'
503 end
504 end
505 end
506
507 if (ifcore.login(account) ~= true) then
508 return
509 end
510
511 local _, mboxs, folders = ifcore.list(account, '', name .. '%')
512
513 local m = {}
514 for s in string.gmatch(mboxs, '%C+') do
515 table.insert(m, s)
516 end
517
518 local f = {}
519 for s in string.gmatch(folders, '%C+') do
520 if s ~= name and s ~= name .. '/' then
521 table.insert(f, s)
522 end
523 end
524
525 return m, f
526 end
527
528 function lsub(account, name)
529 _check_required(account, 'table')
530 _check_optional(name, 'string')
531
532 _check_required(account.server, 'string')
533 _check_required(account.username, 'string')
534 _check_required(account.password, 'string')
535
536 if (name == nil) then
537 name = ''
538 else
539 if (type(options) == 'table' and options.namespace == true) then
540 if (name == '/') then
541 name = ''
542 end
543 if (name ~= '') then
544 name = name .. '/'
545 end
546 end
547 end
548
549 if (ifcore.login(account) ~= true) then
550 return
551 end
552
553 local _, mboxs, folders = ifcore.lsub(account, '', name .. '%')
554
555 local m = {}
556 for s in string.gmatch(mboxs, '%C+') do
557 table.insert(m, s)
558 end
559
560 local f = {}
561 for s in string.gmatch(folders, '%C+') do
562 if s ~= name and s ~= name .. '/' then
563 table.insert(f, s)
564 end
565 end
566
567 return m, f
568 end
569
570
571 function ping(account)
572 _check_required(account, 'table')
573
574 _check_required(account.server, 'string')
575 _check_required(account.username, 'string')
576 _check_required(account.password, 'string')
577
578 if (ifcore.login(account) ~= true) then
579 return
580 end
581
582 local r = ifcore.noop(account)
583
584 return r
585 end
586
587
588 function _cached_select(account, mbox)
589 if (account.mailbox == nil or account.mailbox ~= mbox) then
590 if (ifcore.select(account, mbox) == true) then
591 account.mailbox = mbox
592 return true
593 else
594 return false
595 end
596 else
597 return true
598 end
599 end
600
601 function _cached_close(account)
602 account.mailbox = nil
603 return ifcore.close(account)
604 end
605
606
607 date_before = form_date
608 get_pass = get_password
609 daemon_mode = become_daemon