Browse Source

Add head() method to get first N messages in sequence

Alois Mahdal 3 years ago
parent
commit
78747b5460
1 changed files with 12 additions and 0 deletions
  1. 12
    0
      src/imapdomo.lua

+ 12
- 0
src/imapdomo.lua View File

@@ -203,6 +203,18 @@ pkg.filter_header_saved = function(seq, name)
203 203
     return result
204 204
 end
205 205
 
206
+pkg.head = function(num, seq)
207
+    --
208
+    -- Return first *num* elements from sequence
209
+    --
210
+    local result = seq:is_smaller(0)    -- HACK to generate empty sequence
211
+    for idx, value in ipairs(seq) do
212
+        if idx > num then break end
213
+        table.insert(result, value)
214
+    end
215
+    return result
216
+end
217
+
206 218
 pkg.filter_part_like = function(query, seq)
207 219
     --
208 220
     -- Run MIME part query on *seq* sequence of messages