Commit 1a374c8c 1a374c8cbea21dabe2f7db123a559576531238db by Wojciech Polak

Reflect recent RFC compatibility changes in Python/C++.

* examples/python/mimetest.py: Update.
* include/mailutils/cpp/message.h (get_attachment_name): Overload.
* libmu_cpp/message.cc (Message::get_attachment_name): Overload.
* python/libmu_py/message.c (api_message_get_attachment_name): Update.
* python/mailutils/message.py (Message.get_attachment_name):
Add optional charset parameter. Return (name, lang) tuple.
1 parent d8ab03b0
......@@ -90,7 +90,7 @@ def message_display_parts (msg, indent):
else:
# Save the attachements.
try:
fname = part.get_attachment_name ()
fname, lang = part.get_attachment_name ()
except:
fname = util.tempname ()
......
......@@ -68,6 +68,8 @@ class Message
void save_attachment (const std::string& filename);
Message& unencapsulate ();
std::string get_attachment_name ();
std::string get_attachment_name (const std::string& charset,
char* lang=NULL);
};
}
......
......@@ -224,8 +224,25 @@ Message :: get_attachment_name ()
char *c_name;
std::string name;
/* FIXME: CS/Lang info is ignored */
int status = mu_message_aget_attachment_name (msg, &c_name, NULL);
int status = mu_message_aget_decoded_attachment_name (msg, NULL, &c_name,
NULL);
if (status)
throw Exception ("Message::get_attachment_name", status);
if (c_name) {
name = c_name;
free (c_name);
}
return name;
}
std::string
Message :: get_attachment_name (const std::string& charset, char *lang)
{
char *c_name;
std::string name;
int status = mu_message_aget_decoded_attachment_name (msg, charset.c_str (),
&c_name, &lang);
if (status)
throw Exception ("Message::get_attachment_name", status);
if (c_name) {
......
......@@ -282,14 +282,22 @@ api_message_get_attachment_name (PyObject *self, PyObject *args)
{
int status;
char *name = NULL;
char *charset = NULL;
char *lang = NULL;
PyObject *py_ret;
PyMessage *py_msg;
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
if (!PyArg_ParseTuple (args, "O!|z", &PyMessageType, &py_msg, &charset))
return NULL;
/* FIXME: CS/Lang info is ignored */
status = mu_message_aget_attachment_name (py_msg->msg, &name, NULL);
return status_object (status, PyString_FromString (name ? name : ""));
status = mu_message_aget_decoded_attachment_name (py_msg->msg, charset,
&name, &lang);
py_ret = PyTuple_New (3);
PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
PyTuple_SetItem (py_ret, 1, PyString_FromString (name ? name : ""));
PyTuple_SetItem (py_ret, 2, lang ? PyString_FromString (lang) : Py_None);
return _ro (py_ret);
}
static PyObject *
......@@ -314,12 +322,10 @@ static PyObject *
api_message_unencapsulate (PyObject *self, PyObject *args)
{
int status;
char *filename = NULL;
PyMessage *py_msg;
PyMessage *py_unen = PyMessage_NEW ();
if (!PyArg_ParseTuple (args, "O!|s", &PyMessageType, &py_msg,
&filename))
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
Py_INCREF (py_unen);
......
......@@ -138,11 +138,11 @@ class Message:
raise MessageError (status)
return uidl
def get_attachment_name (self):
status, name = message.get_attachment_name (self.msg)
def get_attachment_name (self, charset=None):
status, name, lang = message.get_attachment_name (self.msg, charset)
if status:
raise MessageError (status)
return name
return name, lang
def save_attachment (self, filename = ''):
status = message.save_attachment (self.msg, filename)
......