Commit 7e90b785 7e90b785792197188501d8dfc78f8e3057634796 by Wojciech Polak

Initial version of libmu_cpp.

1 parent 346f0be9
## Process this file with GNU Automake to create Makefile.in
##
## Copyright (C) 2004 Free Software Foundation, Inc.
##
## GNU Mailutils is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2, or (at
## your option) any later version.
##
## GNU Mailutils is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with GNU Mailutils; if not, write to the Free Software
## Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
MU_CXX_INCLUDES = \
address.h\
error.h\
filter.h\
header.h\
iterator.h\
list.h\
mailbox.h\
mailcap.h\
mailer.h\
mailutils.h\
message.h\
pop3.h\
stream.h\
url.h
pkginclude_HEADERS = @MU_CXX_INCLUDES@
EXTRA_HEADERS = '$(MU_CXX_INCLUDES)'
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _ADDRESS_H
#define _ADDRESS_H
#include <iostream>
#include <mailutils/address.h>
#include <mailutils/cpp/error.h>
namespace mailutils
{
class Address
{
private:
char buf[256];
protected:
address_t addr;
friend class Mailer;
public:
Address (const std::string&);
Address (const address_t);
~Address ();
size_t GetCount ();
bool IsGroup (size_t);
std::string GetEmail (size_t);
std::string GetLocalPart (size_t);
std::string GetDomain (size_t);
std::string GetPersonal (size_t);
std::string GetComments (size_t);
std::string GetRoute (size_t);
// Address Exceptions
class EInval : public Exception {
public:
EInval (const std::string& m, int s) : Exception (m, s) {}
};
class ENoent : public Exception {
public:
ENoent (const std::string& m, int s) : Exception (m, s) {}
};
};
}
#endif // not _ADDRESS_H
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _ERROR_H
#define _ERROR_H
#include <iostream>
#include <string>
#include <mailutils/errno.h>
namespace mailutils
{
class Exception
{
protected:
std::string method;
std::string msgerr;
public:
Exception (const std::string m, int s) {
method = m;
msgerr = mu_strerror (s);
}
std::string Method () const {
return method;
}
std::string MsgError () const {
return msgerr;
}
};
}
#endif /* not _ERROR_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _FILTER_H
#define _FILTER_H
#include <iostream>
#include <mailutils/filter.h>
#include <mailutils/cpp/stream.h>
namespace mailutils
{
class FilterStream : public Stream
{
private:
Stream *input;
public:
void Create (Stream&, const std::string&, int, int);
void IconvCreate (Stream&, const std::string&,
const std::string&, int,
enum mu_iconv_fallback_mode);
};
}
#endif // not _FILTER_H
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _HEADER_H
#define _HEADER_H
#include <iostream>
#include <string>
#include <mailutils/header.h>
namespace mailutils
{
class Header
{
protected:
header_t hdr;
public:
Header ();
Header (const header_t);
std::string GetValue (const std::string&);
std::string operator [] (const std::string&);
};
}
#endif // not _HEADER_H
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _ITERATOR_H
#define _ITERATOR_H
#include <iostream>
#include <mailutils/iterator.h>
#include <mailutils/cpp/list.h>
namespace mailutils
{
class Iterator
{
protected:
iterator_t mu_iter;
List* pList;
public:
Iterator (const List&);
Iterator (const iterator_t);
~Iterator ();
void Dup (Iterator*&, const Iterator&);
void First ();
void Next ();
Iterator& operator ++ (int);
void Current (void**);
void* Current ();
bool IsDone ();
List& GetList ();
};
}
#endif // not _ITERATOR_H
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LIST_H
#define _LIST_H
#include <iostream>
#include <mailutils/list.h>
typedef int list_action_t (void*, void*);
typedef int (*list_comparator_t) (const void*, const void*);
namespace mailutils
{
class List
{
protected:
list_t mu_list;
friend class Iterator;
public:
List ();
List (const list_t);
~List ();
void Append (void*);
void Prepend (void*);
void Insert (void*, void*);
void Remove (void*);
void Replace (void*, void*);
void Get (size_t, void**);
void* Get (size_t);
void* operator [] (size_t);
void ToArray (void**, size_t, size_t*);
void Locate (void*, void**);
void Do (list_action_t*, void*);
list_comparator_t SetComparator (list_comparator_t);
void SetDestroyItem (void (*destoy_item) (void *));
bool IsEmpty ();
size_t Count ();
};
}
#endif // not _LIST_H
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _MAILBOX_H
#define _MAILBOX_H
#include <iostream>
#include <mailutils/mailbox.h>
#include <mailutils/cpp/message.h>
namespace mailutils
{
class MailboxBase
{
protected:
mailbox_t mbox;
public:
void Open (int);
void Close ();
size_t MessagesCount ();
Message& GetMessage (size_t);
Message& operator [] (size_t);
};
class Mailbox : public MailboxBase
{
public:
Mailbox (const std::string&);
Mailbox (const mailbox_t);
~Mailbox ();
};
class MailboxDefault : public MailboxBase
{
public:
MailboxDefault (const std::string&);
MailboxDefault (const mailbox_t);
~MailboxDefault ();
};
}
#endif /* not _MAILBOX_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _MAILCAP_H
#define _MAILCAP_H
#include <iostream>
#include <mailutils/mailcap.h>
#include <mailutils/cpp/stream.h>
namespace mailutils
{
class MailcapEntry
{
private:
char buf[256];
protected:
mu_mailcap_entry_t entry;
public:
MailcapEntry (mu_mailcap_entry_t);
size_t FieldsCount ();
std::string GetTypeField ();
std::string GetViewCommand ();
std::string GetField (size_t);
};
class Mailcap
{
protected:
mu_mailcap_t mailcap;
public:
Mailcap (const Stream&);
Mailcap (const mu_mailcap_t);
~Mailcap ();
size_t GetCount ();
MailcapEntry& GetEntry (size_t);
};
}
#endif // not _MAILCAP_H
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _MAILER_H
#define _MAILER_H
#include <iostream>
#include <string>
#include <mailutils/mailer.h>
#include <mailutils/cpp/message.h>
#include <mailutils/cpp/address.h>
namespace mailutils
{
class Mailer
{
protected:
mailer_t mailer;
public:
Mailer (const std::string&);
Mailer (const mailer_t);
~Mailer ();
void Open (int);
void Close ();
void SendMessage (const Message&, const Address&, const Address&);
};
}
#endif // not _MAILER_H
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <mailutils/cpp/address.h>
#include <mailutils/cpp/error.h>
#include <mailutils/cpp/filter.h>
#include <mailutils/cpp/header.h>
#include <mailutils/cpp/iterator.h>
#include <mailutils/cpp/list.h>
#include <mailutils/cpp/mailbox.h>
#include <mailutils/cpp/mailcap.h>
#include <mailutils/cpp/mailer.h>
#include <mailutils/cpp/message.h>
#include <mailutils/cpp/pop3.h>
#include <mailutils/cpp/stream.h>
#include <mailutils/cpp/url.h>
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _MESSAGE_H
#define _MESSAGE_H
#include <mailutils/message.h>
#include <mailutils/cpp/header.h>
namespace mailutils
{
class Message
{
protected:
message_t msg;
friend class Mailer;
public:
Message ();
Message (const message_t);
Header& GetHeader ();
};
}
#endif // not _MESSAGE_H
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _POP3_H
#define _POP3_H
#include <iostream>
#include <mailutils/pop3.h>
#include <mailutils/cpp/list.h>
#include <mailutils/cpp/stream.h>
namespace mailutils
{
class Pop3
{
protected:
mu_pop3_t pop3;
Stream* pStream;
public:
Pop3 ();
Pop3 (const mu_pop3_t);
~Pop3 ();
void SetCarrier (const Stream&);
Stream& GetCarrier ();
void Connect ();
void Disconnect ();
void SetTimeout (int);
int GetTimeout ();
void Stls ();
Iterator& Capa ();
void Dele (unsigned int);
size_t List (unsigned int);
Iterator& ListAll ();
void Noop ();
void Pass (const char*);
void Quit ();
Stream& Retr (unsigned int);
void Rset ();
void Stat (unsigned int*, size_t*);
Stream& Top (unsigned int, unsigned int);
void User (const char*);
size_t ReadLine (char*, size_t);
size_t Response (char*, size_t);
void SendLine (const char*);
void Send ();
};
}
#endif // not _POP3_H
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _STREAM_H
#define _STREAM_H
#include <iostream>
#include <string>
#include <cstdio>
#include <mailutils/stream.h>
#include <mailutils/cpp/error.h>
namespace mailutils
{
class Stream
{
protected:
stream_t stm;
size_t readn;
size_t writen;
int wflags;
bool opened;
size_t reference_count;
// Inlines
void reference () {
reference_count++;
}
bool dereference () {
return --reference_count == 0;
}
// Friends
friend class FilterStream;
friend class FilterProgStream;
friend class Mailcap;
friend class Pop3;
public:
Stream ();
Stream (Stream& s);
Stream (const stream_t);
~Stream ();
void Open ();
void Close ();
void SetWaitFlags (int);
void Wait (); // timeval is missing
void Wait (int); // timeval is missing
void Read (char*, size_t, off_t);
void Write (const std::string&, size_t, off_t);
void ReadLine (char*, size_t, off_t);
void SequentialReadLine (char*, size_t);
void SequentialWrite (const std::string&, size_t);
void Flush ();
// Inlines
size_t GetReadn () const {
return readn;
};
size_t GetWriten () const {
return writen;
};
friend Stream& operator << (Stream&, const std::string&);
friend Stream& operator >> (Stream&, std::string&);
// Stream Exceptions
class EAgain : public Exception {
public:
EAgain (const std::string& m, int s) : Exception (m, s) {}
};
};
class TcpStream : public Stream
{
public:
TcpStream (const std::string&, int, int);
};
class FileStream : public Stream
{
public:
FileStream (const std::string&, int);
};
class StdioStream : public Stream
{
public:
StdioStream (FILE*, int);
};
class ProgStream : public Stream
{
public:
ProgStream (const std::string&, int);
};
class FilterProgStream : public Stream
{
private:
Stream *input;
public:
FilterProgStream (const std::string&, Stream&);
FilterProgStream (const std::string&, Stream*);
};
}
#endif // not _STREAM_H
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _URL_H
#define _URL_H
#include <iostream>
#include <string>
#include <mailutils/url.h>
namespace mailutils
{
class Url
{
private:
char buf[1024];
protected:
url_t url;
public:
Url (const std::string&);
Url (const char*);
Url (const url_t);
~Url ();
void Parse ();
long GetPort ();
std::string GetScheme ();
std::string GetUser ();
std::string GetPasswd ();
std::string GetAuth ();
std::string GetHost ();
std::string GetPath ();
std::string GetQuery ();
};
}
#endif // not _URL_H
## Process this file with GNU Automake to create Makefile.in
##
## Copyright (C) 2004 Free Software Foundation, Inc.
##
## GNU Mailutils is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
INCLUDES = -I${top_srcdir}/include -I${top_srcdir}/mailbox\
-I${top_srcdir}/mailbox/include\
-I${top_builddir}/include/mailutils/gnu \
@INTLINCS@
MU_CXX_LIBS = libmu_cpp.la
lib_LTLIBRARIES = @MU_CXX_LIBS@
EXTRA_LTLIBRARIES = $(MU_CXX_LIBS)
libmu_cpp_la_SOURCES = \
address.cc\
filter.cc\
header.cc\
iterator.cc\
list.cc\
mailbox.cc\
mailcap.cc\
mailer.cc\
message.cc\
pop3.cc\
stream.cc\
url.cc
libmu_cpp_la_DEPENDENCIES = @MU_LTLIBOBJS@
libmu_cpp_la_LIBADD = @MU_LTLIBOBJS@ @MU_COMMON_LIBRARIES@
libmu_cpp_la_LDFLAGS = -version-info 0:0:0
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <mailutils/cpp/address.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// Address
//
Address :: Address (const std::string& str)
{
int status = address_create (&addr, str.c_str ());
if (status)
throw Exception ("Address::Address", status);
}
Address :: Address (const address_t addr)
{
if (addr == 0)
throw Exception ("Address::Address", EINVAL);
this->addr = addr;
}
Address :: ~Address ()
{
address_destroy (&addr);
}
bool
Address :: IsGroup (size_t n)
{
int isgroup;
int status = address_is_group (addr, n, &isgroup);
if (status == EINVAL)
throw Address::EInval ("Address::IsGroup", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::IsGroup", status);
return (bool) isgroup;
}
size_t
Address :: GetCount ()
{
size_t count;
address_get_count (addr, &count);
return count;
}
std::string
Address :: GetEmail (size_t n)
{
int status = address_get_email (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::GetEmail", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::GetEmail", status);
return std::string (buf);
}
std::string
Address :: GetLocalPart (size_t n)
{
int status = address_get_local_part (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::GetLocalPart", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::GetLocalPart", status);
return std::string (buf);
}
std::string
Address :: GetDomain (size_t n)
{
int status = address_get_domain (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::GetDomain", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::GetDomain", status);
return std::string (buf);
}
std::string
Address :: GetPersonal (size_t n)
{
int status = address_get_personal (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::GetPersonal", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::GetPersonal", status);
return std::string (buf);
}
std::string
Address :: GetComments (size_t n)
{
int status = address_get_comments (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::GetComments", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::GetComments", status);
return std::string (buf);
}
std::string
Address :: GetRoute (size_t n)
{
int status = address_get_route (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::GetRoute", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::GetRoute", status);
return std::string (buf);
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <mailutils/cpp/filter.h>
using namespace mailutils;
//
// FilterStream
//
void
FilterStream :: Create (Stream& transport,
const std::string& code,
int mode, int flag)
{
int status = filter_create (&this->stm,
transport.stm,
code.c_str (),
mode, flag);
if (status)
throw Exception ("FilterStream::Create", status);
this->input = new Stream (transport);
}
void
FilterStream :: IconvCreate (Stream& transport,
const std::string& fromcode,
const std::string& tocode,
int flags,
enum mu_iconv_fallback_mode fallback_mode)
{
int status = filter_iconv_create (&this->stm, transport.stm,
fromcode.c_str (),
tocode.c_str (),
flags, fallback_mode);
if (status)
throw Exception ("FilterStream::IconvCreate", status);
this->input = new Stream (transport);
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <mailutils/cpp/header.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// Header
//
Header :: Header ()
{
}
Header :: Header (const header_t hdr)
{
if (hdr == 0)
throw Exception ("Header::Header", EINVAL);
this->hdr = hdr;
}
std::string
Header :: GetValue (const std::string& name)
{
char* c_val;
int status = header_aget_value (hdr, name.c_str (), &c_val);
if (status)
throw Exception ("Header::GetValue", status);
std::string val (c_val);
free (c_val);
return val;
}
std::string
Header :: operator [] (const std::string& name)
{
return this->GetValue (name);
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <mailutils/cpp/iterator.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// Iterator
//
Iterator :: Iterator (const List& lst)
{
int status = list_get_iterator (lst.mu_list, &mu_iter);
if (status)
throw Exception ("Iterator::Iterator", status);
this->pList = (List*) &lst;
}
Iterator :: Iterator (const iterator_t iter)
{
if (iter == 0)
throw Exception ("Iterator::Iterator", EINVAL);
this->mu_iter = iter;
this->pList = 0;
}
Iterator :: ~Iterator ()
{
iterator_destroy (&mu_iter);
}
void
Iterator :: First ()
{
iterator_first (mu_iter);
}
void
Iterator :: Next ()
{
iterator_next (mu_iter);
}
Iterator&
Iterator :: operator ++ (int)
{
iterator_next (mu_iter);
return *this;
}
void
Iterator :: Current (void** pitem)
{
int status = iterator_current (mu_iter, pitem);
if (status)
throw Exception ("Iterator::Current", status);
}
void*
Iterator :: Current ()
{
void* pitem;
int status = iterator_current (mu_iter, &pitem);
if (status)
throw Exception ("Iterator::Current", status);
return pitem;
}
bool
Iterator :: IsDone ()
{
return (bool) iterator_is_done (mu_iter);
}
List&
Iterator :: GetList ()
{
if (!pList)
throw Exception ("Iterator::GetList", ENOTSUP);
return *pList;
}
void
Iterator :: Dup (Iterator*& piter, const Iterator& orig)
{
iterator_t iter;
int status = iterator_dup (&iter, orig.mu_iter);
if (status)
throw Exception ("Iterator::Dup", status);
piter->mu_iter = iter;
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <mailutils/cpp/list.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// List
//
List :: List ()
{
int status = list_create (&mu_list);
if (status)
throw Exception ("List::List", status);
}
List :: List (const list_t lst)
{
if (lst == 0)
throw Exception ("List::List", EINVAL);
this->mu_list = lst;
}
List :: ~List ()
{
list_destroy (&mu_list);
}
void
List :: Append (void* item)
{
int status = list_append (mu_list, item);
if (status)
throw Exception ("List::Append", status);
}
void
List :: Prepend (void* item)
{
int status = list_prepend (mu_list, item);
if (status)
throw Exception ("List::Prepend", status);
}
void
List :: Insert (void* item, void* new_item)
{
int status = list_insert (mu_list, item, new_item);
if (status)
throw Exception ("List::Insert", status);
}
void
List :: Remove (void* item)
{
int status = list_remove (mu_list, item);
if (status)
throw Exception ("List::Remove", status);
}
void
List :: Replace (void* old_item, void* new_item)
{
int status = list_replace (mu_list, old_item, new_item);
if (status)
throw Exception ("List::Replace", status);
}
void
List :: Get (size_t index, void** pitem)
{
int status = list_get (mu_list, index, pitem);
if (status)
throw Exception ("List::Get", status);
}
void*
List :: Get (size_t index)
{
void* pitem;
int status = list_get (mu_list, index, &pitem);
if (status)
throw Exception ("List::Get", status);
return pitem;
}
void*
List :: operator [] (size_t index)
{
return this->Get (index);
}
void
List :: ToArray (void** array, size_t count, size_t* pcount)
{
int status = list_to_array (mu_list, array, count, pcount);
if (status)
throw Exception ("List::ToArray", status);
}
void
List :: Locate (void* item, void** ret_item)
{
int status = list_locate (mu_list, item, ret_item);
if (status)
throw Exception ("List::Locate", status);
}
bool
List :: IsEmpty ()
{
return (bool) list_is_empty (mu_list);
}
size_t
List :: Count ()
{
size_t count = 0;
int status = list_count (mu_list, &count);
if (status)
throw Exception ("List::Count", status);
return count;
}
void
List :: Do (list_action_t* action, void* cbdata)
{
int status = list_do (mu_list, action, cbdata);
if (status)
throw Exception ("List::Do", status);
}
list_comparator_t
List :: SetComparator (list_comparator_t comp)
{
return list_set_comparator (mu_list, comp);
}
void
List :: SetDestroyItem (void (*destroy_item) (void *item))
{
int status = list_set_destroy_item (mu_list, destroy_item);
if (status)
throw Exception ("List::SetDestroyItem", status);
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <mailutils/cpp/mailbox.h>
#include <mailutils/cpp/message.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// MailboxBase
//
void
MailboxBase :: Open (int flag)
{
int status = mailbox_open (mbox, flag);
if (status)
throw Exception ("MailboxBase::Open", status);
}
void
MailboxBase :: Close ()
{
int status = mailbox_close (mbox);
if (status)
throw Exception ("MailboxBase::Close", status);
}
size_t
MailboxBase :: MessagesCount ()
{
size_t total;
mailbox_messages_count (mbox, &total);
return total;
}
Message&
MailboxBase :: GetMessage (size_t num)
{
message_t c_msg;
int status = mailbox_get_message (mbox, num, &c_msg);
if (status)
throw Exception ("MailboxBase::GetMessage", status);
return *new Message (c_msg);
}
Message&
MailboxBase :: operator [] (size_t num)
{
return this->GetMessage (num);
}
//
// Mailbox
//
Mailbox :: Mailbox (const std::string& name)
{
int status = mailbox_create (&mbox, name.c_str ());
if (status)
throw Exception ("Mailbox::Mailbox", status);
}
Mailbox :: Mailbox (const mailbox_t mbox)
{
if (mbox == 0)
throw Exception ("Mailbox::Mailbox", EINVAL);
this->mbox = mbox;
}
Mailbox :: ~Mailbox ()
{
mailbox_destroy (&mbox);
}
//
// MailboxDefault
//
MailboxDefault :: MailboxDefault (const std::string& name)
{
int status = mailbox_create_default (&mbox, name.c_str ());
if (status)
throw Exception ("MailboxDefault::MailboxDefault", status);
}
MailboxDefault :: MailboxDefault (const mailbox_t mbox)
{
if (mbox == 0)
throw Exception ("MailboxDefault::MailboxDefault", EINVAL);
this->mbox = mbox;
}
MailboxDefault :: ~MailboxDefault ()
{
mailbox_destroy (&mbox);
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <mailutils/cpp/mailcap.h>
#include <mailutils/cpp/stream.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// Mailcap
//
Mailcap :: Mailcap (const Stream& stm)
{
int status = mu_mailcap_create (&mailcap, stm.stm);
if (status)
throw Exception ("Mailcap::Mailcap", status);
}
Mailcap :: Mailcap (const mu_mailcap_t mailcap)
{
if (mailcap == 0)
throw Exception ("Mailcap::Mailcap", EINVAL);
this->mailcap = mailcap;
}
Mailcap :: ~Mailcap ()
{
mu_mailcap_destroy (&mailcap);
}
size_t
Mailcap :: GetCount ()
{
size_t count = 0;
int status = mu_mailcap_entries_count (mailcap, &count);
if (status)
throw Exception ("Mailcap::GetCount", status);
return count;
}
MailcapEntry&
Mailcap :: GetEntry (size_t i)
{
mu_mailcap_entry_t c_entry;
int status = mu_mailcap_get_entry (mailcap, i, &c_entry);
if (status)
throw Exception ("Mailcap::GetEntry", status);
MailcapEntry* entry = new MailcapEntry (c_entry);
return *entry;
}
//
// MailcapEntry
//
MailcapEntry :: MailcapEntry (mu_mailcap_entry_t entry)
{
if (entry == 0)
throw Exception ("MailcapEntry::MailcapEntry", EINVAL);
this->entry = entry;
}
size_t
MailcapEntry :: FieldsCount ()
{
size_t count = 0;
int status = mu_mailcap_entry_fields_count (entry, &count);
if (status)
throw Exception ("MailcapEntry::FieldsCount", status);
return count;
}
std::string
MailcapEntry :: GetField (size_t i)
{
int status = mu_mailcap_entry_get_field (entry, i, buf,
sizeof (buf), NULL);
if (status)
throw Exception ("MailcapEntry::GetField", status);
return std::string (buf);
}
std::string
MailcapEntry :: GetTypeField ()
{
int status = mu_mailcap_entry_get_typefield (entry, buf,
sizeof (buf), NULL);
if (status)
throw Exception ("MailcapEntry::GetTypeField", status);
return std::string (buf);
}
std::string
MailcapEntry :: GetViewCommand ()
{
int status = mu_mailcap_entry_get_viewcommand (entry, buf,
sizeof (buf), NULL);
if (status)
throw Exception ("MailcapEntry::GetViewCommand", status);
return std::string (buf);
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <mailutils/cpp/mailer.h>
#include <errno.h>
using namespace mailutils;
//
// Mailer
//
Mailer :: Mailer (const std::string& url)
{
int status = mailer_create (&mailer, url.c_str ());
if (status)
throw Exception ("Mailer::Mailer", status);
}
Mailer :: Mailer (const mailer_t mailer)
{
if (mailer == 0)
throw Exception ("Mailer::Mailer", EINVAL);
this->mailer = mailer;
}
Mailer :: ~Mailer ()
{
mailer_destroy (&mailer);
}
void
Mailer :: Open (int flags)
{
int status = mailer_open (mailer, flags);
if (status)
throw Exception ("Mailer::Open", status);
}
void
Mailer :: Close ()
{
int status = mailer_close (mailer);
if (status)
throw Exception ("Mailer::Close", status);
}
void
Mailer :: SendMessage (const Message& msg, const Address& from,
const Address& to)
{
int status = mailer_send_message (mailer, msg.msg,
from.addr, to.addr);
if (status)
throw Exception ("Mailer::SendMessage", status);
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <mailutils/cpp/message.h>
#include <mailutils/cpp/header.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// Message
//
Message :: Message ()
{
}
Message :: Message (const message_t msg)
{
if (msg == 0)
throw Exception ("Message::Message", EINVAL);
this->msg = msg;
}
Header&
Message :: GetHeader ()
{
header_t c_hdr;
int status = message_get_header (msg, &c_hdr);
if (status)
throw Exception ("Message::GetHeader", status);
return *new Header (c_hdr);
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <mailutils/cpp/pop3.h>
#include <mailutils/cpp/iterator.h>
#include <errno.h>
using namespace mailutils;
//
// POP3
//
Pop3 :: Pop3 ()
{
int status = mu_pop3_create (&pop3);
if (status)
throw Exception ("Pop3::Pop3", status);
this->pStream = 0;
}
Pop3 :: Pop3 (const mu_pop3_t pop3)
{
if (pop3 == 0)
throw Exception ("Pop3::Pop3", EINVAL);
this->pop3 = pop3;
this->pStream = 0;
}
Pop3 :: ~Pop3 ()
{
mu_pop3_destroy (&pop3);
}
void
Pop3 :: SetCarrier (const Stream& carrier)
{
int status = mu_pop3_set_carrier (pop3, carrier.stm);
if (status)
throw Exception ("Pop3::SetCarrier", status);
this->pStream = (Stream*) &carrier;
}
Stream&
Pop3 :: GetCarrier ()
{
return *pStream;
}
void
Pop3 :: Connect ()
{
int status = mu_pop3_connect (pop3);
if (status)
throw Exception ("Pop3::Connect", status);
}
void
Pop3 :: Disconnect ()
{
int status = mu_pop3_disconnect (pop3);
if (status)
throw Exception ("Pop3::Disconnect", status);
}
void
Pop3 :: SetTimeout (int timeout)
{
int status = mu_pop3_set_timeout (pop3, timeout);
if (status)
throw Exception ("Pop3::SetTimeout", status);
}
int
Pop3 :: GetTimeout ()
{
int timeout;
int status = mu_pop3_get_timeout (pop3, &timeout);
if (status)
throw Exception ("Pop3::GetTimeout", status);
return timeout;
}
void
Pop3 :: Stls ()
{
int status = mu_pop3_stls (pop3);
if (status)
throw Exception ("Pop3::Stls", status);
}
Iterator&
Pop3 :: Capa ()
{
iterator_t mu_itr;
int status = mu_pop3_capa (pop3, &mu_itr);
if (status)
throw Exception ("Pop3::Capa", status);
return *new Iterator (mu_itr);
}
void
Pop3 :: Dele (unsigned int msgno)
{
int status = mu_pop3_dele (pop3, msgno);
if (status)
throw Exception ("Pop3::Dele", status);
}
size_t
Pop3 :: List (unsigned int msgno)
{
size_t msg_octet;
int status = mu_pop3_list (pop3, msgno, &msg_octet);
if (status)
throw Exception ("Pop3::List", status);
return msg_octet;
}
Iterator&
Pop3 :: ListAll ()
{
iterator_t mu_itr;
int status = mu_pop3_list_all (pop3, &mu_itr);
if (status)
throw Exception ("Pop3::ListAll", status);
return *new Iterator (mu_itr);
}
void
Pop3 :: Noop ()
{
int status = mu_pop3_noop (pop3);
if (status)
throw Exception ("Pop3::Noop", status);
}
void
Pop3 :: Pass (const char* pass)
{
int status = mu_pop3_pass (pop3, pass);
if (status)
throw Exception ("Pop3::Pass", status);
}
void
Pop3 :: Quit ()
{
int status = mu_pop3_quit (pop3);
if (status)
throw Exception ("Pop3::Quit", status);
}
Stream&
Pop3 :: Retr (unsigned int msgno)
{
stream_t c_stm;
int status = mu_pop3_retr (pop3, msgno, &c_stm);
if (status)
throw Exception ("Pop3::Retr", status);
return *new Stream (c_stm);
}
void
Pop3 :: Rset ()
{
int status = mu_pop3_rset (pop3);
if (status)
throw Exception ("Pop3::Rset", status);
}
void
Pop3 :: Stat (unsigned int* count, size_t* octets)
{
int status = mu_pop3_stat (pop3, count, octets);
if (status)
throw Exception ("Pop3::Stat", status);
}
Stream&
Pop3 :: Top (unsigned int msgno, unsigned int lines)
{
stream_t c_stm;
int status = mu_pop3_top (pop3, msgno, lines, &c_stm);
if (status)
throw Exception ("Pop3::Top", status);
return *new Stream (c_stm);
}
void
Pop3 :: User (const char* user)
{
int status = mu_pop3_user (pop3, user);
if (status)
throw Exception ("Pop3::User", status);
}
size_t
Pop3 :: ReadLine (char* buf, size_t buflen)
{
size_t nread;
int status = mu_pop3_readline (pop3, buf, buflen, &nread);
if (status)
throw Exception ("Pop3::ReadLine", status);
}
size_t
Pop3 :: Response (char* buf, size_t buflen)
{
size_t nread;
int status = mu_pop3_response (pop3, buf, buflen, &nread);
if (status)
throw Exception ("Pop3::Response", status);
}
void
Pop3 :: SendLine (const char* line)
{
int status = mu_pop3_sendline (pop3, line);
if (status)
throw Exception ("Pop3::SendLine", status);
}
void
Pop3 :: Send ()
{
int status = mu_pop3_send (pop3);
if (status)
throw Exception ("Pop3::Send", status);
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <mailutils/cpp/stream.h>
#include <errno.h>
using namespace mailutils;
//
// Stream
//
Stream :: Stream ()
{
this->stm = 0;
this->opened = false;
reference ();
}
Stream :: Stream (const stream_t stm)
{
if (stm == 0)
throw Exception ("Stream::Stream", EINVAL);
this->stm = stm;
this->opened = false;
reference ();
}
Stream :: Stream (Stream& s)
{
s.reference ();
this->stm = s.stm;
}
Stream :: ~Stream ()
{
if (dereference ())
{
Close ();
if (this->stm)
stream_destroy (&stm, NULL);
}
}
void
Stream :: Open ()
{
int status = stream_open (stm);
if (status == EAGAIN)
throw Stream::EAgain ("Stream::Open", status);
else if (status)
throw Exception ("Stream::Open", status);
this->opened = true;
}
void
Stream :: Close ()
{
if (this->opened)
{
int status = stream_close (stm);
if (status)
throw Exception ("Stream::Close", status);
this->opened = false;
}
}
void
Stream :: SetWaitFlags (int flags)
{
this->wflags = flags;
}
void
Stream :: Wait ()
{
int status = stream_wait (stm, &wflags, NULL);
if (status)
throw Exception ("Stream::Wait", status);
}
void
Stream :: Wait (int flags)
{
this->wflags = flags;
int status = stream_wait (stm, &wflags, NULL);
if (status)
throw Exception ("Stream::Wait", status);
}
void
Stream :: Read (char* rbuf, size_t size, off_t offset)
{
int status = stream_read (stm, rbuf, size, offset, &readn);
if (status == EAGAIN)
throw Stream::EAgain ("Stream::Read", status);
else if (status)
throw Exception ("Stream::Read", status);
}
void
Stream :: Write (const std::string& wbuf, size_t size, off_t offset)
{
int status = stream_write (stm, wbuf.c_str (), size, offset, &writen);
if (status == EAGAIN)
throw Stream::EAgain ("Stream::Write", status);
else if (status)
throw Exception ("Stream::Write", status);
}
void
Stream :: ReadLine (char* rbuf, size_t size, off_t offset)
{
int status = stream_readline (stm, rbuf, size, offset, &readn);
if (status == EAGAIN)
throw Stream::EAgain ("Stream::ReadLine", status);
else if (status)
throw Exception ("Stream::ReadLine", status);
}
void
Stream :: SequentialReadLine (char* rbuf, size_t size)
{
int status = stream_sequential_readline (stm, rbuf, size, &readn);
if (status)
throw Exception ("Stream::SequentialReadLine", status);
}
void
Stream :: SequentialWrite (const std::string& wbuf, size_t size)
{
int status = stream_sequential_write (stm, wbuf.c_str (), size);
if (status)
throw Exception ("Stream::SequentialWrite", status);
}
void
Stream :: Flush ()
{
int status = stream_flush (stm);
if (status)
throw Exception ("Stream::Flush", status);
}
namespace mailutils
{
Stream&
operator << (Stream& stm, const std::string& wbuf)
{
stm.Write (wbuf, wbuf.length (), 0);
return stm;
}
Stream&
operator >> (Stream& stm, std::string& rbuf)
{
char tmp[1024];
stm.Read (tmp, sizeof (tmp), 0);
rbuf = std::string (tmp);
return stm;
}
}
//
// TcpStream
//
TcpStream :: TcpStream (const std::string& host, int port, int flags)
{
int status = tcp_stream_create (&stm, host.c_str (), port, flags);
if (status)
throw Exception ("TcpStream::TcpStream", status);
}
//
// FileStream
//
FileStream :: FileStream (const std::string& filename, int flags)
{
int status = file_stream_create (&stm, filename.c_str (), flags);
if (status)
throw Exception ("FileStream::FileStream", status);
}
//
// StdioStream
//
StdioStream :: StdioStream (FILE* fp, int flags)
{
int status = stdio_stream_create (&stm, fp, flags);
if (status)
throw Exception ("StdioStream::StdioStream", status);
}
//
// ProgStream
//
ProgStream :: ProgStream (const std::string& progname, int flags)
{
int status = prog_stream_create (&stm, progname.c_str (), flags);
if (status)
throw Exception ("ProgStream::ProgStream", status);
}
//
// FilterProgStream
//
FilterProgStream :: FilterProgStream (const std::string& progname,
Stream& input)
{
int status = filter_prog_stream_create (&stm, progname.c_str (),
input.stm);
this->input = new Stream (input);
if (status)
throw Exception ("FilterProgStream::FilterProgStream", status);
}
FilterProgStream :: FilterProgStream (const std::string& progname,
Stream* input)
{
int status = filter_prog_stream_create (&stm, progname.c_str (),
input->stm);
this->input = new Stream (*input);
if (status)
throw Exception ("FilterProgStream::FilterProgStream", status);
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <mailutils/cpp/url.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// Url
//
Url :: Url (const std::string& str)
{
int status = url_create (&url, str.c_str ());
if (status)
throw Exception ("Url::Url", status);
}
Url :: Url (const char* str)
{
int status = url_create (&url, str);
if (status)
throw Exception ("Url::Url", status);
}
Url :: Url (const url_t url)
{
if (url == 0)
throw Exception ("Url::Url", EINVAL);
this->url = url;
}
Url :: ~Url ()
{
url_destroy (&url);
}
void
Url :: Parse ()
{
int status = url_parse (url);
if (status)
throw Exception ("Url::Parse", status);
}
long
Url :: GetPort ()
{
long port;
int status = url_get_port (url, &port);
if (status)
throw Exception ("Url::GetPort", status);
return port;
}
std::string
Url :: GetScheme ()
{
int status = url_get_scheme (url, buf, sizeof (buf), NULL);
if (status)
throw Exception ("Url::GetScheme", status);
return std::string (buf);
}
std::string
Url :: GetUser ()
{
int status = url_get_user (url, buf, sizeof (buf), NULL);
if (status)
throw Exception ("Url::GetUser", status);
return std::string (buf);
}
std::string
Url :: GetPasswd ()
{
int status = url_get_passwd (url, buf, sizeof (buf), NULL);
if (status)
throw Exception ("Url::GetPasswd", status);
return std::string (buf);
}
std::string
Url :: GetAuth ()
{
int status = url_get_auth (url, buf, sizeof (buf), NULL);
if (status)
throw Exception ("Url::GetAuth", status);
return std::string (buf);
}
std::string
Url :: GetHost ()
{
int status = url_get_host (url, buf, sizeof (buf), NULL);
if (status)
throw Exception ("Url::GetHost", status);
return std::string (buf);
}
std::string
Url :: GetPath ()
{
int status = url_get_path (url, buf, sizeof (buf), NULL);
if (status)
throw Exception ("Url::GetPath", status);
return std::string (buf);
}
std::string
Url :: GetQuery ()
{
int status = url_get_query (url, buf, sizeof (buf), NULL);
if (status)
throw Exception ("Url::GetQuery", status);
return std::string (buf);
}