Camel lib: Cannot convert from `unowned string' to `unowned string[]?'

I’m trying to use the Camel library from Evolution and I’m stuck with this error:

my code:

var mimepart = new Camel.MimePart();
mimepart.set_content("bla bla", "text/plain");

valac returns this error.

error: Argument 1: Cannot convert from `unowned string' to `unowned string[]?'
       mimepart.set_content("bla bla", "text/plain");

I’m new to Vala, but if I understand it correctly string[] is an array of string. So I tried:

mimepart.set_content({"bla bla"}, "text/plain");

which only returns a warning, but also doesn’t work

warning: passing argument 2 of ‘camel_mime_part_set_content’ from incompatible pointer type [-Wincompatible-pointer-types]
  camel_mime_part_set_content (mimepart, _tmp6_, 1, "text/plain");
In file included from /usr/include/evolution-data-server/camel/camel-cipher-context.h:27,
                 from /usr/include/evolution-data-server/camel/camel.h:30,
                 from /home/pi/repos/miso/miso.vala.c:10:
/usr/include/evolution-data-server/camel/camel-mime-part.h:119:21: note: expected ‘const gchar *’ {aka ‘const char *’} but argument is of type ‘gchar **’ {aka ‘char **’}
        const gchar *data,

What would be the correct way to create a MimeMessage / MimePart? I found an C example in the wiki, but it also uses a simple string:

text = "Hello NotZed,\nTalking to yourself again?\n\n  NotZed\n";
camel_mime_part_set_content(part, text, strlen(text), "text/plain");

Hm, it seems like the bindings are incorrect here - Camel.MimePart.set_content should take a string instead of a string[] (which is why the C compiler warns you that it can’t convert from a char** (string[]) to a char* (string)).

I guess vapigen gets mixed up because of the function signature:

 * camel_mime_part_set_content:
 * @mime_part: a #CamelMimePart
 * @data: (array length=length) (nullable): data to put into the part
 * @length: length of @data
 * @type: (nullable): Content-Type of the data
 * Utility function used to set the content of a mime part object to
 * be the provided data. If @length is 0, this routine can be used as
 * a way to remove old content (in which case @data and @type are
 * ignored and may be %NULL).
camel_mime_part_set_content (CamelMimePart *mime_part,
                             const gchar *data,
                             gint length,
                             const gchar *type) /* why on earth is the type last? */

Since there’s (array length=length) and a length member afterwards Vala thinks that the function expects an array. You should open an issue about this at evolution-data-server’s bugtracker:

1 Like

I would guess Camel is expecting bytes so should be const guchar *data

Thanks, I’ll open an issue on Gnome’s Gitlab.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.