Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add keyword argument for search charset #364

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,7 @@ def uid_expunge(uid_set)

# :call-seq:
# search(criteria, charset = nil) -> result
# search(criteria, charset: nil) -> result
#
# Sends a {SEARCH command [IMAP4rev1 §6.4.4]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.4.4]
# to search the mailbox for messages that match the given search +criteria+,
Expand Down Expand Up @@ -2210,6 +2211,7 @@ def search(...)

# :call-seq:
# uid_search(criteria, charset = nil) -> result
# uid_search(criteria, charset: nil) -> result
#
# Sends a {UID SEARCH command [IMAP4rev1 §6.4.8]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.4.8]
# to search the mailbox for messages that match the given searching
Expand Down Expand Up @@ -3150,7 +3152,11 @@ def enforce_logindisabled?
end
end

def search_args(keys, charset = nil)
def search_args(keys, charset_arg = nil, charset: nil)
if charset && charset_arg
raise ArgumentError, "multiple charset arguments"
end
charset ||= charset_arg
# NOTE: not handling combined RETURN and CHARSET for raw strings
if charset && keys in /\ACHARSET\b/i | Array[/\ACHARSET\z/i, *]
raise ArgumentError, "multiple charset arguments"
Expand Down
12 changes: 12 additions & 0 deletions test/net/imap/test_imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,9 @@ def test_unselect
imap.search('CHARSET UTF-8 SUBJECT "Hello world"')
assert_equal 'CHARSET UTF-8 SUBJECT "Hello world"', server.commands.pop.args

imap.search('SUBJECT "Hello world"', charset: "UTF-8")
assert_equal 'CHARSET UTF-8 SUBJECT "Hello world"', server.commands.pop.args

imap.search([:*])
assert_equal "*", server.commands.pop.args

Expand Down Expand Up @@ -1276,6 +1279,15 @@ def seqset_coercible.to_sequence_set
assert_raise(ArgumentError) do
imap.search("charset foo ALL", "bar")
end
assert_raise(ArgumentError) do
imap.search(["ALL"], "foo", charset: "bar")
end
assert_raise(ArgumentError) do
imap.search(["charset", "foo", "ALL"], charset: "bar")
end
assert_raise(ArgumentError) do
imap.search("charset foo ALL", charset: "bar")
end
# Parsing return opts is too complicated, for now.
# assert_raise(ArgumentError) do
# imap.search("return () charset foo ALL", "bar")
Expand Down
Loading