sptk2 logo
SPTK Home Page
Public Member Functions | Protected Member Functions | List of all members
sptk::ImapConnect Class Reference

#include <ImapConnect.h>

Inheritance diagram for sptk::ImapConnect:
sptk::TCPSocket sptk::BaseSocket

Public Member Functions

 ImapConnect ()=default
 
void command (const String &cmd, const String &arg1="", const String &arg2="")
 
const Stringsresponse () const
 
void cmd_capability ()
 
void cmd_noop ()
 
void cmd_logout ()
 
void cmd_login (const String &user, const String &password)
 
void cmd_select (const String &mail_box, int32_t &total_msgs)
 
void cmd_examine (const String &mail_box)
 
void cmd_subscribe (const String &mail_box)
 
void cmd_unsubscribe (const String &mail_box)
 
void cmd_create (const String &mail_box)
 
void cmd_delete (const String &mail_box)
 
void cmd_rename (const String &mail_box, const String &new_name)
 
void cmd_list (const String &mail_box_mask, bool decode=false)
 
void cmd_append (const String &mail_box, const Buffer &message)
 
void cmd_close ()
 
void cmd_expunge ()
 
void cmd_search_all (String &result)
 
void cmd_search_new (String &result)
 
void cmd_fetch_headers (int32_t msg_id, FieldList &result)
 
void cmd_fetch_message (int32_t msg_id, FieldList &result)
 
String cmd_fetch_flags (int32_t msg_id)
 
void cmd_store_flags (int32_t msg_id, const char *flags)
 
- Public Member Functions inherited from sptk::TCPSocket
 TCPSocket (SOCKET_ADDRESS_FAMILY domain=AF_INET, int32_t type=SOCK_STREAM, int32_t protocol=0)
 
 ~TCPSocket () override
 
void setProxy (std::shared_ptr< Proxy > proxy)
 
void close () noexcept override
 
virtual bool accept (SOCKET &clientSocketFD, struct sockaddr_in &clientInfo, std::chrono::milliseconds timeout)
 
size_t socketBytes () override
 
bool readyToRead (std::chrono::milliseconds timeout) override
 
size_t readLine (char *buffer, size_t size, char delimiter='\n')
 
size_t readLine (Buffer &buffer, char delimiter='\n')
 
size_t readLine (String &s, char delimiter='\n')
 
size_t read (uint8_t *buffer, size_t size, sockaddr_in *from=nullptr) override
 
size_t read (Buffer &buffer, size_t size, sockaddr_in *from=nullptr) override
 
size_t read (String &buffer, size_t size, sockaddr_in *from=nullptr) override
 
template<typename T >
size_t read (T &value, sockaddr_in *from=nullptr)
 
- Public Member Functions inherited from sptk::BaseSocket
SOCKET fd () const
 
