mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-04 09:53:25 +00:00
plug-ins: xdg-email is a runtime dependency.
This commit is contained in:
parent
8c4d03ada8
commit
05f7726eab
2 changed files with 119 additions and 100 deletions
25
configure.ac
25
configure.ac
|
@ -1855,26 +1855,15 @@ if test "x$with_sendmail" != "x" && test "x$with_sendmail" != "xno"; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_ARG_WITH(xdg_email,[ --with-xdg-email[=DIR] set xdg-email command location])
|
if test "x$have_sendmail" = xno; then
|
||||||
|
AC_PATH_PROG(XDG_EMAIL, xdg-email)
|
||||||
have_xdg_email=no
|
|
||||||
if test "x$have_sendmail" = xno && test "x$with_xdg_email" != "xno"; then
|
|
||||||
if test "x$with_xdg_email" != "xyes" && test "x$with_sendmail" != "x"; then
|
|
||||||
xdg_email_path=$with_xdg_email
|
|
||||||
else
|
|
||||||
xdg_email_path=$PATH
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_PATH_PROG(XDG_EMAIL, xdg-email, , $xdg_email_path)
|
|
||||||
if test "x$XDG_EMAIL" != "x"; then
|
if test "x$XDG_EMAIL" != "x"; then
|
||||||
have_email="yes (xdg-email)"
|
have_email="yes (xdg-email)"
|
||||||
have_xdg_email=yes
|
else
|
||||||
AC_DEFINE_UNQUOTED(XDG_EMAIL, "$XDG_EMAIL",
|
# Not having xdg-email at runtime is not a blocker.
|
||||||
[The email composer search tool used by the mail plug-in.])
|
# But let's inform the builder that for the feature to be available,
|
||||||
elif test "x$with_xdg_email" != "x"; then
|
# xdg-email is a runtime dependency.
|
||||||
AC_MSG_ERROR([
|
have_email="needs runtime dependency: xdg-email"
|
||||||
*** Check for xdg-email failed, though it was explicitly enabled with --with-xdg-email.
|
|
||||||
*** If you know where it is installed, you may configure --with-xdg-email=/path/to/bin/.])
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -58,32 +58,36 @@ typedef struct
|
||||||
} m_info;
|
} m_info;
|
||||||
|
|
||||||
|
|
||||||
static void query (void);
|
static void query (void);
|
||||||
static void run (const gchar *name,
|
static void run (const gchar *name,
|
||||||
gint nparams,
|
gint nparams,
|
||||||
const GimpParam *param,
|
const GimpParam *param,
|
||||||
gint *nreturn_vals,
|
gint *nreturn_vals,
|
||||||
GimpParam **return_vals);
|
GimpParam **return_vals);
|
||||||
|
|
||||||
static GimpPDBStatusType send_image (const gchar *filename,
|
static GimpPDBStatusType send_image (const gchar *filename,
|
||||||
gint32 image_ID,
|
gint32 image_ID,
|
||||||
gint32 drawable_ID,
|
gint32 drawable_ID,
|
||||||
gint32 run_mode);
|
gint32 run_mode);
|
||||||
|
|
||||||
static gboolean send_dialog (void);
|
static gboolean send_dialog (void);
|
||||||
static void mail_entry_callback (GtkWidget *widget,
|
static void mail_entry_callback (GtkWidget *widget,
|
||||||
gchar *data);
|
gchar *data);
|
||||||
static void mesg_body_callback (GtkTextBuffer *buffer,
|
static void mesg_body_callback (GtkTextBuffer *buffer,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
|
||||||
static gboolean valid_file (const gchar *filename);
|
static gboolean valid_file (const gchar *filename);
|
||||||
static void create_headers (FILE *mailpipe);
|
static gchar * find_extension (const gchar *filename);
|
||||||
static gchar * find_extension (const gchar *filename);
|
|
||||||
static gboolean to64 (const gchar *filename,
|
#ifdef SENDMAIL
|
||||||
FILE *outfile,
|
static gchar * sendmail_content_type (const gchar *filename)
|
||||||
GError **error);
|
static void sendmail_create_headers (FILE *mailpipe);
|
||||||
static FILE * sendmail_pipe (gchar **cmd,
|
static gboolean sendmail_to64 (const gchar *filename,
|
||||||
GPid *pid);
|
FILE *outfile,
|
||||||
|
GError **error);
|
||||||
|
static FILE * sendmail_pipe (gchar **cmd,
|
||||||
|
GPid *pid);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
const GimpPlugInInfo PLUG_IN_INFO =
|
const GimpPlugInInfo PLUG_IN_INFO =
|
||||||
|
@ -120,13 +124,38 @@ query (void)
|
||||||
{ GIMP_PDB_INT32, "encapsulation", "ignored" }
|
{ GIMP_PDB_INT32, "encapsulation", "ignored" }
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined XDG_EMAIL || defined SENDMAIL
|
#ifndef SENDMAIL /* xdg-email */
|
||||||
|
/* check if xdg-email is installed
|
||||||
|
* TODO: allow setting the location of the executable in preferences
|
||||||
|
*/
|
||||||
|
gchar *argv[] = { "xdg-email", "--version", NULL };
|
||||||
|
gboolean have_xdg_email = FALSE;
|
||||||
|
|
||||||
|
if (g_spawn_sync (NULL,
|
||||||
|
argv,
|
||||||
|
NULL,
|
||||||
|
G_SPAWN_STDERR_TO_DEV_NULL |
|
||||||
|
G_SPAWN_SEARCH_PATH,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL))
|
||||||
|
{
|
||||||
|
have_xdg_email = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! have_xdg_email)
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
gimp_install_procedure (PLUG_IN_PROC,
|
gimp_install_procedure (PLUG_IN_PROC,
|
||||||
N_("Send the image by email"),
|
N_("Send the image by email"),
|
||||||
#ifdef XDG_EMAIL
|
#ifdef SENDMAIL
|
||||||
"The preferred email composer is used to send emails and must be properly configured.",
|
|
||||||
#else /* sendmail */
|
|
||||||
"Sendmail is used to send emails and must be properly configured.",
|
"Sendmail is used to send emails and must be properly configured.",
|
||||||
|
#else /* xdg-email */
|
||||||
|
"The preferred email composer is used to send emails and must be properly configured.",
|
||||||
#endif
|
#endif
|
||||||
"Adrian Likins, Reagan Blundell",
|
"Adrian Likins, Reagan Blundell",
|
||||||
"Adrian Likins, Reagan Blundell, Daniel Risacher, "
|
"Adrian Likins, Reagan Blundell, Daniel Risacher, "
|
||||||
|
@ -141,7 +170,6 @@ query (void)
|
||||||
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/File/Send");
|
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/File/Send");
|
||||||
gimp_plugin_icon_register (PLUG_IN_PROC, GIMP_ICON_TYPE_ICON_NAME,
|
gimp_plugin_icon_register (PLUG_IN_PROC, GIMP_ICON_TYPE_ICON_NAME,
|
||||||
(const guint8 *) GTK_STOCK_EDIT);
|
(const guint8 *) GTK_STOCK_EDIT);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -254,7 +282,7 @@ send_image (const gchar *filename,
|
||||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||||
gchar *ext;
|
gchar *ext;
|
||||||
gchar *tmpname;
|
gchar *tmpname;
|
||||||
#ifdef XDG_EMAIL
|
#ifndef SENDMAIL /* xdg-email */
|
||||||
gchar *mailcmd[9];
|
gchar *mailcmd[9];
|
||||||
gchar *filepath = NULL;
|
gchar *filepath = NULL;
|
||||||
GFile *tmp_dir = NULL;
|
GFile *tmp_dir = NULL;
|
||||||
|
@ -283,7 +311,7 @@ send_image (const gchar *filename,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef XDG_EMAIL
|
#ifndef SENDMAIL /* xdg-email */
|
||||||
/* From xdg-email doc:
|
/* From xdg-email doc:
|
||||||
* "Some e-mail applications require the file to remain present
|
* "Some e-mail applications require the file to remain present
|
||||||
* after xdg-email returns."
|
* after xdg-email returns."
|
||||||
|
@ -336,7 +364,7 @@ send_image (const gchar *filename,
|
||||||
mail_info.filename, NULL);
|
mail_info.filename, NULL);
|
||||||
g_rename (tmpname, filepath);
|
g_rename (tmpname, filepath);
|
||||||
|
|
||||||
mailcmd[0] = XDG_EMAIL;
|
mailcmd[0] = "xdg-email";
|
||||||
mailcmd[1] = "--attach";
|
mailcmd[1] = "--attach";
|
||||||
mailcmd[2] = filepath;
|
mailcmd[2] = filepath;
|
||||||
mailcmd[3] = "--subject";
|
mailcmd[3] = "--subject";
|
||||||
|
@ -347,7 +375,7 @@ send_image (const gchar *filename,
|
||||||
mailcmd[8] = NULL;
|
mailcmd[8] = NULL;
|
||||||
|
|
||||||
if (! g_spawn_async (NULL, mailcmd, NULL,
|
if (! g_spawn_async (NULL, mailcmd, NULL,
|
||||||
G_SPAWN_DEFAULT,
|
G_SPAWN_SEARCH_PATH,
|
||||||
NULL, NULL, NULL, &error))
|
NULL, NULL, NULL, &error))
|
||||||
{
|
{
|
||||||
g_message ("%s", error->message);
|
g_message ("%s", error->message);
|
||||||
|
@ -560,51 +588,6 @@ valid_file (const gchar *filename)
|
||||||
return g_stat (filename, &buf) == 0 && buf.st_size > 0;
|
return g_stat (filename, &buf) == 0 && buf.st_size > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar *
|
|
||||||
find_content_type (const gchar *filename)
|
|
||||||
{
|
|
||||||
/* This function returns a MIME Content-type: value based on the
|
|
||||||
filename it is given. */
|
|
||||||
const gchar *type_mappings[20] =
|
|
||||||
{
|
|
||||||
"gif" , "image/gif",
|
|
||||||
"jpg" , "image/jpeg",
|
|
||||||
"jpeg", "image/jpeg",
|
|
||||||
"tif" , "image/tiff",
|
|
||||||
"tiff", "image/tiff",
|
|
||||||
"png" , "image/png",
|
|
||||||
"g3" , "image/g3fax",
|
|
||||||
"ps" , "application/postscript",
|
|
||||||
"eps" , "application/postscript",
|
|
||||||
NULL, NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
gchar *ext;
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
ext = find_extension (filename);
|
|
||||||
|
|
||||||
if (!ext)
|
|
||||||
{
|
|
||||||
return g_strdup ("application/octet-stream");
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
ext += 1;
|
|
||||||
|
|
||||||
while (type_mappings[i])
|
|
||||||
{
|
|
||||||
if (g_ascii_strcasecmp (ext, type_mappings[i]) == 0)
|
|
||||||
{
|
|
||||||
return g_strdup (type_mappings[i + 1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
i += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return g_strdup_printf ("image/x-%s", ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
find_extension (const gchar *filename)
|
find_extension (const gchar *filename)
|
||||||
{
|
{
|
||||||
|
@ -665,8 +648,54 @@ mesg_body_callback (GtkTextBuffer *buffer,
|
||||||
mesg_body = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE);
|
mesg_body = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SENDMAIL
|
||||||
|
static gchar *
|
||||||
|
sendmail_content_type (const gchar *filename)
|
||||||
|
{
|
||||||
|
/* This function returns a MIME Content-type: value based on the
|
||||||
|
filename it is given. */
|
||||||
|
const gchar *type_mappings[20] =
|
||||||
|
{
|
||||||
|
"gif" , "image/gif",
|
||||||
|
"jpg" , "image/jpeg",
|
||||||
|
"jpeg", "image/jpeg",
|
||||||
|
"tif" , "image/tiff",
|
||||||
|
"tiff", "image/tiff",
|
||||||
|
"png" , "image/png",
|
||||||
|
"g3" , "image/g3fax",
|
||||||
|
"ps" , "application/postscript",
|
||||||
|
"eps" , "application/postscript",
|
||||||
|
NULL, NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
gchar *ext;
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
ext = find_extension (filename);
|
||||||
|
|
||||||
|
if (!ext)
|
||||||
|
{
|
||||||
|
return g_strdup ("application/octet-stream");
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
ext += 1;
|
||||||
|
|
||||||
|
while (type_mappings[i])
|
||||||
|
{
|
||||||
|
if (g_ascii_strcasecmp (ext, type_mappings[i]) == 0)
|
||||||
|
{
|
||||||
|
return g_strdup (type_mappings[i + 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_strdup_printf ("image/x-%s", ext);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
create_headers (FILE *mailpipe)
|
sendmail_create_headers (FILE *mailpipe)
|
||||||
{
|
{
|
||||||
/* create all the mail header stuff. Feel free to add your own */
|
/* create all the mail header stuff. Feel free to add your own */
|
||||||
/* It is advisable to leave the X-Mailer header though, as */
|
/* It is advisable to leave the X-Mailer header though, as */
|
||||||
|
@ -695,7 +724,7 @@ create_headers (FILE *mailpipe)
|
||||||
fprintf (mailpipe, "\n\n");
|
fprintf (mailpipe, "\n\n");
|
||||||
|
|
||||||
{
|
{
|
||||||
gchar *content = find_content_type (mail_info.filename);
|
gchar *content = sendmail_content_type (mail_info.filename);
|
||||||
|
|
||||||
fprintf (mailpipe, "--GUMP-MIME-boundary\n");
|
fprintf (mailpipe, "--GUMP-MIME-boundary\n");
|
||||||
fprintf (mailpipe, "Content-type: %s\n", content);
|
fprintf (mailpipe, "Content-type: %s\n", content);
|
||||||
|
@ -709,9 +738,9 @@ create_headers (FILE *mailpipe)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
to64 (const gchar *filename,
|
sendmail_to64 (const gchar *filename,
|
||||||
FILE *outfile,
|
FILE *outfile,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GMappedFile *infile;
|
GMappedFile *infile;
|
||||||
const guchar *in;
|
const guchar *in;
|
||||||
|
@ -766,3 +795,4 @@ sendmail_pipe (gchar **cmd,
|
||||||
|
|
||||||
return fdopen (fd, "wb");
|
return fdopen (fd, "wb");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue