|
|
@ -24,15 +24,13 @@ using namespace std; |
|
|
|
using namespace boost::python; |
|
|
|
|
|
|
|
Message::Blob::Blob(bloblist_t *bl, bool chained) : |
|
|
|
_bl(bl), part_of_chain(chained) |
|
|
|
{ |
|
|
|
_bl(bl), part_of_chain(chained) { |
|
|
|
if (!_bl) |
|
|
|
throw bad_alloc(); |
|
|
|
} |
|
|
|
|
|
|
|
Message::Blob::Blob(object data, string mime_type, string filename) : |
|
|
|
_bl(new_bloblist(NULL, 0, NULL, NULL)), part_of_chain(false) |
|
|
|
{ |
|
|
|
_bl(new_bloblist(NULL, 0, NULL, NULL)), part_of_chain(false) { |
|
|
|
if (!_bl) |
|
|
|
throw bad_alloc(); |
|
|
|
|
|
|
@ -59,27 +57,23 @@ Message::Blob::Blob(object data, string mime_type, string filename) : |
|
|
|
} |
|
|
|
|
|
|
|
Message::Blob::Blob(const Message::Blob &second) : |
|
|
|
_bl(second._bl), part_of_chain(true) |
|
|
|
{ |
|
|
|
_bl(second._bl), part_of_chain(true) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Message::Blob::~Blob() |
|
|
|
{ |
|
|
|
Message::Blob::~Blob() { |
|
|
|
if (!part_of_chain) { |
|
|
|
free(_bl->value); |
|
|
|
free(_bl); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
string Message::Blob::_repr() |
|
|
|
{ |
|
|
|
string Message::Blob::_repr() { |
|
|
|
stringstream build; |
|
|
|
build << "Blob("; |
|
|
|
if (!_bl) { |
|
|
|
build << "b'', '', ''"; |
|
|
|
} |
|
|
|
else { |
|
|
|
} else { |
|
|
|
build << "bytes(" << _bl->size << "), "; |
|
|
|
string mime_type; |
|
|
|
if (_bl->mime_type) |
|
|
@ -116,8 +110,7 @@ int Message::Blob::getbuffer(PyObject *self, Py_buffer *view, int flags) { |
|
|
|
return PyBuffer_FillInfo(view, self, bl->value, bl->size, 0, flags); |
|
|
|
} |
|
|
|
|
|
|
|
string Message::Blob::decode(string encoding) |
|
|
|
{ |
|
|
|
string Message::Blob::decode(string encoding) { |
|
|
|
if (encoding == "") { |
|
|
|
string _mime_type = _bl->mime_type ? _bl->mime_type : ""; |
|
|
|
encoding = "ascii"; |
|
|
@ -137,8 +130,7 @@ string Message::Blob::decode(string encoding) |
|
|
|
PyBufferProcs Message::Blob::bp = {getbuffer, NULL}; |
|
|
|
|
|
|
|
Message::Message(int dir, Identity *from) |
|
|
|
: _msg(new_message((PEP_msg_direction) dir), &free_message) |
|
|
|
{ |
|
|
|
: _msg(new_message((PEP_msg_direction) dir), &free_message) { |
|
|
|
if (!_msg) |
|
|
|
throw bad_alloc(); |
|
|
|
|
|
|
@ -151,8 +143,7 @@ Message::Message(int dir, Identity *from) |
|
|
|
} |
|
|
|
|
|
|
|
Message::Message(string mimetext) |
|
|
|
: _msg(NULL, &free_message) |
|
|
|
{ |
|
|
|
: _msg(NULL, &free_message) { |
|
|
|
message *_cpy; |
|
|
|
PEP_STATUS status = mime_decode_message(mimetext.c_str(), |
|
|
|
mimetext.size(), &_cpy, NULL); |
|
|
@ -186,35 +177,29 @@ Message::Message(string mimetext) |
|
|
|
} |
|
|
|
|
|
|
|
Message::Message(const Message &second) |
|
|
|
: _msg(second._msg) |
|
|
|
{ |
|
|
|
: _msg(second._msg) { |
|
|
|
if (!_msg.get()) |
|
|
|
throw bad_alloc(); |
|
|
|
} |
|
|
|
|
|
|
|
Message::Message(message *msg) |
|
|
|
: _msg(::message_dup(msg), &free_message) |
|
|
|
{ |
|
|
|
: _msg(::message_dup(msg), &free_message) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Message::~Message() |
|
|
|
{ |
|
|
|
Message::~Message() { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Message::operator message *() |
|
|
|
{ |
|
|
|
Message::operator message *() { |
|
|
|
return _msg.get(); |
|
|
|
} |
|
|
|
|
|
|
|
Message::operator const message *() const |
|
|
|
{ |
|
|
|
Message::operator const message *() const { |
|
|
|
return _msg.get(); |
|
|
|
} |
|
|
|
|
|
|
|
string Message::_str() |
|
|
|
{ |
|
|
|
string Message::_str() { |
|
|
|
if (!(_msg->from && _msg->from->address && _msg->from->address[0])) |
|
|
|
throw out_of_range(".from_.address missing"); |
|
|
|
|
|
|
@ -246,15 +231,13 @@ string Message::_str() |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
string Message::_repr() |
|
|
|
{ |
|
|
|
string Message::_repr() { |
|
|
|
stringstream build; |
|
|
|
build << "Message(" << repr(_str()) << ")"; |
|
|
|
return build.str(); |
|
|
|
} |
|
|
|
|
|
|
|
boost::python::tuple Message::attachments() |
|
|
|
{ |
|
|
|
boost::python::tuple Message::attachments() { |
|
|
|
boost::python::list l; |
|
|
|
|
|
|
|
for (bloblist_t *bl = _msg->attachments; bl && bl->value; bl = |
|
|
@ -265,8 +248,7 @@ boost::python::tuple Message::attachments() |
|
|
|
return boost::python::tuple(l); |
|
|
|
} |
|
|
|
|
|
|
|
void Message::attachments(boost::python::list value) |
|
|
|
{ |
|
|
|
void Message::attachments(boost::python::list value) { |
|
|
|
bloblist_t *bl = new_bloblist(NULL, 0, NULL, NULL); |
|
|
|
if (!bl) |
|
|
|
throw bad_alloc(); |
|
|
@ -302,14 +284,12 @@ void Message::attachments(boost::python::list value) |
|
|
|
_msg->attachments = bl; |
|
|
|
} |
|
|
|
|
|
|
|
Message Message::encrypt() |
|
|
|
{ |
|
|
|
Message Message::encrypt() { |
|
|
|
boost::python::list extra; |
|
|
|
return encrypt_message(*this, extra, PEP_enc_PGP_MIME, 0); |
|
|
|
} |
|
|
|
|
|
|
|
Message Message::_encrypt(boost::python::list extra, int enc_format, int flags) |
|
|
|
{ |
|
|
|
Message Message::_encrypt(boost::python::list extra, int enc_format, int flags) { |
|
|
|
if (!enc_format) |
|
|
|
enc_format = PEP_enc_PGP_MIME; |
|
|
|
return encrypt_message(*this, extra, enc_format, flags); |
|
|
@ -319,8 +299,7 @@ boost::python::tuple Message::decrypt(int flags) { |
|
|
|
return pEp::PythonAdapter::decrypt_message(*this, flags); |
|
|
|
} |
|
|
|
|
|
|
|
PEP_rating Message::outgoing_rating() |
|
|
|
{ |
|
|
|
PEP_rating Message::outgoing_rating() { |
|
|
|
if (_msg->dir != PEP_dir_outgoing) |
|
|
|
throw invalid_argument("Message.dir must be outgoing"); |
|
|
|
|
|
|
@ -342,26 +321,22 @@ PEP_rating Message::outgoing_rating() |
|
|
|
return rating; |
|
|
|
} |
|
|
|
|
|
|
|
PEP_color Message::outgoing_color() |
|
|
|
{ |
|
|
|
PEP_color Message::outgoing_color() { |
|
|
|
return _color(outgoing_rating()); |
|
|
|
} |
|
|
|
|
|
|
|
Message Message::copy() |
|
|
|
{ |
|
|
|
Message Message::copy() { |
|
|
|
message *dup = message_dup(*this); |
|
|
|
if (!dup) |
|
|
|
throw bad_alloc(); |
|
|
|
return Message(dup); |
|
|
|
} |
|
|
|
|
|
|
|
Message Message::deepcopy(dict&) |
|
|
|
{ |
|
|
|
Message Message::deepcopy(dict &) { |
|
|
|
return copy(); |
|
|
|
} |
|
|
|
|
|
|
|
Message outgoing_message(Identity me) |
|
|
|
{ |
|
|
|
Message outgoing_message(Identity me) { |
|
|
|
if (me.address().empty() || me.user_id().empty()) |
|
|
|
throw runtime_error("at least address and user_id of own user needed"); |
|
|
|
|
|
|
@ -370,16 +345,14 @@ Message outgoing_message(Identity me) |
|
|
|
return m; |
|
|
|
} |
|
|
|
|
|
|
|
static object update(Identity ident) |
|
|
|
{ |
|
|
|
static object update(Identity ident) { |
|
|
|
if (ident.address().empty()) |
|
|
|
throw runtime_error("at least address needed"); |
|
|
|
update_identity(Adapter::session(), ident); |
|
|
|
return object(ident); |
|
|
|
} |
|
|
|
|
|
|
|
static boost::python::list update(boost::python::list il) |
|
|
|
{ |
|
|
|
static boost::python::list update(boost::python::list il) { |
|
|
|
for (int i = 0; i < len(il); i++) { |
|
|
|
update(extract<Identity>(il[i])); |
|
|
|
} |
|
|
@ -387,8 +360,7 @@ static boost::python::list update(boost::python::list il) |
|
|
|
return il; |
|
|
|
} |
|
|
|
|
|
|
|
Message incoming_message(string mime_text) |
|
|
|
{ |
|
|
|
Message incoming_message(string mime_text) { |
|
|
|
auto m = Message(mime_text); |
|
|
|
m.dir(PEP_dir_incoming); |
|
|
|
|
|
|
@ -410,4 +382,4 @@ Message incoming_message(string mime_text) |
|
|
|
} |
|
|
|
|
|
|
|
} // namespace PythonAdapter
|
|
|
|
} // namespace pEp {
|
|
|
|
} // namespace pEp
|
|
|
|