2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-24 22:05:25 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
2003-11-06 15:27:05 +00:00
|
|
|
* Copyright (C) 1997 Daniel Risacher
|
1997-11-24 22:05:25 +00:00
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-24 22:05:25 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-24 22:05:25 +00:00
|
|
|
* (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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-24 22:05:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2008-02-05 09:42:34 +00:00
|
|
|
* GUMP - Gimp Useless Mail Plugin
|
|
|
|
* (or Gump Useless Mail Plugin if you prefer)
|
2000-01-16 15:38:38 +00:00
|
|
|
*
|
|
|
|
* by Adrian Likins <adrian@gimp.org>
|
|
|
|
* MIME encapsulation by Reagan Blundell <reagan@emails.net>
|
|
|
|
*
|
2005-01-07 08:56:10 +00:00
|
|
|
* As always: The utility of this plugin is left as an exercise for
|
|
|
|
* the reader
|
2000-01-16 15:38:38 +00:00
|
|
|
*
|
1997-11-24 22:05:25 +00:00
|
|
|
*/
|
|
|
|
|
2000-01-07 10:39:33 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2005-03-04 15:12:29 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2017-02-02 19:44:28 +01:00
|
|
|
#ifdef SENDMAIL
|
1999-05-17 12:27:10 +00:00
|
|
|
#include <sys/types.h>
|
1997-11-24 22:05:25 +00:00
|
|
|
#include <sys/wait.h>
|
2017-02-02 19:44:28 +01:00
|
|
|
#endif
|
2000-01-07 10:39:33 +00:00
|
|
|
|
2005-03-04 15:12:29 +00:00
|
|
|
#include <glib/gstdio.h>
|
2000-01-07 10:39:33 +00:00
|
|
|
|
2000-01-08 20:00:10 +00:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
1997-11-24 22:05:25 +00:00
|
|
|
|
1999-05-29 16:35:47 +00:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-08-14 22:06:19 +02:00
|
|
|
|
2005-03-02 02:20:02 +00:00
|
|
|
#define BUFFER_SIZE 256
|
|
|
|
|
2005-08-14 00:41:26 +00:00
|
|
|
#define PLUG_IN_PROC "plug-in-mail-image"
|
|
|
|
#define PLUG_IN_BINARY "mail"
|
2011-04-08 20:31:34 +02:00
|
|
|
#define PLUG_IN_ROLE "gimp-mail"
|
2004-11-10 15:52:49 +00:00
|
|
|
|
2019-08-14 22:06:19 +02:00
|
|
|
|
|
|
|
typedef struct _Mail Mail;
|
|
|
|
typedef struct _MailClass MailClass;
|
|
|
|
|
|
|
|
struct _Mail
|
|
|
|
{
|
|
|
|
GimpPlugIn parent_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _MailClass
|
|
|
|
{
|
|
|
|
GimpPlugInClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define MAIL_TYPE (mail_get_type ())
|
2023-10-18 18:29:37 +02:00
|
|
|
#define MAIL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAIL_TYPE, Mail))
|
2019-08-14 22:06:19 +02:00
|
|
|
|
|
|
|
GType mail_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
static GList * mail_init_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * mail_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static GimpValueArray * mail_run (GimpProcedure *procedure,
|
2019-08-18 13:45:58 +02:00
|
|
|
GimpRunMode run_mode,
|
2019-08-17 00:16:11 +02:00
|
|
|
GimpImage *image,
|
2021-04-02 02:55:46 +02:00
|
|
|
GimpDrawable **drawables,
|
2023-07-01 22:30:25 +02:00
|
|
|
GimpProcedureConfig *config,
|
2019-08-14 22:06:19 +02:00
|
|
|
gpointer run_data);
|
2016-05-27 20:50:35 +02:00
|
|
|
|
2023-04-21 11:35:45 +00:00
|
|
|
static GimpPDBStatusType send_image (GObject *config,
|
2021-04-02 02:55:46 +02:00
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable **drawables,
|
|
|
|
gint32 run_mode);
|
2016-05-27 20:50:35 +02:00
|
|
|
|
2023-04-21 11:35:45 +00:00
|
|
|
static gboolean send_dialog (GimpProcedure *procedure,
|
|
|
|
GObject *config);
|
2019-09-11 22:32:44 +02:00
|
|
|
static gboolean valid_file (GFile *file);
|
2016-05-27 20:50:35 +02:00
|
|
|
static gchar * find_extension (const gchar *filename);
|
|
|
|
|
|
|
|
#ifdef SENDMAIL
|
2016-05-27 21:57:06 +02:00
|
|
|
static gchar * sendmail_content_type (const gchar *filename);
|
2023-04-21 11:35:45 +00:00
|
|
|
static void sendmail_create_headers (FILE *mailpipe,
|
|
|
|
GObject *config);
|
2016-05-27 20:50:35 +02:00
|
|
|
static gboolean sendmail_to64 (const gchar *filename,
|
|
|
|
FILE *outfile,
|
|
|
|
GError **error);
|
|
|
|
static FILE * sendmail_pipe (gchar **cmd,
|
|
|
|
GPid *pid);
|
|
|
|
#endif
|
2005-03-02 02:20:02 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-08-14 22:06:19 +02:00
|
|
|
G_DEFINE_TYPE (Mail, mail, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (MAIL_TYPE)
|
2022-05-26 00:59:36 +02:00
|
|
|
DEFINE_STD_SET_I18N
|
2019-08-14 22:06:19 +02:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2023-06-21 21:38:36 +02:00
|
|
|
#ifdef SENDMAIL
|
2008-02-05 09:42:34 +00:00
|
|
|
static gchar *mesg_body = NULL;
|
2023-06-21 21:38:36 +02:00
|
|
|
#endif
|
2003-11-06 15:27:05 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-08-14 22:06:19 +02:00
|
|
|
static void
|
|
|
|
mail_class_init (MailClass *klass)
|
|
|
|
{
|
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
|
|
|
|
|
|
|
plug_in_class->init_procedures = mail_init_procedures;
|
|
|
|
plug_in_class->create_procedure = mail_create_procedure;
|
2022-05-26 00:59:36 +02:00
|
|
|
plug_in_class->set_i18n = STD_SET_I18N;
|
2019-08-14 22:06:19 +02:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
static void
|
2019-08-14 22:06:19 +02:00
|
|
|
mail_init (Mail *mail)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2019-08-14 22:06:19 +02:00
|
|
|
}
|
2016-05-28 00:51:24 +02:00
|
|
|
|
2019-08-14 22:06:19 +02:00
|
|
|
static GList *
|
|
|
|
mail_init_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
GList *list = NULL;
|
|
|
|
gchar *email_bin;
|
1999-05-29 16:35:47 +00:00
|
|
|
|
2016-06-02 01:14:15 +02:00
|
|
|
/* Check if xdg-email or sendmail is installed.
|
|
|
|
* TODO: allow setting the location of the executable in preferences.
|
2016-05-27 20:50:35 +02:00
|
|
|
*/
|
2016-06-02 18:17:09 +02:00
|
|
|
#ifdef SENDMAIL
|
|
|
|
if (strlen (SENDMAIL) == 0)
|
|
|
|
{
|
|
|
|
email_bin = g_find_program_in_path ("sendmail");
|
|
|
|
}
|
|
|
|
else
|
2016-06-02 01:14:15 +02:00
|
|
|
{
|
2016-06-02 18:17:09 +02:00
|
|
|
/* If a directory has been set at build time, we assume that sendmail
|
|
|
|
* can only be in this directory. */
|
|
|
|
email_bin = g_build_filename (SENDMAIL, "sendmail", NULL);
|
|
|
|
if (! g_file_test (email_bin, G_FILE_TEST_IS_EXECUTABLE))
|
|
|
|
{
|
|
|
|
g_free (email_bin);
|
|
|
|
email_bin = NULL;
|
|
|
|
}
|
2016-06-02 01:14:15 +02:00
|
|
|
}
|
2016-05-28 00:51:24 +02:00
|
|
|
#else
|
|
|
|
email_bin = g_find_program_in_path ("xdg-email");
|
|
|
|
#endif
|
2016-05-27 20:50:35 +02:00
|
|
|
|
2019-08-14 22:06:19 +02:00
|
|
|
if (email_bin)
|
|
|
|
list = g_list_append (list, g_strdup (PLUG_IN_PROC));
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpProcedure *
|
|
|
|
mail_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
|
|
|
|
|
|
|
if (! strcmp (name, PLUG_IN_PROC))
|
|
|
|
{
|
2023-10-01 18:23:57 +02:00
|
|
|
procedure = gimp_image_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
mail_run, NULL, NULL);
|
2019-08-14 22:06:19 +02:00
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "*");
|
2021-04-02 02:55:46 +02:00
|
|
|
gimp_procedure_set_sensitivity_mask (procedure,
|
|
|
|
GIMP_PROCEDURE_SENSITIVE_DRAWABLE |
|
|
|
|
GIMP_PROCEDURE_SENSITIVE_DRAWABLES |
|
|
|
|
GIMP_PROCEDURE_SENSITIVE_NO_DRAWABLES);
|
2019-08-14 22:06:19 +02:00
|
|
|
|
2022-07-04 22:50:53 +02:00
|
|
|
gimp_procedure_set_menu_label (procedure, _("Send by E_mail..."));
|
2019-08-18 13:45:58 +02:00
|
|
|
gimp_procedure_set_icon_name (procedure, GIMP_ICON_EDIT);
|
2023-07-13 15:34:40 +02:00
|
|
|
gimp_procedure_add_menu_path (procedure, "<Image>/File/[Send]");
|
2016-05-27 20:50:35 +02:00
|
|
|
|
2019-08-14 22:06:19 +02:00
|
|
|
gimp_procedure_set_documentation (procedure,
|
2022-07-04 22:50:53 +02:00
|
|
|
_("Send the image by email"),
|
2016-05-27 20:50:35 +02:00
|
|
|
#ifdef SENDMAIL
|
2023-04-21 11:35:45 +00:00
|
|
|
_("Sendmail is used to send emails "
|
|
|
|
"and must be properly configured."),
|
2016-05-27 20:50:35 +02:00
|
|
|
#else /* xdg-email */
|
2023-04-21 11:35:45 +00:00
|
|
|
_("The preferred email composer is "
|
|
|
|
"used to send emails and must be "
|
|
|
|
"properly configured."),
|
2013-10-21 23:41:41 +13:00
|
|
|
#endif
|
2019-08-14 22:06:19 +02:00
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Adrian Likins, Reagan Blundell",
|
|
|
|
"Adrian Likins, Reagan Blundell, "
|
|
|
|
"Daniel Risacher, "
|
|
|
|
"Spencer Kimball and Peter Mattis",
|
|
|
|
"1995-1997");
|
|
|
|
|
2024-06-12 16:53:12 +00:00
|
|
|
gimp_procedure_add_string_argument (procedure, "filename",
|
|
|
|
_("File_name"),
|
|
|
|
_("The name of the file to save the image in"),
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_string_argument (procedure, "to-address",
|
|
|
|
_("_To"),
|
|
|
|
_("The email address to send to"),
|
|
|
|
"",
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_string_argument (procedure, "from-address",
|
|
|
|
_("_From"),
|
|
|
|
_("The email address for the From: field"),
|
|
|
|
"",
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_string_argument (procedure, "subject",
|
|
|
|
_("Su_bject"),
|
|
|
|
_("The subject"),
|
|
|
|
"",
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_string_argument (procedure, "comment",
|
|
|
|
_("Co_mment"),
|
|
|
|
_("The comment"),
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE);
|
2019-08-14 22:06:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return procedure;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 22:06:19 +02:00
|
|
|
static GimpValueArray *
|
|
|
|
mail_run (GimpProcedure *procedure,
|
2019-08-18 13:45:58 +02:00
|
|
|
GimpRunMode run_mode,
|
2019-08-17 00:16:11 +02:00
|
|
|
GimpImage *image,
|
2021-04-02 02:55:46 +02:00
|
|
|
GimpDrawable **drawables,
|
2023-07-01 22:30:25 +02:00
|
|
|
GimpProcedureConfig *config,
|
2019-08-14 22:06:19 +02:00
|
|
|
gpointer run_data)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2023-07-01 22:30:25 +02:00
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
2023-04-21 11:35:45 +00:00
|
|
|
|
2023-07-01 22:30:25 +02:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2023-07-01 22:30:25 +02:00
|
|
|
gchar *filename = g_file_get_path (gimp_image_get_file (image));
|
2019-08-14 22:06:19 +02:00
|
|
|
|
2023-07-01 22:30:25 +02:00
|
|
|
if (filename)
|
2023-04-21 11:35:45 +00:00
|
|
|
{
|
2023-07-01 22:30:25 +02:00
|
|
|
gchar *basename = g_filename_display_basename (filename);
|
|
|
|
gchar buffername[BUFFER_SIZE];
|
|
|
|
|
|
|
|
g_strlcpy (buffername, basename, BUFFER_SIZE);
|
2019-08-14 22:06:19 +02:00
|
|
|
|
2023-07-01 22:30:25 +02:00
|
|
|
g_object_set (config,
|
|
|
|
"filename", buffername,
|
|
|
|
NULL);
|
|
|
|
g_free (basename);
|
|
|
|
g_free (filename);
|
2023-04-21 11:35:45 +00:00
|
|
|
}
|
2019-08-14 22:06:19 +02:00
|
|
|
|
2023-07-01 22:30:25 +02:00
|
|
|
if (! send_dialog (procedure, G_OBJECT (config)))
|
|
|
|
return gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL, NULL);
|
2019-08-14 22:06:19 +02:00
|
|
|
}
|
2005-04-20 00:40:32 +00:00
|
|
|
|
2024-10-28 12:16:13 +01:00
|
|
|
status = send_image (G_OBJECT (config), image, drawables, run_mode);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-08-14 22:06:19 +02:00
|
|
|
return gimp_procedure_new_return_values (procedure, status, NULL);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2000-08-22 01:26:57 +00:00
|
|
|
static GimpPDBStatusType
|
2023-04-21 11:35:45 +00:00
|
|
|
send_image (GObject *config,
|
2021-04-02 02:55:46 +02:00
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable **drawables,
|
|
|
|
gint32 run_mode)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2024-05-06 18:38:12 +00:00
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
2005-03-02 02:20:02 +00:00
|
|
|
gchar *ext;
|
2019-09-11 22:32:44 +02:00
|
|
|
GFile *tmpfile;
|
2005-03-02 02:20:02 +00:00
|
|
|
gchar *tmpname;
|
2016-05-27 20:50:35 +02:00
|
|
|
#ifndef SENDMAIL /* xdg-email */
|
2013-10-21 23:41:41 +13:00
|
|
|
gchar *mailcmd[9];
|
|
|
|
gchar *filepath = NULL;
|
|
|
|
GFile *tmp_dir = NULL;
|
|
|
|
GFileEnumerator *enumerator;
|
2016-05-27 21:13:06 +02:00
|
|
|
gint i;
|
2013-10-21 23:41:41 +13:00
|
|
|
#else /* SENDMAIL */
|
2005-03-02 02:20:02 +00:00
|
|
|
gchar *mailcmd[3];
|
|
|
|
GPid mailpid;
|
2016-05-27 21:57:06 +02:00
|
|
|
FILE *mailpipe = NULL;
|
2013-10-21 23:41:41 +13:00
|
|
|
#endif
|
2023-06-21 21:38:36 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
gchar *filename = NULL;
|
|
|
|
gchar *receipt = NULL;
|
|
|
|
gchar *from = NULL;
|
|
|
|
gchar *subject = NULL;
|
|
|
|
gchar *comment = NULL;
|
2023-04-21 11:35:45 +00:00
|
|
|
|
2024-08-17 15:35:01 +02:00
|
|
|
mailcmd[0] = NULL;
|
2023-04-21 11:35:45 +00:00
|
|
|
g_object_get (config,
|
|
|
|
"filename", &filename,
|
|
|
|
"to-address", &receipt,
|
|
|
|
"from-address", &from,
|
|
|
|
"subject", &subject,
|
|
|
|
"comment", &comment,
|
|
|
|
NULL);
|
2005-03-02 02:20:02 +00:00
|
|
|
|
|
|
|
ext = find_extension (filename);
|
|
|
|
|
|
|
|
if (ext == NULL)
|
2000-08-22 01:26:57 +00:00
|
|
|
return GIMP_PDB_CALLING_ERROR;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* get a temp name with the right extension and save into it. */
|
2019-09-11 22:32:44 +02:00
|
|
|
tmpfile = gimp_temp_file (ext + 1);
|
|
|
|
tmpname = g_file_get_path (tmpfile);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
app, libgimp*, pdb, plug-ins: review and enhance MR !1549.
- Fix annotations for gimp_export_options_get_image() to make it
actually introspectable with the GimpImage being both input and
output. Even though the logic doesn't change much (the input image may
be overriden or not), it doesn't matter for introspection because
images are handled centrally by libgimp and therefore must not be
freed. Actually deleting the image from the central list of images
though remains a manual action depending on code logic, not some
automatic action to be handled by binding engines.
- Add G_GNUC_WARN_UNUSED_RESULT to gimp_export_options_get_image()
because ignoring the returned value is rarely a good idea (as you
usually want to delete the image).
- Remove gimp_export_options_new(): we don't need this constructor
because at this point, the best is to tell plug-in developers to just
pass NULL everywhere. This leaves us free to create a more useful
default constructor if needed, in the future. Main description for
GimpExportOptions has also been updated to say this.
- Add a data_destroy callback for the user data passed in
gimp_export_procedure_set_capabilities().
- Fixing annotations of 'export_options' object from pdb/pdb.pl: input
args would actually be (nullable) and would not transfer ownership
(calling code must still free the object). Return value's ownership on
the other hand is fully transfered.
- Add C and Python unit testing for GimpExportOptions and
gimp_export_options_get_image() in particular.
- Fix or improve various details.
Note that I have also considered for a long time changing the signature
of gimp_export_options_get_image() to return a boolean indicating
whether `image` had been replaced (hence needed deletion) or not. This
also meant getting rid of the GimpExportReturn enum. Right now it would
work because there are no third case, but I was considering the future
possibility that for instance we got some impossible conversion for some
future capability. I'm not sure it would ever happen; and for sure, this
is not desirable because it implies an export failure a bit late in the
workflow. But just in case, let's keep the enum return value. It does
not even make the using code that much more complicated (well just a
value comparison instead of a simple boolean test).
2024-08-17 15:06:27 +02:00
|
|
|
if (! (gimp_file_save (run_mode, image, tmpfile, NULL) &&
|
2019-09-11 22:32:44 +02:00
|
|
|
valid_file (tmpfile)))
|
2013-10-21 23:41:41 +13:00
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2016-05-27 20:50:35 +02:00
|
|
|
#ifndef SENDMAIL /* xdg-email */
|
2013-10-21 23:41:41 +13:00
|
|
|
/* From xdg-email doc:
|
|
|
|
* "Some e-mail applications require the file to remain present
|
|
|
|
* after xdg-email returns."
|
|
|
|
* As a consequence, the file cannot be removed at the end of the
|
|
|
|
* function. We actually have no way to ever know *when* the file can
|
|
|
|
* be removed since the caller could leave the email window opened for
|
|
|
|
* hours. Yet we still want to clean sometimes and not have temporary
|
|
|
|
* images piling up.
|
|
|
|
* So I use a known directory that we control under $GIMP_DIRECTORY/tmp/,
|
|
|
|
* and clean it out each time the plugin runs. This means that *if* you
|
|
|
|
* are in the above case (your email client requires the file to stay
|
2019-08-17 00:16:11 +02:00
|
|
|
* alive), you cannot run twice the plugin at the same time.
|
2013-10-21 23:41:41 +13:00
|
|
|
*/
|
|
|
|
tmp_dir = gimp_directory_file ("tmp", PLUG_IN_PROC, NULL);
|
|
|
|
|
|
|
|
if (g_mkdir_with_parents (gimp_file_get_utf8_name (tmp_dir),
|
|
|
|
S_IRUSR | S_IWUSR | S_IXUSR) == -1)
|
|
|
|
{
|
|
|
|
g_message ("Temporary directory %s could not be created.",
|
|
|
|
gimp_file_get_utf8_name (tmp_dir));
|
|
|
|
g_error_free (error);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
enumerator = g_file_enumerate_children (tmp_dir,
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
|
|
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
|
|
|
NULL, NULL);
|
|
|
|
if (enumerator)
|
|
|
|
{
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
while ((info = g_file_enumerator_next_file (enumerator,
|
|
|
|
NULL, NULL)))
|
|
|
|
{
|
2023-09-19 14:38:42 +02:00
|
|
|
if (g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_STANDARD_TYPE) == G_FILE_TYPE_REGULAR)
|
2013-10-21 23:41:41 +13:00
|
|
|
{
|
|
|
|
GFile *file = g_file_enumerator_get_child (enumerator, info);
|
|
|
|
g_file_delete (file, NULL, NULL);
|
|
|
|
g_object_unref (file);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (enumerator);
|
|
|
|
}
|
|
|
|
|
2023-04-21 11:35:45 +00:00
|
|
|
filepath = g_build_filename (gimp_file_get_utf8_name (tmp_dir), filename,
|
|
|
|
NULL);
|
2019-08-17 00:41:00 +02:00
|
|
|
if (g_rename (tmpname, filepath) == -1)
|
|
|
|
{
|
|
|
|
/* But on some system, I got an 'Invalid cross-device link' errno
|
|
|
|
* with g_rename().
|
|
|
|
* On the other hand, g_file_move() seems to be more robust.
|
|
|
|
*/
|
2019-09-11 22:32:44 +02:00
|
|
|
GFile *source = tmpfile;
|
2019-08-17 00:41:00 +02:00
|
|
|
GFile *target = g_file_new_for_path (filepath);
|
|
|
|
|
|
|
|
if (! g_file_move (source, target, G_FILE_COPY_NONE, NULL, NULL, NULL, &error))
|
|
|
|
{
|
|
|
|
g_message ("%s", error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
g_object_unref (target);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (target);
|
|
|
|
}
|
2013-10-21 23:41:41 +13:00
|
|
|
|
2016-06-02 18:17:09 +02:00
|
|
|
mailcmd[0] = g_strdup ("xdg-email");
|
2013-10-21 23:41:41 +13:00
|
|
|
mailcmd[1] = "--attach";
|
|
|
|
mailcmd[2] = filepath;
|
2016-05-27 21:13:06 +02:00
|
|
|
i = 3;
|
2023-06-21 21:38:36 +02:00
|
|
|
if (subject != NULL && strlen (subject) > 0)
|
2016-05-27 21:13:06 +02:00
|
|
|
{
|
|
|
|
mailcmd[i++] = "--subject";
|
2023-04-21 11:35:45 +00:00
|
|
|
mailcmd[i++] = subject;
|
2016-05-27 21:13:06 +02:00
|
|
|
}
|
2023-06-21 21:38:36 +02:00
|
|
|
if (comment != NULL && strlen (comment) > 0)
|
2016-05-27 21:13:06 +02:00
|
|
|
{
|
|
|
|
mailcmd[i++] = "--body";
|
2023-04-21 11:35:45 +00:00
|
|
|
mailcmd[i++] = comment;
|
2016-05-27 21:13:06 +02:00
|
|
|
}
|
2023-06-21 21:38:36 +02:00
|
|
|
if (receipt != NULL && strlen (receipt) > 0)
|
2016-05-27 21:13:06 +02:00
|
|
|
{
|
2023-04-21 11:35:45 +00:00
|
|
|
mailcmd[i++] = receipt;
|
2016-05-27 21:13:06 +02:00
|
|
|
}
|
|
|
|
mailcmd[i] = NULL;
|
2013-10-21 23:41:41 +13:00
|
|
|
|
|
|
|
if (! g_spawn_async (NULL, mailcmd, NULL,
|
2016-05-27 20:50:35 +02:00
|
|
|
G_SPAWN_SEARCH_PATH,
|
2013-10-21 23:41:41 +13:00
|
|
|
NULL, NULL, NULL, &error))
|
|
|
|
{
|
|
|
|
g_message ("%s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* SENDMAIL */
|
1997-11-24 22:05:25 +00:00
|
|
|
/* construct the "sendmail user@location" line */
|
2016-06-02 18:17:09 +02:00
|
|
|
if (strlen (SENDMAIL) == 0)
|
|
|
|
mailcmd[0] = g_strdup ("sendmail");
|
|
|
|
else
|
|
|
|
mailcmd[0] = g_build_filename (SENDMAIL, "sendmail", NULL);
|
|
|
|
|
2023-04-21 11:35:45 +00:00
|
|
|
mailcmd[1] = receipt;
|
2005-03-02 02:20:02 +00:00
|
|
|
mailcmd[2] = NULL;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* create a pipe to sendmail */
|
2005-03-02 02:20:02 +00:00
|
|
|
mailpipe = sendmail_pipe (mailcmd, &mailpid);
|
|
|
|
|
|
|
|
if (mailpipe == NULL)
|
|
|
|
return GIMP_PDB_EXECUTION_ERROR;
|
2004-01-11 21:25:24 +00:00
|
|
|
|
2023-04-21 11:35:45 +00:00
|
|
|
sendmail_create_headers (mailpipe, config);
|
2003-11-06 15:27:05 +00:00
|
|
|
|
|
|
|
fflush (mailpipe);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2016-05-27 21:57:06 +02:00
|
|
|
if (! sendmail_to64 (tmpname, mailpipe, &error))
|
2000-01-25 17:46:56 +00:00
|
|
|
{
|
2008-11-04 14:05:24 +00:00
|
|
|
g_message ("%s", error->message);
|
2008-02-05 09:42:34 +00:00
|
|
|
g_error_free (error);
|
|
|
|
goto error;
|
2000-01-25 17:46:56 +00:00
|
|
|
}
|
2005-01-07 08:56:10 +00:00
|
|
|
|
2008-02-05 09:42:34 +00:00
|
|
|
fprintf (mailpipe, "\n--GUMP-MIME-boundary--\n");
|
2013-10-21 23:41:41 +13:00
|
|
|
#endif
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2005-03-02 02:20:02 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* stop sendmail from doing anything */
|
2013-10-21 23:41:41 +13:00
|
|
|
#ifdef SENDMAIL
|
2005-03-02 02:20:02 +00:00
|
|
|
kill (mailpid, SIGINT);
|
2013-10-21 23:41:41 +13:00
|
|
|
#endif
|
2005-03-02 02:20:02 +00:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
/* close out the sendmail process */
|
2013-10-21 23:41:41 +13:00
|
|
|
#ifdef SENDMAIL
|
2016-05-27 21:57:06 +02:00
|
|
|
if (mailpipe)
|
|
|
|
{
|
|
|
|
fclose (mailpipe);
|
|
|
|
waitpid (mailpid, NULL, 0);
|
|
|
|
g_spawn_close_pid (mailpid);
|
|
|
|
}
|
2005-03-02 02:20:02 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
/* delete the tmpfile that was generated */
|
2005-03-04 15:12:29 +00:00
|
|
|
g_unlink (tmpname);
|
2013-10-21 23:41:41 +13:00
|
|
|
#else
|
|
|
|
if (tmp_dir)
|
|
|
|
g_object_unref (tmp_dir);
|
|
|
|
if (filepath)
|
|
|
|
g_free (filepath);
|
|
|
|
#endif
|
|
|
|
|
2023-06-21 21:38:36 +02:00
|
|
|
g_free (filename);
|
|
|
|
g_free (receipt);
|
|
|
|
g_free (from);
|
|
|
|
g_free (subject);
|
|
|
|
g_free (comment);
|
|
|
|
|
2016-06-02 18:17:09 +02:00
|
|
|
g_free (mailcmd[0]);
|
1999-10-27 22:16:20 +00:00
|
|
|
g_free (tmpname);
|
2019-09-11 22:32:44 +02:00
|
|
|
g_object_unref (tmpfile);
|
1999-10-27 22:16:20 +00:00
|
|
|
|
2005-03-02 02:20:02 +00:00
|
|
|
return status;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-20 00:40:32 +00:00
|
|
|
static gboolean
|
2023-04-21 11:35:45 +00:00
|
|
|
send_dialog (GimpProcedure *procedure,
|
|
|
|
GObject *config)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2001-09-17 12:01:27 +00:00
|
|
|
GtkWidget *dlg;
|
2005-04-20 00:40:32 +00:00
|
|
|
GtkWidget *main_vbox;
|
2001-09-17 12:01:27 +00:00
|
|
|
GtkWidget *entry;
|
2023-04-21 11:35:45 +00:00
|
|
|
GtkWidget *real_entry;
|
2018-05-09 01:11:12 +02:00
|
|
|
GtkWidget *grid;
|
2023-04-21 11:35:45 +00:00
|
|
|
GtkWidget *button;
|
2016-05-27 21:13:06 +02:00
|
|
|
#ifdef SENDMAIL
|
2001-09-17 12:01:27 +00:00
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
GtkWidget *text_view;
|
2016-05-27 21:13:06 +02:00
|
|
|
#endif
|
2003-11-06 15:27:05 +00:00
|
|
|
gchar *gump_from;
|
|
|
|
gboolean run;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-09-20 19:39:00 +02:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2004-11-10 15:52:49 +00:00
|
|
|
/* check gimprc for a preferred "From:" address */
|
2003-11-06 15:27:05 +00:00
|
|
|
gump_from = gimp_gimprc_query ("gump-from");
|
1999-03-19 09:12:36 +00:00
|
|
|
|
2000-08-01 00:38:38 +00:00
|
|
|
if (gump_from)
|
|
|
|
{
|
2023-04-21 11:35:45 +00:00
|
|
|
g_object_set (config,
|
|
|
|
"from-address", gump_from,
|
|
|
|
NULL);
|
2000-08-01 00:38:38 +00:00
|
|
|
g_free (gump_from);
|
|
|
|
}
|
2000-01-07 10:39:33 +00:00
|
|
|
|
2023-04-21 11:35:45 +00:00
|
|
|
dlg = gimp_procedure_dialog_new (procedure,
|
|
|
|
GIMP_PROCEDURE_CONFIG (config),
|
|
|
|
_("Send by Email"));
|
|
|
|
/* Change "Ok" button to "Send" */
|
|
|
|
button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dlg),
|
|
|
|
GTK_RESPONSE_OK);
|
|
|
|
gtk_button_set_label (GTK_BUTTON (button), _("Send"));
|
2000-01-07 10:39:33 +00:00
|
|
|
|
|
|
|
|
2018-05-10 17:04:37 +02:00
|
|
|
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dlg),
|
2023-04-21 11:35:45 +00:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2005-02-08 20:40:33 +00:00
|
|
|
|
2005-09-09 18:07:31 +00:00
|
|
|
gimp_window_set_transient (GTK_WINDOW (dlg));
|
2005-09-05 21:40:29 +00:00
|
|
|
|
2011-09-30 12:17:53 +02:00
|
|
|
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
2005-04-20 00:40:32 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
2009-07-15 18:57:12 +02:00
|
|
|
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
|
2005-04-20 00:40:32 +00:00
|
|
|
main_vbox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (main_vbox);
|
|
|
|
|
2018-05-09 01:11:12 +02:00
|
|
|
/* grid */
|
|
|
|
grid = gtk_grid_new ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), grid, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (grid);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2018-05-09 01:11:12 +02:00
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2005-04-20 00:40:32 +00:00
|
|
|
/* Filename entry */
|
2023-04-21 11:35:45 +00:00
|
|
|
entry = gimp_procedure_dialog_get_widget (GIMP_PROCEDURE_DIALOG (dlg),
|
|
|
|
"filename", GIMP_TYPE_LABEL_ENTRY);
|
|
|
|
real_entry = gimp_label_entry_get_entry (GIMP_LABEL_ENTRY (entry));
|
|
|
|
gtk_widget_set_size_request (real_entry, 200, -1);
|
|
|
|
gtk_entry_set_activates_default (GTK_ENTRY (real_entry), TRUE);
|
|
|
|
|
|
|
|
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dlg),
|
|
|
|
"filename",
|
|
|
|
NULL);
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (real_entry),
|
|
|
|
BUFFER_SIZE - 1);
|
2005-04-20 00:40:32 +00:00
|
|
|
|
2016-05-27 21:13:06 +02:00
|
|
|
#ifdef SENDMAIL
|
2005-04-20 00:40:32 +00:00
|
|
|
/* To entry */
|
2023-04-21 11:35:45 +00:00
|
|
|
entry = gimp_procedure_dialog_get_widget (GIMP_PROCEDURE_DIALOG (dlg),
|
|
|
|
"to-address",
|
|
|
|
GIMP_TYPE_LABEL_ENTRY);
|
|
|
|
real_entry = gimp_label_entry_get_entry (GIMP_LABEL_ENTRY (entry));
|
|
|
|
gtk_widget_set_size_request (real_entry, 200, -1);
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (real_entry), BUFFER_SIZE - 1);
|
|
|
|
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dlg),
|
|
|
|
"to-address",
|
|
|
|
NULL);
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (real_entry),
|
|
|
|
BUFFER_SIZE - 1);
|
|
|
|
|
|
|
|
gtk_widget_grab_focus (real_entry);
|
2005-04-20 00:40:32 +00:00
|
|
|
|
1999-11-26 18:03:59 +00:00
|
|
|
/* From entry */
|
2023-04-21 11:35:45 +00:00
|
|
|
entry = gimp_procedure_dialog_get_widget (GIMP_PROCEDURE_DIALOG (dlg),
|
|
|
|
"from-address",
|
|
|
|
GIMP_TYPE_LABEL_ENTRY);
|
|
|
|
real_entry = gimp_label_entry_get_entry (GIMP_LABEL_ENTRY (entry));
|
|
|
|
gtk_widget_set_size_request (real_entry, 200, -1);
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (real_entry), BUFFER_SIZE - 1);
|
|
|
|
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dlg),
|
|
|
|
"from-address",
|
|
|
|
NULL);
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (real_entry),
|
|
|
|
BUFFER_SIZE - 1);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* Subject entry */
|
2023-04-21 11:35:45 +00:00
|
|
|
entry = gimp_procedure_dialog_get_widget (GIMP_PROCEDURE_DIALOG (dlg),
|
|
|
|
"subject",
|
|
|
|
GIMP_TYPE_LABEL_ENTRY);
|
|
|
|
real_entry = gimp_label_entry_get_entry (GIMP_LABEL_ENTRY (entry));
|
|
|
|
gtk_widget_set_size_request (real_entry, 200, -1);
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (real_entry), BUFFER_SIZE - 1);
|
|
|
|
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dlg),
|
|
|
|
"subject",
|
|
|
|
NULL);
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (real_entry),
|
|
|
|
BUFFER_SIZE - 1);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2005-04-20 00:40:32 +00:00
|
|
|
/* Body */
|
2023-04-21 11:35:45 +00:00
|
|
|
text_view = gimp_procedure_dialog_get_widget (GIMP_PROCEDURE_DIALOG (dlg),
|
|
|
|
"comment",
|
|
|
|
GTK_TYPE_TEXT_VIEW);
|
|
|
|
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD);
|
|
|
|
|
|
|
|
scrolled_window =
|
|
|
|
gimp_procedure_dialog_fill_scrolled_window (GIMP_PROCEDURE_DIALOG (dlg),
|
|
|
|
"comment-scrolled",
|
|
|
|
"comment");
|
2003-11-15 13:53:33 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_SHADOW_IN);
|
2001-09-17 12:01:27 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2005-03-02 02:20:02 +00:00
|
|
|
|
2023-04-21 11:35:45 +00:00
|
|
|
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dlg),
|
|
|
|
"comment-scrolled",
|
|
|
|
NULL);
|
2016-05-27 21:13:06 +02:00
|
|
|
#endif
|
2001-09-17 12:01:27 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
gtk_widget_show (dlg);
|
2000-01-16 15:38:38 +00:00
|
|
|
|
2023-04-21 11:35:45 +00:00
|
|
|
run = gimp_procedure_dialog_run (GIMP_PROCEDURE_DIALOG (dlg));
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
gtk_widget_destroy (dlg);
|
|
|
|
|
|
|
|
return run;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2005-03-02 02:20:02 +00:00
|
|
|
static gboolean
|
2019-09-11 22:32:44 +02:00
|
|
|
valid_file (GFile *file)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2019-09-22 13:52:37 +02:00
|
|
|
GStatBuf buf;
|
|
|
|
gboolean valid;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2021-10-01 18:56:12 +02:00
|
|
|
valid = g_stat (g_file_peek_path (file), &buf) == 0 && buf.st_size > 0;
|
2019-09-11 22:32:44 +02:00
|
|
|
|
|
|
|
return valid;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2000-01-16 15:38:38 +00:00
|
|
|
static gchar *
|
2003-07-02 12:03:08 +00:00
|
|
|
find_extension (const gchar *filename)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2000-01-16 15:38:38 +00:00
|
|
|
gchar *filename_copy;
|
|
|
|
gchar *ext;
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
/* we never free this copy - aren't we evil! */
|
2005-01-07 08:56:10 +00:00
|
|
|
filename_copy = g_strdup (filename);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* find the extension, boy! */
|
|
|
|
ext = strrchr (filename_copy, '.');
|
|
|
|
|
2005-01-07 08:56:10 +00:00
|
|
|
while (TRUE)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2005-05-06 19:36:12 +00:00
|
|
|
if (!ext || ext[1] == '\0' || strchr (ext, G_DIR_SEPARATOR))
|
2008-10-20 06:04:39 +00:00
|
|
|
{
|
|
|
|
g_message (_("some sort of error with the file extension "
|
2005-01-07 08:56:10 +00:00
|
|
|
"or lack thereof"));
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2008-10-20 06:04:39 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-03-02 02:20:02 +00:00
|
|
|
|
2005-05-06 19:36:12 +00:00
|
|
|
if (0 != g_ascii_strcasecmp (ext, ".gz") &&
|
|
|
|
0 != g_ascii_strcasecmp (ext, ".bz2"))
|
2008-10-20 06:04:39 +00:00
|
|
|
{
|
|
|
|
return ext;
|
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
else
|
2008-10-20 06:04:39 +00:00
|
|
|
{
|
2018-04-25 14:31:11 -04:00
|
|
|
/* we found something, loop back, and look again */
|
2008-10-20 06:04:39 +00:00
|
|
|
*ext = 0;
|
|
|
|
ext = strrchr (filename_copy, '.');
|
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2005-01-07 08:56:10 +00:00
|
|
|
|
2010-11-09 16:03:47 -02:00
|
|
|
g_free (filename_copy);
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
2016-05-27 21:13:06 +02:00
|
|
|
#ifdef SENDMAIL
|
2016-05-27 20:50:35 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
static void
|
2023-04-21 11:35:45 +00:00
|
|
|
sendmail_create_headers (FILE *mailpipe,
|
|
|
|
GObject *config)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2023-06-21 21:38:36 +02:00
|
|
|
gchar *filename = NULL;
|
|
|
|
gchar *receipt = NULL;
|
|
|
|
gchar *from = NULL;
|
|
|
|
gchar *subject = NULL;
|
|
|
|
gchar *comment = NULL;
|
2023-04-21 11:35:45 +00:00
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
"filename", &filename,
|
|
|
|
"to-address", &receipt,
|
|
|
|
"from-address", &from,
|
|
|
|
"subject", &subject,
|
|
|
|
"comment", &comment,
|
|
|
|
NULL);
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
/* create all the mail header stuff. Feel free to add your own */
|
|
|
|
/* It is advisable to leave the X-Mailer header though, as */
|
2013-01-27 17:52:38 +02:00
|
|
|
/* there is a possibility of a Gimp mail scanner/reader in the */
|
2019-09-21 17:10:46 +00:00
|
|
|
/* future. It will probably need that header. */
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2023-04-21 11:35:45 +00:00
|
|
|
fprintf (mailpipe, "To: %s \n", receipt);
|
|
|
|
fprintf (mailpipe, "Subject: %s \n", subject);
|
2023-06-21 21:38:36 +02:00
|
|
|
if (from != NULL && strlen (from) > 0)
|
2023-04-21 11:35:45 +00:00
|
|
|
fprintf (mailpipe, "From: %s \n", from);
|
2005-04-20 00:40:32 +00:00
|
|
|
|
2017-03-21 17:45:50 +01:00
|
|
|
fprintf (mailpipe, "X-Mailer: GIMP Useless Mail plug-in %s\n", GIMP_VERSION);
|
1999-03-19 09:12:36 +00:00
|
|
|
|
2008-02-05 09:42:34 +00:00
|
|
|
fprintf (mailpipe, "MIME-Version: 1.0\n");
|
|
|
|
fprintf (mailpipe, "Content-type: multipart/mixed; "
|
|
|
|
"boundary=GUMP-MIME-boundary\n");
|
2005-03-02 02:20:02 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
fprintf (mailpipe, "\n\n");
|
2005-03-02 02:20:02 +00:00
|
|
|
|
2008-02-05 09:42:34 +00:00
|
|
|
fprintf (mailpipe, "--GUMP-MIME-boundary\n");
|
|
|
|
fprintf (mailpipe, "Content-type: text/plain; charset=UTF-8\n\n");
|
2005-03-02 02:20:02 +00:00
|
|
|
|
2001-09-17 12:01:27 +00:00
|
|
|
if (mesg_body)
|
2007-05-30 17:57:26 +00:00
|
|
|
fprintf (mailpipe, "%s", mesg_body);
|
2005-03-02 02:20:02 +00:00
|
|
|
|
1998-07-28 22:22:56 +00:00
|
|
|
fprintf (mailpipe, "\n\n");
|
2005-03-02 02:20:02 +00:00
|
|
|
|
2008-02-05 09:42:34 +00:00
|
|
|
{
|
2023-04-21 11:35:45 +00:00
|
|
|
gchar *content = sendmail_content_type (filename);
|
2003-07-02 12:03:08 +00:00
|
|
|
|
2008-02-05 09:42:34 +00:00
|
|
|
fprintf (mailpipe, "--GUMP-MIME-boundary\n");
|
|
|
|
fprintf (mailpipe, "Content-type: %s\n", content);
|
|
|
|
fprintf (mailpipe, "Content-transfer-encoding: base64\n");
|
|
|
|
fprintf (mailpipe, "Content-disposition: attachment; filename=\"%s\"\n",
|
2023-04-21 11:35:45 +00:00
|
|
|
filename);
|
|
|
|
fprintf (mailpipe, "Content-description: %s\n\n", filename);
|
2003-07-02 12:03:08 +00:00
|
|
|
|
2008-02-05 09:42:34 +00:00
|
|
|
g_free (content);
|
|
|
|
}
|
2023-06-21 21:38:36 +02:00
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
g_free (receipt);
|
|
|
|
g_free (from);
|
|
|
|
g_free (subject);
|
|
|
|
g_free (comment);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2007-01-12 14:34:09 +00:00
|
|
|
static gboolean
|
2016-05-27 20:50:35 +02:00
|
|
|
sendmail_to64 (const gchar *filename,
|
|
|
|
FILE *outfile,
|
|
|
|
GError **error)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2007-01-12 14:34:09 +00:00
|
|
|
GMappedFile *infile;
|
|
|
|
const guchar *in;
|
|
|
|
gchar out[2048];
|
|
|
|
gint state = 0;
|
|
|
|
gint save = 0;
|
|
|
|
gsize len;
|
|
|
|
gsize bytes;
|
|
|
|
gsize c;
|
|
|
|
|
|
|
|
infile = g_mapped_file_new (filename, FALSE, error);
|
|
|
|
if (! infile)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
in = (const guchar *) g_mapped_file_get_contents (infile);
|
|
|
|
len = g_mapped_file_get_length (infile);
|
|
|
|
|
|
|
|
for (c = 0; c < len;)
|
2000-01-16 15:38:38 +00:00
|
|
|
{
|
2007-01-12 14:34:09 +00:00
|
|
|
gsize step = MIN (1024, len - c);
|
|
|
|
|
2008-02-05 09:42:34 +00:00
|
|
|
bytes = g_base64_encode_step (in + c, step, TRUE, out, &state, &save);
|
2007-01-12 14:34:09 +00:00
|
|
|
fwrite (out, 1, bytes, outfile);
|
|
|
|
|
|
|
|
c += step;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2000-01-16 15:38:38 +00:00
|
|
|
|
2007-01-12 14:34:09 +00:00
|
|
|
bytes = g_base64_encode_close (TRUE, out, &state, &save);
|
|
|
|
fwrite (out, 1, bytes, outfile);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2009-07-20 12:39:09 +02:00
|
|
|
g_mapped_file_unref (infile);
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2007-01-12 14:34:09 +00:00
|
|
|
return TRUE;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2005-03-02 02:20:02 +00:00
|
|
|
|
|
|
|
static FILE *
|
|
|
|
sendmail_pipe (gchar **cmd,
|
2008-02-05 09:42:34 +00:00
|
|
|
GPid *pid)
|
2005-03-02 02:20:02 +00:00
|
|
|
{
|
|
|
|
gint fd;
|
|
|
|
GError *err = NULL;
|
|
|
|
|
2016-05-28 00:51:24 +02:00
|
|
|
if (! g_spawn_async_with_pipes (NULL, cmd, NULL,
|
|
|
|
G_SPAWN_DO_NOT_REAP_CHILD |
|
|
|
|
G_SPAWN_SEARCH_PATH,
|
2008-10-20 06:04:39 +00:00
|
|
|
NULL, NULL, pid, &fd, NULL, NULL, &err))
|
2005-03-02 02:20:02 +00:00
|
|
|
{
|
|
|
|
g_message (_("Could not start sendmail (%s)"), err->message);
|
|
|
|
g_error_free (err);
|
|
|
|
|
|
|
|
*pid = -1;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-04-26 20:31:01 +00:00
|
|
|
return fdopen (fd, "wb");
|
2005-03-02 02:20:02 +00:00
|
|
|
}
|
2016-05-27 20:50:35 +02:00
|
|
|
#endif
|