浏览代码

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

Alois Mahdal 3 年前
父节点
当前提交
78747b5460
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. 12
    0
      src/imapdomo.lua

+ 12
- 0
src/imapdomo.lua 查看文件

@@ -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