void open_addr (OpenMode openMode=OpenMode::CREATE, const sockaddr_in *addr=nullptr, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
 
 BaseSocket (SOCKET_ADDRESS_FAMILY domain=AF_INET, int32_t type=SOCK_STREAM, int32_t protocol=0)
 
 BaseSocket (const BaseSocket &other)=delete
 
 BaseSocket (BaseSocket &&other) noexcept=default
 
virtual ~BaseSocket ()
 Destructor.
 
BaseSocketoperator= (const BaseSocket &other)=delete
 
BaseSocketoperator= (BaseSocket &&other) noexcept=default
 
void blockingMode (bool blocking)
 
virtual size_t socketBytes ()
 
virtual void attach (SOCKET socketHandle, bool accept)
 
virtual SOCKET detach ()
 
void host (const Host &host)
 
const Hosthost () const
 
void open (const Host &host=Host(), OpenMode openMode=OpenMode::CONNECT, bool blockingMode=true, std::chrono::milliseconds timeoutMS=std::chrono::milliseconds(0))
 
void open (const struct sockaddr_in &address, OpenMode openMode=OpenMode::CONNECT, bool blockingMode=true, std::chrono::milliseconds timeoutMS=std::chrono::milliseconds(0))
 
void bind (const char *address, uint32_t portNumber)
 
void listen (uint16_t portNumber=0)
 
virtual void close () noexcept
 
bool active () const
 
int32_t control (int flag, const uint32_t *check) const
 
void setOption (int level, int option, int value) const
 
void getOption (int level, int option, int &value) const
 
virtual size_t recv (uint8_t *buffer, size_t len)
 
virtual size_t send (const uint8_t *buffer, size_t len)
 
virtual size_t read (uint8_t *buffer, size_t size, sockaddr_in *from)
 
virtual size_t read (uint8_t *buffer, size_t size)
 
virtual size_t read (Buffer &buffer, size_t size, sockaddr_in *from)
 
size_t read (Buffer &buffer, size_t size)
 
virtual size_t read (String &buffer, size_t size, sockaddr_in *from)
 
size_t read (String &buffer, size_t size)
 
virtual size_t write (const uint8_t *buffer, size_t size, const sockaddr_in *peer)
 
size_t write (const uint8_t *buffer, size_t size)
 
virtual size_t write (const Buffer &buffer, const sockaddr_in *peer)
 
size_t write (const Buffer &buffer)
 
virtual size_t write (const String &buffer, const sockaddr_in *peer)
 
size_t write (const String &buffer)
 
virtual bool readyToRead (std::chrono::milliseconds timeout)
 
virtual bool readyToWrite (std::chrono::milliseconds timeout)
 
bool blockingMode () const
 Return current blocking mode state. More...
 

Protected Member Functions

String sendCommand (const String &cmd)
 
bool getResponse (const String &ident)
 
void parseSearch (String &result) const
 
void parseMessage (FieldList &result, bool headersOnly)
 
void parseFolderList ()
 
- Protected Member Functions inherited from sptk::TCPSocket
TCPSocketReaderreader ()
 
void _open (const Host &host, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeout) override
 
void _open (const struct sockaddr_in &address, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeout) override
 
Proxyproxy ()
 
- Protected Member Functions inherited from sptk::BaseSocket
void setSocketFD (SOCKET socket)
 
int32_t domain () const
 
int32_t type () const
 
int32_t protocol () const
 
virtual void _open (const Host &host, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeoutMS)
 
virtual void _open (const struct sockaddr_in &address, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeoutMS)
 

Additional Inherited Members

- Public Types inherited from sptk::BaseSocket
enum class  OpenMode : uint8_t { CREATE , CONNECT , BIND }
 

Detailed Description

IMAP socket

Class CImapConnect is used to communicate with IMAP 4 servers. It implements the most popular commands of IMAP protocol to build a simple IMAP client.

Constructor & Destructor Documentation

◆ ImapConnect()

sptk::ImapConnect::ImapConnect ( )
default

Default constructor

Member Function Documentation

◆ cmd_append()

void sptk::ImapConnect::cmd_append ( const String mail_box,
const Buffer message 
)

Appends the message to the mail box.

Parameters
mail_boxstd::string, the name of the mail box
messageCBuffer, the RFC-2060 defined message

◆ cmd_capability()

void sptk::ImapConnect::cmd_capability ( )
inline

IMAPv4 commands - any state

Retrieves server's capabilities in response().

◆ cmd_close()

void sptk::ImapConnect::cmd_close ( )
inline

Closes the connection with the server.

◆ cmd_create()

void sptk::ImapConnect::cmd_create ( const String mail_box)
inline

Creates the new mail box.

Parameters
mail_boxstd::string, the name of the mail box

◆ cmd_delete()

void sptk::ImapConnect::cmd_delete ( const String mail_box)
inline

Deletes the new mail box.

Parameters
mail_boxstd::string, the name of the mail box

◆ cmd_examine()

void sptk::ImapConnect::cmd_examine ( const String mail_box)
inline

Retrieves the mail box information into response().

Parameters
mail_boxstd::string, the name of the mail box

◆ cmd_expunge()

void sptk::ImapConnect::cmd_expunge ( )
inline

Expanges the deleted messages in the current mail box.

◆ cmd_fetch_flags()

String sptk::ImapConnect::cmd_fetch_flags ( int32_t  msg_id)

Gets message flags

Parameters
msg_idint, the message identifier
Returns
std::string, the message flags

◆ cmd_fetch_headers()

void sptk::ImapConnect::cmd_fetch_headers ( int32_t  msg_id,
FieldList result 
)

Reatrieves the headers for the message.

Parameters
msg_idint32_t, the message identifier
resultCFieldList, the message headers information

◆ cmd_fetch_message()

void sptk::ImapConnect::cmd_fetch_message ( int32_t  msg_id,
FieldList result 
)

Reatrieves the message information.

Parameters
msg_idint, the message identifier
resultCFieldList, the complete message information

◆ cmd_list()

void sptk::ImapConnect::cmd_list ( const String mail_box_mask,
bool  decode = false 
)

Retrieves the list of mail boxes.

Parameters
mail_box_maskstd::string, the mask for the mail box names
decodebool, true if you want to convert the response into plain folder list.

◆ cmd_login()

void sptk::ImapConnect::cmd_login ( const String user,
const String password 
)

Logs in the server. The server name or address should be defined with the call of host() method.

Parameters
userstd::string&, user name on the server
passwordstd::string&, user password on the server

◆ cmd_logout()

void sptk::ImapConnect::cmd_logout ( )
inline

Logs out from the current session.

◆ cmd_noop()

void sptk::ImapConnect::cmd_noop ( )
inline

Sends NOOP command.

◆ cmd_rename()

void sptk::ImapConnect::cmd_rename ( const String mail_box,
const String new_name 
)
inline

Renames the new mail box.

Parameters
mail_boxstd::string, the name of the mail box
new_namestd::string, the new name of the mail box

◆ cmd_search_all()

void sptk::ImapConnect::cmd_search_all ( String result)

Reatrieves all the messages list in the current mail box.

◆ cmd_search_new()

void sptk::ImapConnect::cmd_search_new ( String result)

Reatrieves the new messages list in the current mail box.

◆ cmd_select()

void sptk::ImapConnect::cmd_select ( const String mail_box,
int32_t &  total_msgs 
)

Selects the mail box for future operations.

Parameters
mail_boxconst std::string&, the name of the mail box
total_msgsint32_t&, returns the total messages in the mail box

◆ cmd_store_flags()

void sptk::ImapConnect::cmd_store_flags ( int32_t  msg_id,
const char *  flags 
)

Sets message flags

Parameters
msg_idint, the message identifier
flagsconst char *, the message flags

◆ cmd_subscribe()

void sptk::ImapConnect::cmd_subscribe ( const String mail_box)
inline

Subscribes the mail box to the user.

Parameters
mail_boxstd::string, the name of the mail box

◆ cmd_unsubscribe()

void sptk::ImapConnect::cmd_unsubscribe ( const String mail_box)
inline

Unsubscribes the mail box from the user.

Parameters
mail_boxstd::string, the name of the mail box

◆ command()

void sptk::ImapConnect::command ( const String cmd,
const String arg1 = "",
const String arg2 = "" 
)

Sends a command with the arguments. Arguments (if any) are automatically enquoted with double-quotes. The command is also appended with the new line characters (CRLF).

Parameters
cmdstd::string, IMAP4 command
arg1std::string, optional command argument1
arg2std::string, optional command argument2

◆ getResponse()

bool sptk::ImapConnect::getResponse ( const String ident)
protected

Gets a response from the server for a previously sent command, identified by the ident

Parameters
identstd::string, the command identifier returned by prior sendCommand().

◆ parseFolderList()

void sptk::ImapConnect::parseFolderList ( )
protected

Parses server response as a folder list (after the appropriate command), and converts the response to it

As a result, the response contains the plain list of folders.

◆ parseMessage()

void sptk::ImapConnect::parseMessage ( FieldList result,
bool  headersOnly 
)
protected

Parses server response as a message data (after the appropriate command) to the set of fields

Parameters
resultCFieldList, the set of fields with the message information.
headersOnlybool, true if we don't want to retrieve message body.

◆ parseSearch()

void sptk::ImapConnect::parseSearch ( String result) const
protected

Parses the result of SEARCH command in response. Returns results in result parameter

Parameters
resultstd::string, returns the search results.

◆ response()

const Strings & sptk::ImapConnect::response ( ) const
inline

Returns reference to a last command response.

◆ sendCommand()

String sptk::ImapConnect::sendCommand ( const String cmd)
protected

Sends a command to the server, but doesn't retrieve the server response

The new line characters (CRLF) are added to the end of every command.

Parameters
cmdstd::string, the complete text of IMAP4 command
Returns
the unique command identifier

The documentation for this class was generated from the following file:

Fri Oct 14 2022 09:58:43: SPTK 5.4.1