-
Notifications
You must be signed in to change notification settings - Fork 6
/
R6.R
1854 lines (1721 loc) · 97.7 KB
/
R6.R
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
#' @title An IMAP Connection Class
#' @description Configure an IMAP connection using the \code{ImapCon} \code{R6}
#' class.
#' @importFrom R6 R6Class
#' @export
#' @examples
#' \dontrun{
#' # w/ Plain authentication
#' con <- configure_imap(
#' url="imaps://outlook.office365.com",
#' username="user@agency.gov.br",
#' password=rstudioapi::askForPassword(),
#' verbose = TRUE)
#'
#' # OR
#' con <- ImapCon$new(
#' url="imaps://outlook.office365.com",
#' username="user@agency.gov.br",
#' password=rstudioapi::askForPassword(),
#' verbose = TRUE)
#'
#' # w/ OAuth2.0 authentication
#' con <- configure_imap(
#' url="imaps://outlook.office365.com",
#' username="user@agency.gov.br",
#' verbose = TRUE,
#' xoauth2_bearer = "XX.Ya9...")
#'
#' # OR
#' con <- ImapCon$new(
#' url="imaps://outlook.office365.com",
#' username="user@agency.gov.br",
#' verbose = TRUE,
#' xoauth2_bearer = "XX.Ya9...")
#'
#' }
#'
#'
ImapCon <- R6::R6Class("ImapCon",
portable = FALSE,
lock_objects = FALSE,
# private = list(
# # password = character(0)#,
# # xoauth2_bearer = character(0),
# ),
public = list(
#' @description Configure and create a new IMAP connection.
#' @param url A character string containing the IMAP server address
#' @param username A character string containing the username.
#' @param password A character string containing the user's password.
#' @param xoauth2_bearer A character string containing the oauth2 bearer token.
#' @param use_ssl A logical indicating the use or not of Secure Sockets Layer
#' encryption when connecting to the IMAP server. Default is \code{TRUE}.
#' @param verbose If \code{FALSE}, mutes the flow of information between the
#' server and the client. Default is \code{FALSE}.
#' @param buffersize The size in bytes for the receive buffer. Default is
#' 16000 bytes or 16kb, which means it will use the libcurl's default value.
#' According to the libcurl's documentation, the maximum buffersize is 512kb
#' (or 512000 bytes), but any number passed to \code{buffersize} is treated
#' as a request, not an order.
#' @param timeout_ms Time in milliseconds (ms) to wait for the execution or
#' re-execution of a command. Default is 0, which means that no timeout limit is
#' set.
#' @param ... Further curl parameters (see \code{curl::curl_options}) that
#' can be used with the IMAP protocol. Only for advanced users.
#' @note \href{#method-new}{\code{ImapCon$new()}}: The \code{\link{configure_imap}}
#' should be preferred instead of \code{ImapCon$new()}.
#' @return A new `ImapCon` object.
initialize = function(url,
username,
password = NULL,
xoauth2_bearer = NULL,
use_ssl = TRUE,
verbose = FALSE,
buffersize = 16000,
timeout_ms = 0,
...) {
out <- config_con_handle_and_params(url = url, username = username,
password = password, xoauth2_bearer = xoauth2_bearer,
use_ssl = use_ssl, verbose = verbose,
buffersize = buffersize, timeout_ms = timeout_ms,
...)
# print(out$con_params)
self$con_params <- out$con_params
self$con_handle <- out$con_handle
self$con_params$folder <- NA
},
# R6 methods
## RESET methods
#' @description Reset the previously informed url
#' @param x A character string containing a new url to be set.
reset_url = function(x) {
url = x
assertthat::assert_that(
is.character(url),
msg='Argument "x" must be a string, e.g. "imaps://imap.servername.com".')
url <- utils::URLencode(gsub("/+$", "", url))
check_url <- grepl("^(imap|imaps)://\\w", url)
assertthat::assert_that(
isTRUE(check_url),
msg='Invalid url! Try the following format: "imaps://imap.servername.com".')
self$con_params$url <- utils::URLencode(gsub("/+$", "", url))
},
#' @description Reset the previously informed username
#' @param x A character string containing a new username to be set.
reset_username = function(x) {
username = x
modify_con_handle(self, username = username) # same strategy from check_args() to keep a named list
self$con_params$username <- username
},
#' @description Reset the previously informed use_ssl parameter
#' @param x A logical indicating the use or not of Secure Sockets Layer
#' encryption when connecting to the IMAP server. Default is \code{TRUE}.
reset_use_ssl = function(x) {
use_ssl = x
modify_con_handle(self, use_ssl = use_ssl)
self$con_params$use_ssl <- use_ssl
},
#' @description Reset the previously informed verbose parameter
#' @param x If \code{FALSE}, mutes the flow of information between the
#' server and the client.
reset_verbose = function(x) {
verbose = x
# verbose = to
modify_con_handle(self, verbose = verbose)
self$con_params$verbose <- verbose
},
#' @description Reset the previously informed buffersize parameter
#' @param x The size in bytes for the receive buffer. Default is
#' 16000 bytes or 16kb, which means it will use the libcurl's default value.
#' According to the libcurl's documentation, the maximum buffersize is 512kb
#' (or 512000 bytes), but any number passed to \code{buffersize} is treated
#' as a request, not an order.
reset_buffersize = function(x) {
buffersize = x
modify_con_handle(self, buffersize = buffersize)
self$con_params$buffersize <- buffersize
},
#' @description Reset the previously informed buffersize parameter
#' @param x Time in milliseconds (ms) to wait for the execution or
#' re-execution of a command. Default is 0, which means that no timeout limit is
#' set.
reset_timeout_ms = function(x) {
timeout_ms = x
modify_con_handle(self, timeout_ms = timeout_ms)
self$con_params$timeout_ms <- timeout_ms
},
#' @description Reset the previously informed password
#' @param x A character string containing the user's password.
reset_password = function(x) {
password = x
modify_con_handle(self, password = password)
},
#' @description Reset the previously informed oauth2 bearer token
#' @param x A character string containing the oauth2 bearer token.
reset_xoauth2_bearer = function(x) {
xoauth2_bearer = x
modify_con_handle(self, xoauth2_bearer = xoauth2_bearer)
},
# List elements
# access = function() {
# list(
# url = self$url,
# user = self$user
# )
# },
# MAIN METHODS:
## server capabalities
#' @description List the server's IMAP capabilities.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return A character \code{vector} containing the server's IMAP capabilities.
#' @examples
#' \dontrun{
#' cap <- con$list_server_capabilities()
#' cap
#' }
list_server_capabilities = function(retries = 1) {
out <- list_server_capabilities_int(self, retries)
return(out)
},
## mailbox operations
#' @description List mail folders in a mailbox.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return A \code{list} containing the mail folder names and their inherent
#' structure.
#' @examples
#' \dontrun{
#' folders <- con$list_mail_folders()
#' folders
#' }
list_mail_folders = function(retries = 1) {
out <- list_mail_folders_int(self, retries)
return(out)
},
#' @description Select a mail folder.
#' @param name A string containing the name of an existing mail folder on the
#' user's mailbox.
#' @param mute A \code{logical}. If \code{TRUE}, mutes the confirmation message
#' when the command is successfully executed. Default is \code{FALSE}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return A \code{list} containing the mail folder names and their inherent
#' structure.
#' @examples
#' \dontrun{
#' con$select_mail_folder(name = "INBOX")
#' }
select_folder = function(name, mute = FALSE, retries = 1) {
self$con_params$folder <- select_folder_int(self, name, mute, retries)
invisible(TRUE)
},
#' @description Examine the number of messages in a mail folder.
#' @param name A \code{character} string containing the name of an existing
#' mail folder on the user's mailbox. If no name is passed, the command
#' will be executed using the previously selected mail folder name.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return A \code{vector} (with names \code{"EXISTS"} and \code{"RECENT"})
#' containing the number of messages in each category.
#' @examples
#' \dontrun{
#' con$select_folder(name = "INBOX")
#' con$examine_folder()
#'
#' # or directly:
#' con$examine_folder("Sent")
#' }
examine_folder = function(name = NULL, retries = 1) {
out <- examine_folder_int(self, name, retries)
return(out)
},
#' @description Create a new mail folder.
#' @param name A string containing the name of the new mail folder to be
#' created.
#' @param mute A \code{logical}. If \code{TRUE}, mutes the confirmation message
#' when the command is successfully executed. Default is \code{FALSE}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return \code{TRUE} in case the operation is successful.
#' @examples
#' \dontrun{
#' con$create_folder(name = "New Folder Name")
#' }
create_folder = function(name, mute = FALSE, retries = 1) {
invisible(create_folder_int(self, name, mute, retries))
},
#' @description Rename a mail folder.
#' @param name A string containing the name of the new mail folder to be
#' renamed. If no name is passed, the command will be executed using the
#' previously selected mail folder name.
#' @param new_name A string containing the new name to be assigned.
#' @param reselect A logical. If \code{TRUE}, calls
#' \code{select_folder(name = to_folder)} under the hood before returning
#' the output. Default is \code{TRUE}.
#' @param mute A \code{logical}. If \code{TRUE}, mutes the confirmation message
#' when the command is successfully executed. Default is \code{FALSE}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return \code{TRUE} in case the operation is successful.
#' @examples
#' \dontrun{
#' con$select_folder(name = "Folder A")
#' con$rename_folder(new_name = "Folder B")
#' # or directly:
#' con$rename_folder(name = "Folder A", new_name = "Folder B")
#' }
rename_folder = function(name = NULL, new_name, reselect = TRUE,
mute = FALSE, retries = 1) {
self$con_params$folder <- rename_folder_int(self, name, new_name, reselect, mute,
retries)
invisible(TRUE)
},
#' @description List flags in a selected mail folder
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return \code{TRUE} in case the operation is successful.
#' @examples
#' \dontrun{
#' con$select_folder(name = "INBOX")
#' con$list_flags()
#' }
list_flags = function(retries = 1) {
out <- list_flags_int(self, retries)
return(out)
},
## SEARCH
### custom search
#' @description Execute a custom search
#' @param request A string directly specifying what to search or
#' constructed by a combination of relational-operator-helper-functions \code{\link{OR}}
#' and \code{\link{AND}}, and criteria helper functions such as
#' \code{\link{before}}, \code{\link{since}}, \code{\link{on}},
#' \code{\link{sent_before}}, \code{\link{sent_since}}, \code{\link{sent_on}},
#' \code{\link{flag}}, \code{\link{string}}, \code{\link{smaller_than}},
#' \code{\link{larger_than}}, \code{\link{younger_than}}, or
#' \code{\link{younger_than}}.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERIA". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @note \href{#method-search}{\code{ImapCon$search()}}: IMAP queries follows
#' Polish notation, i.e. operators such as \code{OR} come before arguments,
#' e.g. "OR argument1 argument2". Therefore, the relational-operator-helper-functions
#' in this package should be used like the following examples:
#' \code{OR(before("17-Apr-2015"), string("FROM", "John"))}. Even though there
#' is no "AND" operator in IMAP, this package adds a helper function
#' \code{\link{AND}} to indicate multiples arguments that must be searched
#' together, e.g. \code{AND(since("01-Jul-2018"), smaller_than(16000))}.
#' @return A \code{list} containing the flags (\code{character vector}),
#' the permanent flags (\code{character vector}), and an indication if custom
#' flags are allowed by the server (\code{logical vector}).
#' @family custom search
#' @examples
#' \dontrun{
#' con$select_folder(name = "INBOX")
#' # ex1
#' con$search(OR(before(date_char = "17-Apr-2015"),
#' string(expr = "John", where = "FROM")))
#'
#' # ex2
#' con$search(AND(smaller_than(size = "512000"),
#' string(expr = "John", where = "FROM"),
#' string(expr = "@ksu.edu", where = "CC")))
#' }
search = function(request, negate = FALSE, use_uid = FALSE,
esearch = FALSE, retries = 1) {
out <- search_int(self, request, negate, use_uid, esearch, retries)
return(out)
},
#OBS: helper methods for custom search -- internal helpers are not methods,
# but functions!
### size search
#' @description Search by size (LARGER)
#' @param size An integer specifying the size in bytes to be used as the
#' search criterion.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERION". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param flag An optional argument that sets one or more flags as an additional
#' filter to the search. Use \href{#method-list_flags}{\code{ImapCon$list_flags()}}
#' to list the flags in a selected mail folder. Default is \code{NULL}.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return A \code{numeric vector} containing the message ids.
#' @family search by size
#' @examples
#' \dontrun{
#' # search for messages with size larger than 512Kb
#' con$search_larger_than(size = 512000))
#' }
search_larger_than = function(size, negate = FALSE, use_uid = FALSE,
flag = NULL, esearch = FALSE, retries = 1) {
out <- search_larger_than_int(self, size, negate, use_uid, flag, esearch,
retries)
return(out)
},
#' @description Search by size (SMALLER)
#' @param size An integer specifying the size in bytes to be used as the
#' search criterion.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERION". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param flag An optional argument that sets one or more flags as an additional
#' filter to the search. Use \href{#method-list_flags}{\code{ImapCon$list_flags()}}
#' to list the flags in a selected mail folder. Default is \code{NULL}.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return A \code{numeric vector} containing the message ids.
#' @family search by size
#' @examples
#' \dontrun{
#' con$select_folder(name = "INBOX")
#' # search for messages with size smaller than 512Kb
#' con$search_smaller_than(size = 512000))
#' }
search_smaller_than = function(size, negate = FALSE, use_uid = FALSE,
flag = NULL, esearch = FALSE, retries = 1) {
out <- search_smaller_than_int(self, size, negate, use_uid, flag, esearch,
retries)
return(out)
},
### search by date
#' @description Search by internal date (BEFORE)
#' @param date_char A \code{character string} with format "DD-Mon-YYYY", e.g.
#' "01-Apr-2019". We opt not to use \code{Date} or \code{POSIX*} like
#' objects, since IMAP servers use this uncommon date format.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERION". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param flag An optional argument that sets one or more flags as an additional
#' filter to the search. Use \href{#method-list_flags}{\code{ImapCon$list_flags()}}
#' to list the flags in a selected mail folder. Default is \code{NULL}.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return A \code{numeric vector} containing the message ids.
#' @family search by date
#' @examples
#' \dontrun{
#' con$select_folder(name = "INBOX")
#' # search for messages with date before "02-Jan-2020", presenting the
#' # .. results as unique identifiers (UID)
#' con$search_before(date = "02-Jan-2020", use_uid = TRUE)
#' }
search_before = function(date_char, negate = FALSE, use_uid = FALSE,
flag = NULL, esearch = FALSE, retries = 1) {
out <- search_before_int(self, date_char, negate, use_uid,
flag, esearch, retries)
return(out)
},
#' @description Search by internal date (SINCE)
#' @param date_char A \code{character string} with format "DD-Mon-YYYY", e.g.
#' "01-Apr-2019". We opt not to use \code{Date} or \code{POSIX*} like
#' objects, since IMAP servers use this uncommon date format.
#' \code{POSIX*} like objects, since IMAP servers use this uncommon date format.
#' \code{POSIX*} like, since IMAP servers like this not so common date format.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERION". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param flag An optional argument that sets one or more flags as an additional
#' filter to the search. Use \href{#method-list_flags}{\code{ImapCon$list_flags()}}
#' to list the flags in a selected mail folder. Default is \code{NULL}.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return A \code{numeric vector} containing the message ids.
#' @family search by date
#' @examples
#' \dontrun{
#' con$select_folder(name = "INBOX")
#' # search for messages with date since "02-Jan-2020", presenting the
#' # .. results as unique identifiers (UID)
#' con$search_since(date = "02-Jan-2020", use_uid = TRUE)
#' }
search_since = function(date_char, negate = FALSE, use_uid = FALSE,
flag = NULL, esearch = FALSE, retries = 1) {
out <- search_since_int(self, date_char, negate, use_uid,
flag, esearch, retries)
return(out)
},
#' @description Search by internal date (ON)
#' @param date_char A \code{character string} with format "DD-Mon-YYYY", e.g.
#' "01-Apr-2019". We opt not to use \code{Date} or \code{POSIX*} like
#' objects, since IMAP servers use this uncommon date format.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERION". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param flag An optional argument that sets one or more flags as an additional
#' filter to the search. Use \href{#method-list_flags}{\code{ImapCon$list_flags()}}
#' to list the flags in a selected mail folder. Default is \code{NULL}.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return A \code{numeric vector} containing the message ids.
#' @family search by date
#' @examples
#' \dontrun{
#' con$select_folder(name = "INBOX")
#' # search for messages received on date "02-Jan-2020", presenting the
#' #... results as unique identifiers (UID)
#' con$search_on(date = "02-Jan-2020", use_uid = TRUE)
#' }
search_on = function(date_char, negate = FALSE, use_uid = FALSE,
flag = NULL, esearch = FALSE, retries = 1) {
out <- search_on_int(self, date_char, negate, use_uid,
flag, esearch, retries)
return(out)
},
#' @description Search by internal date (Period)
#' @param since_date_char A \code{character string} with format "DD-Mon-YYYY", e.g.
#' "01-Apr-2019". We opt not to use \code{Date} or \code{POSIX*} like
#' objects, since IMAP servers use this uncommon date format.
#' @param before_date_char A \code{character string} with format "DD-Mon-YYYY", e.g.
#' "01-Apr-2019". We opt not to use \code{Date} or \code{POSIX*} like
#' objects, since IMAP servers use this uncommon date format.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERION". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param flag An optional argument that sets one or more flags as an additional
#' filter to the search. Use \href{#method-list_flags}{\code{ImapCon$list_flags()}}
#' to list the flags in a selected mail folder. Default is \code{NULL}.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return A \code{numeric vector} containing the message ids.
#' @family search by date
#' @examples
#' \dontrun{
#' con$select_folder(name = "INBOX")
#' # search for all messages in the mail folder, EXCEPT (negate = TRUE) by
#' #... those received between the dates "02-Jan-2020" and "22-Mar-2020"
#' con$search_period(since_date_char = "02-Jan-2020",
#' before_date_char = "22-Mar-2020",
#' negate = TRUE))
#' }
search_period = function(since_date_char, before_date_char, negate = FALSE,
use_uid = FALSE, flag = NULL, esearch = FALSE,
retries = 1) {
out <- search_period_int(self, since_date_char, before_date_char, negate,
use_uid, flag, esearch, retries)
return(out)
},
#' @description Search by origination date (RFC 2822 Header - SENT BEFORE)
#' @param date_char A \code{character string} with format "DD-Mon-YYYY", e.g.
#' "01-Apr-2019". We opt not to use \code{Date} or \code{POSIX*} like
#' objects, since IMAP servers use this uncommon date format.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERION". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param flag An optional argument that sets one or more flags as an additional
#' filter to the search. Use \href{#method-list_flags}{\code{ImapCon$list_flags()}}
#' to list the flags in a selected mail folder. Default is \code{NULL}.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @note \href{#method-sent_before}{\code{ImapCon$sent_before()}}: Search
#' operations that use the origination/RFC-2822 Header date
#' tend to be "slower" than those that use the internal date. Although the
#' overhead is minimum, the difference is due to the fact that the internal date
#' is kept on a database, while the origination date has to be retrieved from
#' inside the message. Therefore, the server needs to access each message when
#' executing this type of search. Despite this fact, both dates tend to be the
#' same.
#' @return A \code{numeric vector} containing the message ids.
#' @family search by date
#' @examples
#' \dontrun{
#' # search for messages with date before "02-Jan-2020", presenting the
#' # .. results as unique identifiers (UID)
#' con$search_sent_before(date = "02-Jan-2020", use_uid = TRUE)
#' }
search_sent_before = function(date_char, negate = FALSE, use_uid = FALSE,
flag = NULL, esearch = FALSE, retries = 1) {
out <- search_sent_before_int(self, date_char, negate, use_uid,
flag, esearch, retries)
return(out)
},
#' @description Search by origination date (RFC 2822 Header - SENT SINCE)
#' @param date_char A \code{character string} with format "DD-Mon-YYYY", e.g.
#' "01-Apr-2019". We opt not to use \code{Date} or \code{POSIX*} like
#' objects, since IMAP servers use this uncommon date format.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERION". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param flag An optional argument that sets one or more flags as an additional
#' filter to the search. Use \href{#method-list_flags}{\code{ImapCon$list_flags()}}
#' to list the flags in a selected mail folder. Default is \code{NULL}.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @note \href{#method-search_sent_since}{\code{ImapCon$search_sent_since()}}: Search
#' operations that use the origination/RFC-2822 Header date
#' tend to be "slower" than those that use the internal date. Although the
#' overhead is minimum, the difference is due to the fact that the internal date
#' is kept on a database, while the origination date has to be retrieved from
#' inside the message. Therefore, the server needs to access each message when
#' executing this type of search. Despite this fact, both dates tend to be the
#' same.
#' @return A \code{numeric vector} containing the message ids.
#' @family search by date
#' @examples
#' \dontrun{
#' # search for messages with date before "02-Jan-2020", presenting the
#' # .. results as unique identifiers (UID)
#' con$search_sent_since(date = "02-Jan-2020", use_uid = TRUE)
#' }
search_sent_since = function(date_char, negate = FALSE, use_uid = FALSE,
flag = NULL, esearch = FALSE, retries = 1) {
out <- search_sent_since_int(self, date_char, negate, use_uid,
flag, esearch, retries)
return(out)
},
#' @description Search by origination date (RFC 2822 Header - SENT ON)
#' @param date_char A \code{character string} with format "DD-Mon-YYYY", e.g.
#' "01-Apr-2019". We opt not to use \code{Date} or \code{POSIX*} like
#' objects, since IMAP servers use this uncommon date format.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERION". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param flag An optional argument that sets one or more flags as an additional
#' filter to the search. Use \href{#method-list_flags}{\code{ImapCon$list_flags()}}
#' to list the flags in a selected mail folder. Default is \code{NULL}.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @note \href{#method-search_sent_on}{\code{ImapCon$search_sent_on()}}: Search
#' operations that use the origination/RFC-2822 Header date
#' tend to be "slower" than those that use the internal date. Although the
#' overhead is minimum, the difference is due to the fact that the internal date
#' is kept on a database, while the origination date has to be retrieved from
#' inside the message. Therefore, the server needs to access each message when
#' executing this type of search. Despite this fact, both dates tend to be the
#' same.
#' @return A \code{numeric vector} containing the message ids.
#' @family search by size
#' @examples
#' \dontrun{
#' con$select_folder(name = "INBOX")
#' # search for messages received on date "02-Jan-2020", presenting the
#' #... results as unique identifiers (UID)
#' con$search_sent_on(date = "02-Jan-2020", use_uid = TRUE)
#' }
search_sent_on = function(date_char, negate = FALSE, use_uid = FALSE,
flag = NULL, esearch = FALSE, retries = 1) {
out <- search_sent_on_int(self, date_char, negate, use_uid,
flag, esearch, retries)
return(out)
},
#' @description Search by origination date (RFC 2822 Header - SENT Period)
#' @param since_date_char A \code{character string} with format "DD-Mon-YYYY", e.g.
#' "01-Apr-2019". We opt not to use \code{Date} or \code{POSIX*} like
#' objects, since IMAP servers use this uncommon date format.
#' @param before_date_char A \code{character string} with format "DD-Mon-YYYY", e.g.
#' "01-Apr-2019". We opt not to use \code{Date} or \code{POSIX*} like
#' objects, since IMAP servers use this uncommon date format.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERION". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param flag An optional argument that sets one or more flags as an additional
#' filter to the search. Use \href{#method-list_flags}{\code{ImapCon$list_flags()}}
#' to list the flags in a selected mail folder. Default is \code{NULL}.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @note \href{#method-search_sent_period}{\code{ImapCon$search_sent_period()}}: Search
#' operations that use the origination/RFC-2822 Header date
#' tend to be "slower" than those that use the internal date. Although the
#' overhead is minimum, the difference is due to the fact that the internal date
#' is kept on a database, while the origination date has to be retrieved from
#' inside the message. Therefore, the server needs to access each message when
#' executing this type of search. Despite this fact, both dates tend to be the
#' same.
#' @return A \code{numeric vector} containing the message ids.
#' @family search by date
#' @examples
#' \dontrun{
#' con$select_folder(name = "INBOX")
#' # search for all messages in the mail folder, EXCEPT (negate = TRUE) by
#' #... those received between the dates "02-Jan-2020" and "22-Mar-2020"
#' con$search_sent_period(since_date_char = "02-Jan-2020",
#' before_date_char = "22-Mar-2020",
#' negate = TRUE))
#' }
search_sent_period = function(since_date_char, before_date_char, negate = FALSE,
use_uid = FALSE, flag = NULL, esearch = FALSE,
retries = 1) {
out <- search_sent_period_int(self, since_date_char, before_date_char,
negate, use_uid, flag, esearch, retries)
return(out)
},
### OTHER SEARCH
### flag
#' @description Search by flag(s)
#' @param name A string containing one or more flags to search for. Use
#' \href{#method-list_flags}{\code{ImapCon$list_flags()}} to list the flags
#' in a selected mail folder.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERION". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @return A \code{numeric vector} containing the message ids.
#' @family search by flag
#' @examples
#' \dontrun{
#' con$select_folder(name = "INBOX")
#' # search for all messages in the mail folder that are marked as "SEEN" AND
#' #.. "ANSWERED"
#' con$search_flag(name = c("SEEN", "ANSWERED"))
#' }
search_flag = function(name, negate = FALSE, use_uid = FALSE, esearch = FALSE,
retries = 1) {
out <- search_flag_int(self, name, negate, use_uid, esearch, retries)
return(out)
},
### WITHIN
#' @description Search WITHIN a specific time (OLDER)
#' @param seconds An integer specifying the number of seconds to be used as
#' the search criterion.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERION". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param flag An optional argument that sets one or more flags as an additional
#' filter to the search. Use \href{#method-list_flags}{\code{ImapCon$list_flags()}}
#' to list the flags in a selected mail folder. Default is \code{NULL}.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @note \href{#method-search_older_than}{\code{ImapCon$search_older_than()}}:
#' To be able to use this functionality, the server must support the
#' \code{WITHIN} capability. You can check it by running
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @return A \code{numeric vector} containing the message ids.
#' @family search within
#' @examples
#' \dontrun{
#' con$select_folder(name = "INBOX")
#' # search for all messages received in the last hour (not older than 3600 seconds)
#' con$search_older_than(seconds = 3600, negate = TRUE)
#' }
search_older_than = function(seconds, negate = FALSE, use_uid = FALSE,
flag = NULL, esearch = FALSE, retries = 1) {
out <- search_older_than_int(self, seconds, negate, use_uid, flag,
esearch, retries)
return(out)
},
#' @description Search WITHIN a specific time (YOUNGER)
#' @param seconds An integer specifying the number of seconds to be used as
#' the search criterion.
#' @param negate If \code{TRUE}, negates the search and seeks for "NOT SEARCH
#' CRITERION". Default is \code{FALSE}.
#' @param use_uid Default is \code{FALSE}. In this case, results will be
#' presented as message sequence numbers. A message sequence number is a
#' message's relative position to the oldest message in a mail folder. It may
#' change after deleting or moving messages. If a message is deleted,
#' sequence numbers are reordered to fill the gap. If \code{TRUE}, the
#' command will be performed using the \code{"UID"} or unique identifier,
#' and results are presented as such. UIDs are always the same during the
#' life cycle of a message in a mail folder.
#' @param flag An optional argument that sets one or more flags as an additional
#' filter to the search. Use \href{#method-list_flags}{\code{ImapCon$list_flags()}}
#' to list the flags in a selected mail folder. Default is \code{NULL}.
#' @param esearch A logical. Default is \code{FALSE}. If the IMAP server has
#' \code{ESEARCH} capability, it can be used to optimize search results. It
#' will condense the results: instead of writing down the whole sequences of messages'
#' ids, such as \code{\{1 2 3 4 5\}}, it will be presented as \code{\{1:5\}},
#' which decreases transmission costs. This argument can be used along with
#' \code{buffersize} to avoid results stripping. Check if your IMAP server
#' supports \code{ESEARCH} with
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @param retries Number of attempts to connect and execute the command.
#' Default is \code{1}.
#' @note \href{#method-search_older_than}{\code{ImapCon$search_older_than()}}:
#' To be able to use this functionality, the server must support the
#' \code{WITHIN} capability. You can check it by running
#' \href{#method-list_server_capabilities}{\code{ImapCon$list_server_capabilities()}}.
#' @return A \code{numeric vector} containing the message ids.
#' @family search within
#' @examples
#' \dontrun{
#' con$select_folder(name = "INBOX")
#' # search for all messages received in the last hour (younger than 3600 seconds)