-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathlua.js
1318 lines (1160 loc) · 23.9 KB
/
lua.js
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Lua function definitions. */
export const lua_functions = [
{
// Function name
name: 'i_debug',
// List of function arguments
args: {
text: {
// If this argument is set, the 'text (w/default)' and
// 'values' information from the Dovecot setting is used if it
// does NOT otherwise exist in this config.
// dovecot_setting: 'dovecot_setting_name',
// If true, this argument appears inside a Lua hash table
// instead of as a standalone argument.
// hash_arg: false,
// If true, this argument can be provided multiple times.
// multi: false,
// If true, this is an optional argument.
// optional: false,
// Argument type
type: 'string',
// Argument description. Rendered w/Markdown.
text: `Message to log.`
},
},
// List of tags to associate with this function. This is the
// Lua namespace/object (this is appended to the beginning of the
// function name).
tags: [ 'dovecot' ],
// Function description. Rendered w/Markdown.
text: `Log debug level message.`
},
{
name: 'i_info',
args: {
text: {
type: 'string',
text: `Message to log.`
},
},
tags: [ 'dovecot' ],
text: `Log info level message.`
},
{
name: 'i_warning',
args: {
text: {
type: 'string',
text: `Message to log.`
},
},
tags: [ 'dovecot' ],
text: `Log warning level message.`
},
{
name: 'i_error',
args: {
text: {
type: 'string',
text: `Message to log.`
},
},
tags: [ 'dovecot' ],
text: `Log error level message.`
},
{
name: 'event',
args: {
parent: {
type: 'parent',
text: `Use as parent event.`
},
},
tags: [ 'dovecot' ],
text:
`Generate new event. If \`parent\` is not specified, the lua script is used
as the parent.`
},
{
name: 'base64.encode',
args: {
input: {
type: 'string',
text: 'Data to encode',
}
},
tags: [ 'dovecot' ],
text: `Base64 encodes the provided input.`
},
{
name: 'base64.decode',
args: {
input: {
type: 'string',
text: 'Data to decode',
}
},
tags: [ 'dovecot' ],
text: `Base64 decodes the provided input.`
},
{
name: 'restrict_global_variables',
args: {
toggle: {
type: 'boolean',
text: `Enable or disable defining new global variables.`
},
},
tags: [ 'dovecot' ],
text: `
Enable or disable restricting new global variables.
If enabled, the rest of the script won't be allowed to declare global
non-function variables but they can declare local variables and use
already defined global variables.
If a script needs to define a variable, they must declare them as local i.e.
instead of \`my_var = "some value"\`, do \`local my_var = "some value"\`.
Restrictions will remain in place until the end of the execution of the
script or until they are lifted by calling
\`dovecot.restrict_global_variables(false)\`.
Default is permissive mode, i.e., same as lua's default, global variables
are not restricted.`
},
{
name: 'client',
args: {
auto_redirect: {
dovecot_setting: 'http_client_auto_redirect',
hash_arg: true,
},
auto_retry: {
dovecot_setting: 'http_client_auto_retry',
hash_arg: true,
},
connect_backoff_time: {
dovecot_setting: 'http_client_connect_backoff_time',
hash_arg: true,
},
connect_backoff_max_time: {
dovecot_setting: 'http_client_connect_backoff_max_time',
hash_arg: true,
},
connect_timeout: {
dovecot_setting: 'http_client_connect_timeout',
hash_arg: true,
},
event_parent: {
hash_arg: true,
type: 'event',
text: `Parent event to use.`
},
request_max_attempts: {
dovecot_setting: 'http_client_request_max_attempts',
hash_arg: true,
},
max_auto_retry_delay: {
dovecot_setting: 'http_client_max_auto_retry_delay',
hash_arg: true,
},
max_connect_attempts: {
dovecot_setting: 'http_client_max_connect_attempts',
hash_arg: true,
},
max_idle_time: {
dovecot_setting: 'http_client_max_idle_time',
hash_arg: true,
},
request_max_redirects: {
dovecot_setting: 'http_client_request_max_redirects',
hash_arg: true,
},
proxy_url: {
dovecot_setting: 'http_client_proxy_url',
hash_arg: true,
},
request_absolute_timeout: {
dovecot_setting: 'http_client_request_absolute_timeout',
hash_arg: true,
},
request_timeout: {
dovecot_setting: 'http_client_request_timeout',
hash_arg: true,
},
soft_connect_timeout: {
dovecot_setting: 'http_client_soft_connect_timeout',
hash_arg: true,
},
ssl_cipher_list: {
dovecot_setting: 'ssl_cipher_list',
hash_arg: true
},
ssl_cipher_suites: {
dovecot_setting: 'ssl_cipher_suites',
hash_arg: true
},
ssl_client_ca_dir: {
dovecot_setting: 'ssl_client_ca_dir',
hash_arg: true
},
ssl_client_ca_file: {
dovecot_setting: 'ssl_client_ca_file',
hash_arg: true
},
ssl_client_cert_file: {
dovecot_setting: 'ssl_client_cert_file',
hash_arg: true
},
ssl_client_key_file: {
dovecot_setting: 'ssl_client_key_file',
hash_arg: true
},
ssl_client_key_password: {
dovecot_setting: 'ssl_client_key_password',
hash_arg: true
},
ssl_crypto_device: {
dovecot_setting: 'ssl_crypto_device',
hash_arg: true
},
ssl_curve_list: {
dovecot_setting: 'ssl_curve_list',
hash_arg: true
},
ssl_client_require_valid_cert: {
dovecot_setting: 'ssl_client_require_valid_cert',
hash_arg: true
},
ssl_min_protocol: {
dovecot_setting: 'ssl_min_protocol',
hash_arg: true
},
ssl_options: {
dovecot_setting: 'ssl_options',
hash_arg: true
},
rawlog_dir: {
dovecot_setting: 'http_client_rawlog_dir',
hash_arg: true,
},
user_agent: {
dovecot_setting: 'http_client_user_agent',
hash_arg: true,
},
},
return: 'An http_client object.',
tags: [ 'dovecot.http' ],
text: `
Create a new http client object that can be used to submit requests to
remote servers.`
},
{
name: 'request',
args: {
url: {
hash_arg: true,
type: 'string',
text: `Full url address. Parameters will be parsed from the string. TLS encryption is implied with use of \`https\`.`
},
method: {
hash_arg: true,
type: 'string',
text: `HTTP method to use.`
},
},
return: 'An http_request object.',
tags: [ 'http_client' ],
text: `
Create a new request object.
By default, the request has \`Host\`, and \`Date\` headers with relevant
values, as well as \`Connection: Keep-Alive\`.`
},
{
name: 'add_header',
args: {
name: {
type: 'string',
text: `Name of the HTTP header.`
},
value: {
type: 'string',
text: `Value of the header.`
},
},
tags: [ 'http_request' ],
text: `Add a header to the request.`
},
{
name: 'remove_header',
args: {
name: {
type: 'string',
text: `Name of the HTTP header.`
},
},
tags: [ 'http_request' ],
text: `
Do a lookup of the header in the request and remove it if found.`
},
{
name: 'set_payload',
args: {
value: {
type: 'string',
text: `Payload of the request as string data.`
},
synchronous: {
type: 'boolean',
text: `Expect 100 Continue header before sending data. Defaults to \`false\`.`
},
},
tags: [ 'http_request' ],
text: `
Set payload data to the request.
Optionally you can set \`synchronous\`, which will cause "100 Continue"
header to be sent.`
},
{
name: 'submit',
return: `An http_response object.`,
tags: [ 'http_request' ],
text: `
Connect to the remote server and submit the request.
This function blocks until the HTTP response is fully received.`
},
{
name: 'status',
return: `Status code of the http response.`,
tags: [ 'http_response' ],
text: `
Get the status code of the HTTP response.
The codes contain error codes as well as HTTP codes, e.g., '200 HTTP_OK'
and error code that denote connection to remote server failed.
A human-readable string of the error can then be read using \`reason()\`
function.`
},
{
name: 'reason',
return: `String representation of the status.`,
tags: [ 'http_response' ],
text: `
Returns a human-readable string of HTTP status codes, e.g. "OK",
"Bad Request", "Service Unavailable", as well as connection errors, e.g.,
"connect(...) failed: Connection refused".`
},
{
name: 'header',
args: {
name: {
type: 'string',
text: `Header to retrieve.`
}
},
return: `Value of the HTTP response header.`,
tags: [ 'http_response' ],
text: `
Get value of a header in the HTTP request.
If header is not found from the response, an empty string is returned.`
},
{
name: 'payload',
return: `Payload of the HTTP response as a string.`,
tags: [ 'http_response' ],
text: `Get the payload of the HTTP response.`
},
{
name: 'append_log_prefix',
args: {
prefix: {
type: 'string',
text: `Prefix to append.`
},
},
tags: [ 'event', 'event_passthrough' ],
text: `Set prefix to append into log messages.`
},
{
name: 'replace_log_prefix',
args: {
prefix: {
type: 'string',
text: `Prefix to append.`
},
},
tags: [ 'event', 'event_passthrough' ],
text: `Append prefix for log messages.`
},
{
name: 'set_always_log_source',
tags: [ 'event', 'event_passthrough' ],
text: `Add source path:line to the log messages.`
},
{
name: 'set_forced_debug',
tags: [ 'event' ],
text: `
[[added,event_set_forced_debug_added]] Enable forced debugging for the event
and its child events.`
},
{
name: 'unset_forced_debug',
tags: [ 'event' ],
text: `
[[added,event_set_forced_debug_added]] Disable previously enabled forced
debugging.`
},
{
name: 'set_name',
args: {
name: {
type: 'string',
text: `Event name.`
},
},
tags: [ 'event', 'event_passthrough' ],
text: `Set name for event.`
},
{
name: 'add_str',
args: {
key: {
type: 'string',
text: `Key name.`
},
value: {
type: 'string',
text: `A value.`
},
},
tags: [ 'event', 'event_passthrough' ],
text: `Add a key-value pair to event.`
},
{
name: 'add_int',
args: {
key: {
type: 'string',
text: `Key name.`
},
value: {
type: 'int',
text: `Integer value.`
},
},
tags: [ 'event', 'event_passthrough' ],
text: `Add a key-value pair to event.`
},
{
name: 'add_timeval',
args: {
key: {
type: 'string',
text: `Key name.`
},
value: {
type: 'int',
text: `Unix timestamp.`
},
},
tags: [ 'event', 'event_passthrough' ],
text: `Add a key-value pair to event.`
},
{
name: 'inc_int',
args: {
key: {
type: 'string',
text: `Key name.`
},
diff: {
type: 'int',
text: `Difference to add. Can be negative.`
},
},
tags: [ 'event', 'event_passthrough' ],
text: `Increment key-value pair.`
},
{
name: 'log_debug',
args: {
message: {
type: 'string',
text: `Message to log.`
},
},
tags: [ 'event', 'event_passthrough' ],
text: `Emit debug message.`
},
{
name: 'log_info',
args: {
message: {
type: 'string',
text: `Message to log.`
},
},
tags: [ 'event', 'event_passthrough' ],
text: `Emit info message.`
},
{
name: 'log_warning',
args: {
message: {
type: 'string',
text: `Message to log.`
},
},
tags: [ 'event', 'event_passthrough' ],
text: `Emit warning message.`
},
{
name: 'log_error',
args: {
message: {
type: 'string',
text: `Message to log.`
},
},
tags: [ 'event', 'event_passthrough' ],
text: `Emit error message.`
},
{
name: 'passthrough_event',
tags: [ 'event' ],
text: `
Returns an passthrough event.
A log message *must be* logged or else a panic will occur.`
},
{
name: 'lookup',
args: {
key: {
type: 'string',
text: `Key to lookup.`
},
username: {
optional: true,
type: 'string',
text: `Username for private dict keys.`
},
},
tags: [ 'dict' ],
text: `
Lookup key from dict. If key is found, returns a table with values.
If key is not found, returns \`nil\`.`
},
{
name: 'iterate',
args: {
path: {
type: 'string',
text: `Path prefix to iterate.`
},
flags: {
type: 'int',
text: `Iteration flags. Currently raw numbers must be used for these. See \`enum dict_iterate_flags\` in the C code.`
},
username: {
optional: true,
type: 'string',
text: `Username for private dict paths.`
},
},
tags: [ 'dict' ],
text: `
Returns an iteration step function and dict iter userdata. For example:
\`\`\`lua
for key, values in dict:iterate(key_prefix, 0) do
dovecot.i_debug('key='..key..', first value='..values[1])
end`
},
{
name: 'transaction_begin',
args: {
username: {
optional: true,
type: 'string',
text: `Username for private dict keys.`
},
},
tags: [ 'dict' ],
text: `Returns a new transaction object.`
},
{
name: 'set',
args: {
key: {
type: 'string',
text: `Key to set.`
},
value: {
type: 'string',
text: `Value to set.`
},
},
tags: [ 'dict.transaction' ],
text: `Set key=value in the dict transaction.`
},
{
name: 'unset',
args: {
key: {
type: 'string',
text: `Key to unset.`
},
},
tags: [ 'dict.transaction' ],
text: `Unset key in the dict transaction.`
},
{
name: 'set_timestamp',
args: {
seconds: {
hash_arg: true,
type: 'int',
text: `UNIX timestamp.`
},
nanoseconds: {
hash_arg: true,
type: 'int',
text: `Nanoseconds part of the timestamp.`
},
},
tags: [ 'dict.transaction' ],
text: `
Set timestamp to the dict transaction.
This is currently used only with Cassandra.`
},
{
name: 'commit',
tags: [ 'dict.transaction' ],
text: `Commit the transaction.`
},
{
name: 'rollback',
tags: [ 'dict.transaction' ],
text: `Rollback the transaction.`
},
{
name: 'lookup',
args: {
hostname: {
type: 'string',
text: `Hostname to lookup.`
},
event: {
optional: true,
type: 'event',
text: `Event to use for logging.`
},
},
return: `
On successful DNS lookup, returns a table with IP addresses (which has at
least one IP).
On failure, returns nil, error string, net_gethosterror()
compatible error code (similar to e.g. Lua io.* calls).`,
tags: [ 'dns_client' ],
text: `Lookup hostname asynchronously via dns-client process.`
},
{
name: 'plugin_getenv',
args: {
key: {
type: 'string',
text: `Setting name.`
},
},
tags: [ 'mail_user' ],
text: `Returns key from user plugin settings or userdb environment.`
},
{
name: 'var_expand',
args: {
template: {
type: 'string',
text: `Variable template string.`
},
},
tags: [ 'mail_user' ],
text: `Expands mail user variables (see [[variable]]).`
},
{
name: 'mailbox',
args: {
name: {
type: 'string',
text: `Mailbox name.`
},
flags: {
optional: true,
type: 'int',
text: `Flags, see [\`dovecot.storage\`](#dovecot-storage).`
},
},
tags: [ 'mail_user' ],
text: `Allocates a mailbox.`
},
{
name: 'metadata_get',
args: {
key: {
type: 'string',
text: `Metadata key, must begin with \`/private/\` or \`/shared/\`.`
},
},
tags: [ 'mail_user' ],
text: `Returns given metadata key for the user.`
},
{
name: 'metadata_set',
args: {
key: {
type: 'string',
text: `Metadata key, must begin with \`/private/\` or \`/shared/\`.`
},
value: {
type: 'string',
text: `Value to set, \`nil\` unsets value.`
},
},
tags: [ 'mail_user' ],
text: `Sets user metadata key to value.`
},
{
name: 'metadata_unset',
args: {
key: {
type: 'string',
text: `Metadata key, must begin with \`/private/\` or \`/shared/\`.`
},
},
tags: [ 'mail_user' ],
text: `
Unsets value, same as calling \`mail_user.metadata_set()\` with value = \`nil\`.`
},
{
name: 'metadata_list',
args: {
key: {
multi: true,
type: 'string',
text: `Metadata prefix, must begin with \`/private/\` or \`/shared/\`.`
},
},
tags: [ 'mail_user' ],
text: `Lists all keys for the user metadata under prefix.`
},
{
name: 'open',
tags: [ 'mailbox' ],
text: `Opens the mailbox.`
},
{
name: 'close',
tags: [ 'mailbox' ],
text: `Closes the mailbox.`
},
{
name: 'free',
tags: [ 'mailbox' ],
text: `Releases mailbox (must be done).`
},
{
name: 'sync',
args: {
flags: {
optional: true,
type: 'int',
text: `Flags, see [\`dovecot.storage\`](#dovecot-storage).`
},
},
tags: [ 'mailbox' ],
text: `Synchronizes the mailbox (should usually be done).`
},
{
name: 'status',
args: {
item: {
multi: true,
type: 'string',
text: `Item name.`
},
},
return: `mailbox_status table`,
tags: [ 'mailbox' ],
text: `Returns requested mailbox status items as table.`
},
{
name: 'metadata_get',
args: {
key: {
type: 'string',
text: `Metadata key, must begin with \`/private/\` or \`/shared/\`.`
},
},
tags: [ 'mailbox' ],
text: `Returns given metadata key for the mailbox.`
},
{
name: 'metadata_set',
args: {
key: {
type: 'string',
text: `Metadata key, must begin with \`/private/\` or \`/shared/\`.`
},
value: {
type: 'string',
text: `Value to set, \`nil\` unsets value.`
},
},
tags: [ 'mailbox' ],
text: `Sets mailbox metadata key to value.`
},
{
name: 'metadata_unset',
args: {
key: {
type: 'string',
text: `Metadata key, must begin with \`/private/\` or \`/shared/\`.`
},
},
tags: [ 'mail_user' ],
text: `
Unsets value, same as calling \`mailbox.metadata_set()\` with value = \`nil\`.`
},
{
name: 'metadata_list',
args: {
key: {
multi: true,
type: 'string',
text: `Metadata prefix, must begin with \`/private/\` or \`/shared/\`.`
},
},
tags: [ 'mail_user' ],
text: `Lists all keys for the mailbox metadata under prefix.`
},
]
export const lua_constants = [
{
// Constant name
name: 'STATUS_MESSAGES',
// List of tags to associate with this constant. This is the
// Lua namespace/object (this is appended to the beginning of the
// constant name).
tags: [ 'dovecot.storage' ],
// Constant description. Rendered w/Markdown.
// text: `foo`,
},
{
name: 'STATUS_RECENT',
tags: [ 'dovecot.storage' ]
},
{
name: 'STATUS_UIDNEXT',
tags: [ 'dovecot.storage' ]
},
{
name: 'STATUS_UIDVALIDITY',
tags: [ 'dovecot.storage' ]
},
{
name: 'STATUS_UNSEEN',
tags: [ 'dovecot.storage' ]
},
{
name: 'STATUS_FIRST_UNSEEN_SEQ',
tags: [ 'dovecot.storage' ]
},
{
name: 'STATUS_KEYWORDS',
tags: [ 'dovecot.storage' ]
},
{
name: 'STATUS_HIGHESTMODSEQ',
tags: [ 'dovecot.storage' ]
},
{
name: 'STATUS_PERMANENT_FLAGS',
tags: [ 'dovecot.storage' ]
},
{
name: 'FIRST_RECENT_UID',
tags: [ 'dovecot.storage' ]
},
{
name: 'STATUS_HIGHESTPVTMODSEQ',
tags: [ 'dovecot.storage' ]
},
{
name: 'MAILBOX_FLAG_READONLY',
tags: [ 'dovecot.storage' ]
},
{
name: 'MAILBOX_FLAG_SAVEONLY',
tags: [ 'dovecot.storage' ]
},
{
name: 'MAILBOX_FLAG_DROP_RECENT',
tags: [ 'dovecot.storage' ]
},