Skip to content

Commit

Permalink
IMAP folder functions overloaded for string arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
karastojko committed Jun 24, 2021
1 parent 300ccd3 commit 0a0cedb
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 16 deletions.
52 changes: 49 additions & 3 deletions include/mailio/imap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,42 @@ class MAILIO_EXPORT imap
/**
Creating folder.
@param folder_tree Folder to be created.
@param folder_name Folder to be created.
@return True if created, false if not.
@throw imap_error Parsing failure.
@throw imap_error Creating folder failure.
@throw * `folder_delimiter()`, `parse_tag_result(const string&)`, `dialog::send(const string&)`, `dialog::receive()`.
@throw * `parse_tag_result(const string&)`, `dialog::send(const string&)`, `dialog::receive()`.
@todo Return status really needed?
**/
bool create_folder(const std::string& folder_name);

/**
Creating folder.
@param folder_name Folder to be created.
@return True if created, false if not.
@throw * `folder_delimiter()`, `create_folder(const string&)`.
@todo Return status really needed?
**/
bool create_folder(const std::list<std::string>& folder_name);

/**
Listing folders.
@param folder_name Folder to list.
@return Subfolder tree of the folder.
@throw imap_error Listing folders failure.
@throw imap_error Parsing failure.
@throw * `folder_delimiter()`, `parse_tag_result`, `dialog::send(const string&)`, `dialog::receive()`.
**/
bool create_folder(const std::list<std::string>& folder_tree);
mailbox_folder list_folders(const std::string& folder_name);

/**
Listing folders.
@param folder_name Folder to list.
@return Subfolder tree of the folder.
@throw * `folder_delimiter()`, `list_folders(const string&)`.
**/
mailbox_folder list_folders(const std::list<std::string>& folder_name);

Expand All @@ -400,6 +423,17 @@ class MAILIO_EXPORT imap
@throw imap_error Parsing failure.
@throw imap_error Deleting folder failure.
@throw * `folder_delimiter()`, `parse_tag_result(const string&)`, `dialog::send(const string&)`, `dialog::receive()`.
@todo Return status really needed?
**/
bool delete_folder(const std::string& folder_name);

/**
Deleting a folder.
@param folder_name Folder to delete.
@return True if deleted, false if not.
@throw * `delete_folder(const string&)`.
@todo Return status really needed?
**/
bool delete_folder(const std::list<std::string>& folder_name);

Expand All @@ -412,6 +446,18 @@ class MAILIO_EXPORT imap
@throw imap_error Parsing failure.
@throw imap_error Renaming folder failure.
@throw * `folder_delimiter()`, `parse_tag_result(const string&)`, `dialog::send(const string&)`, `dialog::receive()`.
@todo Return status really needed?
**/
bool rename_folder(const std::string& old_name, const std::string& new_name);

/**
Renaming a folder.
@param old_name Old name of the folder.
@param new_name New name of the folder.
@return True if renaming is successful, false if not.
@throw * `rename_folder(const string&, const string&)`.
@todo Return status really needed?
**/
bool rename_folder(const std::list<std::string>& old_name, const std::list<std::string>& new_name);

Expand Down
52 changes: 39 additions & 13 deletions src/imap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,11 +769,9 @@ void imap::search(const list<imap::search_condition_t>& conditions, list<unsigne
}


bool imap::create_folder(const list<string>& folder_tree)
bool imap::create_folder(const string& folder_name)
{
string delim = folder_delimiter();
string folder_str = folder_tree_to_string(folder_tree, delim);
_dlg->send(format("CREATE " + QUOTED_STRING_SEPARATOR + folder_str + QUOTED_STRING_SEPARATOR));
_dlg->send(format("CREATE " + QUOTED_STRING_SEPARATOR + folder_name + QUOTED_STRING_SEPARATOR));

string line = _dlg->receive();
tag_result_response_t parsed_line = parse_tag_result(line);
Expand All @@ -784,14 +782,22 @@ bool imap::create_folder(const list<string>& folder_tree)
if (parsed_line.result.value() != tag_result_response_t::OK)
throw imap_error("Creating folder failure.");
return true;

}


auto imap::list_folders(const list<string>& folder_name) -> mailbox_folder
bool imap::create_folder(const list<string>& folder_name)
{
string delim = folder_delimiter();
string folder_name_s = folder_tree_to_string(folder_name, delim);
_dlg->send(format("LIST " + QUOTED_STRING_SEPARATOR + QUOTED_STRING_SEPARATOR + TOKEN_SEPARATOR_STR + QUOTED_STRING_SEPARATOR + folder_name_s + "*" +
string folder_str = folder_tree_to_string(folder_name, delim);
return create_folder(folder_str);
}


auto imap::list_folders(const string& folder_name) -> mailbox_folder
{
string delim = folder_delimiter();
_dlg->send(format("LIST " + QUOTED_STRING_SEPARATOR + QUOTED_STRING_SEPARATOR + TOKEN_SEPARATOR_STR + QUOTED_STRING_SEPARATOR + folder_name + "*" +
QUOTED_STRING_SEPARATOR));
mailbox_folder mailboxes;

Expand Down Expand Up @@ -840,11 +846,17 @@ auto imap::list_folders(const list<string>& folder_name) -> mailbox_folder
}


bool imap::delete_folder(const list<string>& folder_name)
auto imap::list_folders(const list<string>& folder_name) -> mailbox_folder
{
string delim = folder_delimiter();
string folder_name_s = folder_tree_to_string(folder_name, delim);
_dlg->send(format("DELETE " + QUOTED_STRING_SEPARATOR + folder_name_s + QUOTED_STRING_SEPARATOR));
return list_folders(folder_name_s);
}


bool imap::delete_folder(const string& folder_name)
{
_dlg->send(format("DELETE " + QUOTED_STRING_SEPARATOR + folder_name + QUOTED_STRING_SEPARATOR));

string line = _dlg->receive();
tag_result_response_t parsed_line = parse_tag_result(line);
Expand All @@ -858,12 +870,17 @@ bool imap::delete_folder(const list<string>& folder_name)
}


bool imap::rename_folder(const list<string>& old_name, const list<string>& new_name)
bool imap::delete_folder(const list<string>& folder_name)
{
string delim = folder_delimiter();
string old_name_s = folder_tree_to_string(old_name, delim);
string new_name_s = folder_tree_to_string(new_name, delim);
_dlg->send(format("RENAME " + QUOTED_STRING_SEPARATOR + old_name_s + QUOTED_STRING_SEPARATOR + TOKEN_SEPARATOR_STR + QUOTED_STRING_SEPARATOR + new_name_s +
string folder_name_s = folder_tree_to_string(folder_name, delim);
return delete_folder(folder_name_s);
}


bool imap::rename_folder(const string& old_name, const string& new_name)
{
_dlg->send(format("RENAME " + QUOTED_STRING_SEPARATOR + old_name + QUOTED_STRING_SEPARATOR + TOKEN_SEPARATOR_STR + QUOTED_STRING_SEPARATOR + new_name +
QUOTED_STRING_SEPARATOR));

string line = _dlg->receive();
Expand All @@ -878,6 +895,15 @@ bool imap::rename_folder(const list<string>& old_name, const list<string>& new_n
}


bool imap::rename_folder(const list<string>& old_name, const list<string>& new_name)
{
string delim = folder_delimiter();
string old_name_s = folder_tree_to_string(old_name, delim);
string new_name_s = folder_tree_to_string(new_name, delim);
return rename_folder(old_name_s, new_name_s);
}


string imap::connect()
{
// read greetings message
Expand Down

0 comments on commit 0a0cedb

Please sign in to comment.