2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
2003-11-06 23:27:05 +08:00
|
|
|
* Copyright (C) 1997 Daniel Risacher
|
1997-11-25 06:05:25 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08: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-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2008-02-05 17:42:34 +08:00
|
|
|
* GUMP - Gimp Useless Mail Plugin
|
|
|
|
* (or Gump Useless Mail Plugin if you prefer)
|
2000-01-16 23:38:38 +08:00
|
|
|
*
|
|
|
|
* by Adrian Likins <adrian@gimp.org>
|
|
|
|
* MIME encapsulation by Reagan Blundell <reagan@emails.net>
|
|
|
|
*
|
2005-01-07 16:56:10 +08:00
|
|
|
* As always: The utility of this plugin is left as an exercise for
|
|
|
|
* the reader
|
2000-01-16 23:38:38 +08:00
|
|
|
*
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
2000-01-07 18:39:33 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2005-03-04 23:12:29 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2017-02-03 02:44:28 +08:00
|
|
|
#ifdef SENDMAIL
|
1999-05-17 20:27:10 +08:00
|
|
|
#include <sys/types.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <sys/wait.h>
|
2017-02-03 02:44:28 +08:00
|
|
|
#endif
|
2000-01-07 18:39:33 +08:00
|
|
|
|
2005-03-04 23:12:29 +08:00
|
|
|
#include <glib/gstdio.h>
|
2000-01-07 18:39:33 +08:00
|
|
|
|
2000-01-09 04:00:10 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-05-30 00:35:47 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-15 04:06:19 +08:00
|
|
|
|
2005-03-02 10:20:02 +08:00
|
|
|
#define BUFFER_SIZE 256
|
|
|
|
|
2005-08-14 08:41:26 +08:00
|
|
|
#define PLUG_IN_PROC "plug-in-mail-image"
|
|
|
|
#define PLUG_IN_BINARY "mail"
|
2011-04-09 02:31:34 +08:00
|
|
|
#define PLUG_IN_ROLE "gimp-mail"
|
2004-11-10 23:52:49 +08:00
|
|
|
|
2019-08-15 04:06:19 +08:00
|
|
|
|
2005-03-02 10:20:02 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2008-02-05 17:42:34 +08:00
|
|
|
gchar filename[BUFFER_SIZE];
|
2005-03-02 10:20:02 +08:00
|
|
|
gchar receipt[BUFFER_SIZE];
|
2008-02-05 17:42:34 +08:00
|
|
|
gchar from[BUFFER_SIZE];
|
2005-03-02 10:20:02 +08:00
|
|
|
gchar subject[BUFFER_SIZE];
|
|
|
|
gchar comment[BUFFER_SIZE];
|
2005-04-20 08:40:32 +08:00
|
|
|
} m_info;
|
2005-03-02 10:20:02 +08:00
|
|
|
|
2004-11-10 23:52:49 +08:00
|
|
|
|
2019-08-15 04:06:19 +08: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 ())
|
|
|
|
#define MAIL (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAIL_TYPE, Mail))
|
|
|
|
|
|
|
|
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 19:45:58 +08:00
|
|
|
GimpRunMode run_mode,
|
2019-08-17 06:16:11 +08:00
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
2019-08-15 04:06:19 +08:00
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data);
|
2016-05-28 02:50:35 +08:00
|
|
|
|
|
|
|
static GimpPDBStatusType send_image (const gchar *filename,
|
2019-08-17 06:16:11 +08:00
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
2016-05-28 02:50:35 +08:00
|
|
|
gint32 run_mode);
|
|
|
|
|
|
|
|
static gboolean send_dialog (void);
|
|
|
|
static void mail_entry_callback (GtkWidget *widget,
|
|
|
|
gchar *data);
|
|
|
|
static gboolean valid_file (const gchar *filename);
|
|
|
|
static gchar * find_extension (const gchar *filename);
|
|
|
|
|
|
|
|
#ifdef SENDMAIL
|
2016-05-28 03:13:06 +08:00
|
|
|
static void mesg_body_callback (GtkTextBuffer *buffer,
|
|
|
|
gpointer data);
|
|
|
|
|
2016-05-28 03:57:06 +08:00
|
|
|
static gchar * sendmail_content_type (const gchar *filename);
|
2016-05-28 02:50:35 +08:00
|
|
|
static void sendmail_create_headers (FILE *mailpipe);
|
|
|
|
static gboolean sendmail_to64 (const gchar *filename,
|
|
|
|
FILE *outfile,
|
|
|
|
GError **error);
|
|
|
|
static FILE * sendmail_pipe (gchar **cmd,
|
|
|
|
GPid *pid);
|
|
|
|
#endif
|
2005-03-02 10:20:02 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-15 04:06:19 +08:00
|
|
|
G_DEFINE_TYPE (Mail, mail, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (MAIL_TYPE)
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-16 23:38:38 +08:00
|
|
|
static m_info mail_info =
|
|
|
|
{
|
2008-02-05 17:42:34 +08:00
|
|
|
"", "", "", "", ""
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
2008-02-05 17:42:34 +08:00
|
|
|
static gchar *mesg_body = NULL;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-15 04:06:19 +08: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;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2019-08-15 04:06:19 +08:00
|
|
|
mail_init (Mail *mail)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-08-15 04:06:19 +08:00
|
|
|
}
|
2016-05-28 06:51:24 +08:00
|
|
|
|
2019-08-15 04:06:19 +08:00
|
|
|
static GList *
|
|
|
|
mail_init_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
GList *list = NULL;
|
|
|
|
gchar *email_bin;
|
1999-05-30 00:35:47 +08:00
|
|
|
|
2016-06-02 07:14:15 +08:00
|
|
|
/* Check if xdg-email or sendmail is installed.
|
|
|
|
* TODO: allow setting the location of the executable in preferences.
|
2016-05-28 02:50:35 +08:00
|
|
|
*/
|
2016-06-03 00:17:09 +08:00
|
|
|
#ifdef SENDMAIL
|
|
|
|
if (strlen (SENDMAIL) == 0)
|
|
|
|
{
|
|
|
|
email_bin = g_find_program_in_path ("sendmail");
|
|
|
|
}
|
|
|
|
else
|
2016-06-02 07:14:15 +08:00
|
|
|
{
|
2016-06-03 00:17:09 +08: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 07:14:15 +08:00
|
|
|
}
|
2016-05-28 06:51:24 +08:00
|
|
|
#else
|
|
|
|
email_bin = g_find_program_in_path ("xdg-email");
|
|
|
|
#endif
|
2016-05-28 02:50:35 +08:00
|
|
|
|
2019-08-15 04:06:19 +08: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))
|
|
|
|
{
|
2019-08-30 18:52:28 +08:00
|
|
|
procedure = gimp_image_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
2019-08-18 19:45:58 +08:00
|
|
|
mail_run, NULL, NULL);
|
2019-08-15 04:06:19 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "*");
|
|
|
|
|
|
|
|
gimp_procedure_set_menu_label (procedure, N_("Send by E_mail..."));
|
2019-08-18 19:45:58 +08:00
|
|
|
gimp_procedure_set_icon_name (procedure, GIMP_ICON_EDIT);
|
2019-08-15 04:06:19 +08:00
|
|
|
gimp_procedure_add_menu_path (procedure, "<Image>/File/Send");
|
2016-05-28 02:50:35 +08:00
|
|
|
|
2019-08-15 04:06:19 +08:00
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
N_("Send the image by email"),
|
2016-05-28 02:50:35 +08:00
|
|
|
#ifdef SENDMAIL
|
2019-08-15 04:06:19 +08:00
|
|
|
"Sendmail is used to send emails "
|
|
|
|
"and must be properly configured.",
|
2016-05-28 02:50:35 +08:00
|
|
|
#else /* xdg-email */
|
2019-08-15 04:06:19 +08:00
|
|
|
"The preferred email composer is "
|
|
|
|
"used to send emails and must be "
|
|
|
|
"properly configured.",
|
2013-10-21 18:41:41 +08:00
|
|
|
#endif
|
2019-08-15 04:06:19 +08:00
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Adrian Likins, Reagan Blundell",
|
|
|
|
"Adrian Likins, Reagan Blundell, "
|
|
|
|
"Daniel Risacher, "
|
|
|
|
"Spencer Kimball and Peter Mattis",
|
|
|
|
"1995-1997");
|
|
|
|
|
2019-08-19 16:02:07 +08:00
|
|
|
GIMP_PROC_ARG_STRING (procedure, "filename",
|
|
|
|
"Filename",
|
|
|
|
"The name of the file to save the image in",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
GIMP_PROC_ARG_STRING (procedure, "to-address",
|
|
|
|
"To address",
|
|
|
|
"The email address to send to",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
GIMP_PROC_ARG_STRING (procedure, "from-address",
|
|
|
|
"From address",
|
|
|
|
"The email address for the From: field",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
GIMP_PROC_ARG_STRING (procedure, "subject",
|
|
|
|
"Subject",
|
|
|
|
"The subject",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
GIMP_PROC_ARG_STRING (procedure, "comment",
|
|
|
|
"Comment",
|
|
|
|
"The comment",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE);
|
2019-08-15 04:06:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return procedure;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2019-08-15 04:06:19 +08:00
|
|
|
static GimpValueArray *
|
|
|
|
mail_run (GimpProcedure *procedure,
|
2019-08-18 19:45:58 +08:00
|
|
|
GimpRunMode run_mode,
|
2019-08-17 06:16:11 +08:00
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
2019-08-15 04:06:19 +08:00
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-08-18 19:45:58 +08:00
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
INIT_I18N ();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-15 04:06:19 +08:00
|
|
|
switch (run_mode)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-08-15 04:06:19 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
gimp_get_data (PLUG_IN_PROC, &mail_info);
|
|
|
|
{
|
2019-08-17 06:16:11 +08:00
|
|
|
gchar *filename = gimp_image_get_filename (image);
|
2009-07-28 09:08:50 +08:00
|
|
|
|
2019-08-15 04:06:19 +08:00
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
gchar *basename = g_filename_display_basename (filename);
|
2009-07-28 09:08:50 +08:00
|
|
|
|
2019-08-15 04:06:19 +08:00
|
|
|
g_strlcpy (mail_info.filename, basename, BUFFER_SIZE);
|
|
|
|
g_free (basename);
|
|
|
|
g_free (filename);
|
2009-07-28 09:08:50 +08:00
|
|
|
}
|
2019-08-15 04:06:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! send_dialog ())
|
|
|
|
return gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
2019-08-20 07:03:38 +08:00
|
|
|
g_strlcpy (mail_info.filename, GIMP_VALUES_GET_STRING (args, 0),
|
2019-08-15 04:06:19 +08:00
|
|
|
BUFFER_SIZE);
|
2019-08-20 07:03:38 +08:00
|
|
|
g_strlcpy (mail_info.receipt, GIMP_VALUES_GET_STRING (args, 1),
|
2019-08-15 04:06:19 +08:00
|
|
|
BUFFER_SIZE);
|
2019-08-20 07:03:38 +08:00
|
|
|
g_strlcpy (mail_info.from, GIMP_VALUES_GET_STRING (args, 2),
|
2019-08-15 04:06:19 +08:00
|
|
|
BUFFER_SIZE);
|
2019-08-20 07:03:38 +08:00
|
|
|
g_strlcpy (mail_info.subject, GIMP_VALUES_GET_STRING (args, 3),
|
2019-08-15 04:06:19 +08:00
|
|
|
BUFFER_SIZE);
|
2019-08-20 07:03:38 +08:00
|
|
|
g_strlcpy (mail_info.comment, GIMP_VALUES_GET_STRING (args, 4),
|
2019-08-15 04:06:19 +08:00
|
|
|
BUFFER_SIZE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
|
|
|
gimp_get_data (PLUG_IN_PROC, &mail_info);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-04-20 08:40:32 +08:00
|
|
|
|
2019-08-15 04:06:19 +08:00
|
|
|
status = send_image (mail_info.filename,
|
2019-08-17 06:16:11 +08:00
|
|
|
image,
|
|
|
|
drawable,
|
2019-08-15 04:06:19 +08:00
|
|
|
run_mode);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-15 04:06:19 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2000-01-26 01:46:56 +08:00
|
|
|
{
|
2019-08-15 04:06:19 +08:00
|
|
|
if (mesg_body)
|
|
|
|
g_strlcpy (mail_info.comment, mesg_body, BUFFER_SIZE);
|
|
|
|
|
|
|
|
gimp_set_data (PLUG_IN_PROC, &mail_info, sizeof (m_info));
|
2000-01-26 01:46:56 +08:00
|
|
|
}
|
|
|
|
|
2019-08-15 04:06:19 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure, status, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpPDBStatusType
|
2019-08-17 06:16:11 +08:00
|
|
|
send_image (const gchar *filename,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
gint32 run_mode)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-03-02 10:20:02 +08:00
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
gchar *ext;
|
|
|
|
gchar *tmpname;
|
2016-05-28 02:50:35 +08:00
|
|
|
#ifndef SENDMAIL /* xdg-email */
|
2013-10-21 18:41:41 +08:00
|
|
|
gchar *mailcmd[9];
|
|
|
|
gchar *filepath = NULL;
|
|
|
|
GFile *tmp_dir = NULL;
|
|
|
|
GFileEnumerator *enumerator;
|
2016-05-28 03:13:06 +08:00
|
|
|
gint i;
|
2013-10-21 18:41:41 +08:00
|
|
|
#else /* SENDMAIL */
|
2005-03-02 10:20:02 +08:00
|
|
|
gchar *mailcmd[3];
|
|
|
|
GPid mailpid;
|
2016-05-28 03:57:06 +08:00
|
|
|
FILE *mailpipe = NULL;
|
2013-10-21 18:41:41 +08:00
|
|
|
#endif
|
2008-02-05 17:42:34 +08:00
|
|
|
GError *error = NULL;
|
2005-03-02 10:20:02 +08:00
|
|
|
|
|
|
|
ext = find_extension (filename);
|
|
|
|
|
|
|
|
if (ext == NULL)
|
2000-08-22 09:26:57 +08:00
|
|
|
return GIMP_PDB_CALLING_ERROR;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* get a temp name with the right extension and save into it. */
|
2000-08-25 23:38:38 +08:00
|
|
|
tmpname = gimp_temp_name (ext + 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2013-10-21 18:41:41 +08:00
|
|
|
if (! (gimp_file_save (run_mode,
|
2019-08-17 06:16:11 +08:00
|
|
|
image,
|
|
|
|
drawable,
|
2013-10-21 18:41:41 +08:00
|
|
|
tmpname) && valid_file (tmpname)))
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2016-05-28 02:50:35 +08:00
|
|
|
#ifndef SENDMAIL /* xdg-email */
|
2013-10-21 18:41:41 +08: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 06:16:11 +08:00
|
|
|
* alive), you cannot run twice the plugin at the same time.
|
2013-10-21 18:41:41 +08: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)))
|
|
|
|
{
|
|
|
|
if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
filepath = g_build_filename (gimp_file_get_utf8_name (tmp_dir),
|
|
|
|
mail_info.filename, NULL);
|
2019-08-17 06:41:00 +08: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.
|
|
|
|
*/
|
|
|
|
GFile *source = g_file_new_for_path (tmpname);
|
|
|
|
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 (source);
|
|
|
|
g_object_unref (target);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (source);
|
|
|
|
g_object_unref (target);
|
|
|
|
}
|
2013-10-21 18:41:41 +08:00
|
|
|
|
2016-06-03 00:17:09 +08:00
|
|
|
mailcmd[0] = g_strdup ("xdg-email");
|
2013-10-21 18:41:41 +08:00
|
|
|
mailcmd[1] = "--attach";
|
|
|
|
mailcmd[2] = filepath;
|
2016-05-28 03:13:06 +08:00
|
|
|
i = 3;
|
2017-07-14 19:10:46 +08:00
|
|
|
if (strlen (mail_info.subject) > 0)
|
2016-05-28 03:13:06 +08:00
|
|
|
{
|
|
|
|
mailcmd[i++] = "--subject";
|
|
|
|
mailcmd[i++] = mail_info.subject;
|
|
|
|
}
|
2017-07-14 19:10:46 +08:00
|
|
|
if (strlen (mail_info.comment) > 0)
|
2016-05-28 03:13:06 +08:00
|
|
|
{
|
|
|
|
mailcmd[i++] = "--body";
|
|
|
|
mailcmd[i++] = mail_info.comment;
|
|
|
|
}
|
2017-07-14 19:10:46 +08:00
|
|
|
if (strlen (mail_info.receipt) > 0)
|
2016-05-28 03:13:06 +08:00
|
|
|
{
|
|
|
|
mailcmd[i++] = mail_info.receipt;
|
|
|
|
}
|
|
|
|
mailcmd[i] = NULL;
|
2013-10-21 18:41:41 +08:00
|
|
|
|
|
|
|
if (! g_spawn_async (NULL, mailcmd, NULL,
|
2016-05-28 02:50:35 +08:00
|
|
|
G_SPAWN_SEARCH_PATH,
|
2013-10-21 18:41:41 +08:00
|
|
|
NULL, NULL, NULL, &error))
|
|
|
|
{
|
|
|
|
g_message ("%s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* SENDMAIL */
|
1997-11-25 06:05:25 +08:00
|
|
|
/* construct the "sendmail user@location" line */
|
2016-06-03 00:17:09 +08:00
|
|
|
if (strlen (SENDMAIL) == 0)
|
|
|
|
mailcmd[0] = g_strdup ("sendmail");
|
|
|
|
else
|
|
|
|
mailcmd[0] = g_build_filename (SENDMAIL, "sendmail", NULL);
|
|
|
|
|
2005-03-02 10:20:02 +08:00
|
|
|
mailcmd[1] = mail_info.receipt;
|
|
|
|
mailcmd[2] = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* create a pipe to sendmail */
|
2005-03-02 10:20:02 +08:00
|
|
|
mailpipe = sendmail_pipe (mailcmd, &mailpid);
|
|
|
|
|
|
|
|
if (mailpipe == NULL)
|
|
|
|
return GIMP_PDB_EXECUTION_ERROR;
|
2004-01-12 05:25:24 +08:00
|
|
|
|
2016-05-28 03:57:06 +08:00
|
|
|
sendmail_create_headers (mailpipe);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
|
|
|
fflush (mailpipe);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2016-05-28 03:57:06 +08:00
|
|
|
if (! sendmail_to64 (tmpname, mailpipe, &error))
|
2000-01-26 01:46:56 +08:00
|
|
|
{
|
2008-11-04 22:05:24 +08:00
|
|
|
g_message ("%s", error->message);
|
2008-02-05 17:42:34 +08:00
|
|
|
g_error_free (error);
|
|
|
|
goto error;
|
2000-01-26 01:46:56 +08:00
|
|
|
}
|
2005-01-07 16:56:10 +08:00
|
|
|
|
2008-02-05 17:42:34 +08:00
|
|
|
fprintf (mailpipe, "\n--GUMP-MIME-boundary--\n");
|
2013-10-21 18:41:41 +08:00
|
|
|
#endif
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2005-03-02 10:20:02 +08:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* stop sendmail from doing anything */
|
2013-10-21 18:41:41 +08:00
|
|
|
#ifdef SENDMAIL
|
2005-03-02 10:20:02 +08:00
|
|
|
kill (mailpid, SIGINT);
|
2013-10-21 18:41:41 +08:00
|
|
|
#endif
|
2005-03-02 10:20:02 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
/* close out the sendmail process */
|
2013-10-21 18:41:41 +08:00
|
|
|
#ifdef SENDMAIL
|
2016-05-28 03:57:06 +08:00
|
|
|
if (mailpipe)
|
|
|
|
{
|
|
|
|
fclose (mailpipe);
|
|
|
|
waitpid (mailpid, NULL, 0);
|
|
|
|
g_spawn_close_pid (mailpid);
|
|
|
|
}
|
2005-03-02 10:20:02 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* delete the tmpfile that was generated */
|
2005-03-04 23:12:29 +08:00
|
|
|
g_unlink (tmpname);
|
2013-10-21 18:41:41 +08:00
|
|
|
#else
|
|
|
|
if (tmp_dir)
|
|
|
|
g_object_unref (tmp_dir);
|
|
|
|
if (filepath)
|
|
|
|
g_free (filepath);
|
|
|
|
#endif
|
|
|
|
|
2016-06-03 00:17:09 +08:00
|
|
|
g_free (mailcmd[0]);
|
1999-10-28 06:16:20 +08:00
|
|
|
g_free (tmpname);
|
|
|
|
|
2005-03-02 10:20:02 +08:00
|
|
|
return status;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-20 08:40:32 +08:00
|
|
|
static gboolean
|
2013-10-21 18:41:41 +08:00
|
|
|
send_dialog (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-09-17 20:01:27 +08:00
|
|
|
GtkWidget *dlg;
|
2005-04-20 08:40:32 +08:00
|
|
|
GtkWidget *main_vbox;
|
2001-09-17 20:01:27 +08:00
|
|
|
GtkWidget *entry;
|
2018-05-09 07:11:12 +08:00
|
|
|
GtkWidget *grid;
|
2016-05-28 03:13:06 +08:00
|
|
|
#ifdef SENDMAIL
|
2001-09-17 20:01:27 +08:00
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
GtkWidget *text_view;
|
|
|
|
GtkTextBuffer *text_buffer;
|
2016-05-28 03:13:06 +08:00
|
|
|
#endif
|
2003-11-06 23:27:05 +08:00
|
|
|
gchar *gump_from;
|
2005-04-20 08:40:32 +08:00
|
|
|
gint row = 0;
|
2003-11-06 23:27:05 +08:00
|
|
|
gboolean run;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-08-14 08:41:26 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-11-10 23:52:49 +08:00
|
|
|
/* check gimprc for a preferred "From:" address */
|
2003-11-06 23:27:05 +08:00
|
|
|
gump_from = gimp_gimprc_query ("gump-from");
|
1999-03-19 17:12:36 +08:00
|
|
|
|
2000-08-01 08:38:38 +08:00
|
|
|
if (gump_from)
|
|
|
|
{
|
2005-03-02 10:20:02 +08:00
|
|
|
g_strlcpy (mail_info.from, gump_from, BUFFER_SIZE);
|
2000-08-01 08:38:38 +08:00
|
|
|
g_free (gump_from);
|
|
|
|
}
|
2000-01-07 18:39:33 +08:00
|
|
|
|
2011-04-09 02:31:34 +08:00
|
|
|
dlg = gimp_dialog_new (_("Send by Email"), PLUG_IN_ROLE,
|
2003-11-06 23:27:05 +08:00
|
|
|
NULL, 0,
|
2008-10-20 14:04:39 +08:00
|
|
|
gimp_standard_help_func, PLUG_IN_PROC,
|
2000-01-07 18:39:33 +08:00
|
|
|
|
2017-02-12 23:18:24 +08:00
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Send"), GTK_RESPONSE_OK,
|
2000-01-07 18:39:33 +08:00
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
NULL);
|
2000-01-07 18:39:33 +08:00
|
|
|
|
2018-05-10 23:04:37 +08:00
|
|
|
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dlg),
|
2005-03-02 10:20:02 +08:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2005-02-09 04:40:33 +08:00
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
gimp_window_set_transient (GTK_WINDOW (dlg));
|
2005-09-06 05:40:29 +08:00
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
2005-04-20 08:40:32 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
2009-07-16 00:57:12 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
|
2005-04-20 08:40:32 +08:00
|
|
|
main_vbox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (main_vbox);
|
|
|
|
|
2018-05-09 07:11:12 +08:00
|
|
|
/* grid */
|
|
|
|
grid = gtk_grid_new ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), grid, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (grid);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2018-05-09 07:11:12 +08:00
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-04-20 08:40:32 +08:00
|
|
|
/* Filename entry */
|
|
|
|
entry = gtk_entry_new ();
|
|
|
|
gtk_widget_set_size_request (entry, 200, -1);
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (entry), BUFFER_SIZE - 1);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry), mail_info.filename);
|
2018-05-09 07:11:12 +08:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, row++,
|
|
|
|
_("_Filename:"), 0.0, 0.5,
|
|
|
|
entry, 1);
|
2005-04-20 08:40:32 +08:00
|
|
|
g_signal_connect (entry, "changed",
|
|
|
|
G_CALLBACK (mail_entry_callback),
|
|
|
|
mail_info.filename);
|
2016-05-28 04:02:39 +08:00
|
|
|
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
|
2005-04-20 08:40:32 +08:00
|
|
|
|
2016-05-28 03:13:06 +08:00
|
|
|
#ifdef SENDMAIL
|
2005-04-20 08:40:32 +08:00
|
|
|
/* To entry */
|
1997-11-25 06:05:25 +08:00
|
|
|
entry = gtk_entry_new ();
|
2001-11-12 02:35:25 +08:00
|
|
|
gtk_widget_set_size_request (entry, 200, -1);
|
2005-03-02 10:20:02 +08:00
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (entry), BUFFER_SIZE - 1);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry), mail_info.receipt);
|
2018-05-09 07:11:12 +08:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, row++,
|
|
|
|
C_("email-address", "_To:"), 0.0, 0.5,
|
|
|
|
entry, 1);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (entry, "changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (mail_entry_callback),
|
2005-03-02 10:20:02 +08:00
|
|
|
mail_info.receipt);
|
1999-03-19 17:12:36 +08:00
|
|
|
|
2005-04-20 08:40:32 +08:00
|
|
|
gtk_widget_grab_focus (entry);
|
|
|
|
|
1999-11-27 02:03:59 +08:00
|
|
|
/* From entry */
|
1999-03-19 17:12:36 +08:00
|
|
|
entry = gtk_entry_new ();
|
2001-11-12 02:35:25 +08:00
|
|
|
gtk_widget_set_size_request (entry, 200, -1);
|
2005-03-02 10:20:02 +08:00
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (entry), BUFFER_SIZE - 1);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry), mail_info.from);
|
2018-05-09 07:11:12 +08:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, row++,
|
|
|
|
C_("email-address", "_From:"), 0.0, 0.5,
|
|
|
|
entry, 1);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (entry, "changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (mail_entry_callback),
|
2005-03-02 10:20:02 +08:00
|
|
|
mail_info.from);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Subject entry */
|
|
|
|
entry = gtk_entry_new ();
|
2001-11-12 02:35:25 +08:00
|
|
|
gtk_widget_set_size_request (entry, 200, -1);
|
2005-03-02 10:20:02 +08:00
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (entry), BUFFER_SIZE - 1);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry), mail_info.subject);
|
2018-05-09 07:11:12 +08:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, row++,
|
|
|
|
_("S_ubject:"), 0.0, 0.5,
|
|
|
|
entry, 1);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (entry, "changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (mail_entry_callback),
|
2005-03-02 10:20:02 +08:00
|
|
|
mail_info.subject);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-04-20 08:40:32 +08:00
|
|
|
/* Body */
|
2001-09-17 20:01:27 +08:00
|
|
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
2003-11-15 21:53:33 +08:00
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_SHADOW_IN);
|
2001-09-17 20:01:27 +08:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2005-04-20 08:40:32 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), scrolled_window, TRUE, TRUE, 0);
|
2001-09-17 20:01:27 +08:00
|
|
|
gtk_widget_show (scrolled_window);
|
|
|
|
|
|
|
|
text_buffer = gtk_text_buffer_new (NULL);
|
|
|
|
|
2008-02-05 17:42:34 +08:00
|
|
|
g_signal_connect (text_buffer, "changed",
|
|
|
|
G_CALLBACK (mesg_body_callback),
|
2008-10-20 14:04:39 +08:00
|
|
|
NULL);
|
2008-02-05 17:42:34 +08:00
|
|
|
|
|
|
|
gtk_text_buffer_set_text (text_buffer, mail_info.comment, -1);
|
|
|
|
|
2001-09-17 20:01:27 +08:00
|
|
|
text_view = gtk_text_view_new_with_buffer (text_buffer);
|
2005-03-02 10:20:02 +08:00
|
|
|
g_object_unref (text_buffer);
|
|
|
|
|
2001-09-17 20:01:27 +08:00
|
|
|
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD);
|
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
|
|
|
|
gtk_widget_show (text_view);
|
2016-05-28 03:13:06 +08:00
|
|
|
#endif
|
2001-09-17 20:01:27 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (dlg);
|
2000-01-16 23:38:38 +08:00
|
|
|
|
2003-11-12 02:11:56 +08:00
|
|
|
run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
gtk_widget_destroy (dlg);
|
|
|
|
|
|
|
|
return run;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2005-03-02 10:20:02 +08:00
|
|
|
static gboolean
|
2003-07-02 20:03:08 +08:00
|
|
|
valid_file (const gchar *filename)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
struct stat buf;
|
|
|
|
|
2005-05-07 03:36:12 +08:00
|
|
|
return g_stat (filename, &buf) == 0 && buf.st_size > 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-01-16 23:38:38 +08:00
|
|
|
static gchar *
|
2003-07-02 20:03:08 +08:00
|
|
|
find_extension (const gchar *filename)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-16 23:38:38 +08:00
|
|
|
gchar *filename_copy;
|
|
|
|
gchar *ext;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* we never free this copy - aren't we evil! */
|
2005-01-07 16:56:10 +08:00
|
|
|
filename_copy = g_strdup (filename);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* find the extension, boy! */
|
|
|
|
ext = strrchr (filename_copy, '.');
|
|
|
|
|
2005-01-07 16:56:10 +08:00
|
|
|
while (TRUE)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-05-07 03:36:12 +08:00
|
|
|
if (!ext || ext[1] == '\0' || strchr (ext, G_DIR_SEPARATOR))
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
g_message (_("some sort of error with the file extension "
|
2005-01-07 16:56:10 +08:00
|
|
|
"or lack thereof"));
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-03-02 10:20:02 +08:00
|
|
|
|
2005-05-07 03:36:12 +08:00
|
|
|
if (0 != g_ascii_strcasecmp (ext, ".gz") &&
|
|
|
|
0 != g_ascii_strcasecmp (ext, ".bz2"))
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
return ext;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
2018-04-26 02:31:11 +08:00
|
|
|
/* we found something, loop back, and look again */
|
2008-10-20 14:04:39 +08:00
|
|
|
*ext = 0;
|
|
|
|
ext = strrchr (filename_copy, '.');
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2005-01-07 16:56:10 +08:00
|
|
|
|
2010-11-10 02:03:47 +08:00
|
|
|
g_free (filename_copy);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-26 01:46:56 +08:00
|
|
|
mail_entry_callback (GtkWidget *widget,
|
2008-10-20 14:04:39 +08:00
|
|
|
gchar *data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-03-02 10:20:02 +08:00
|
|
|
g_strlcpy (data, gtk_entry_get_text (GTK_ENTRY (widget)), BUFFER_SIZE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2016-05-28 03:13:06 +08:00
|
|
|
#ifdef SENDMAIL
|
2003-11-06 23:27:05 +08:00
|
|
|
static void
|
2001-09-17 20:01:27 +08:00
|
|
|
mesg_body_callback (GtkTextBuffer *buffer,
|
2008-10-20 14:04:39 +08:00
|
|
|
gpointer data)
|
1998-07-29 06:22:56 +08:00
|
|
|
{
|
2001-09-26 20:52:12 +08:00
|
|
|
GtkTextIter start_iter;
|
|
|
|
GtkTextIter end_iter;
|
2001-09-17 20:01:27 +08:00
|
|
|
|
2001-11-20 22:46:44 +08:00
|
|
|
gtk_text_buffer_get_bounds (buffer, &start_iter, &end_iter);
|
2005-04-20 08:40:32 +08:00
|
|
|
|
|
|
|
g_free (mesg_body);
|
2001-09-17 20:01:27 +08:00
|
|
|
mesg_body = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE);
|
2003-11-06 23:27:05 +08:00
|
|
|
}
|
1998-07-29 06:22:56 +08:00
|
|
|
|
2016-05-28 02:50:35 +08: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-25 06:05:25 +08:00
|
|
|
static void
|
2016-05-28 02:50:35 +08:00
|
|
|
sendmail_create_headers (FILE *mailpipe)
|
1997-11-25 06:05:25 +08: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 23:52:38 +08:00
|
|
|
/* there is a possibility of a Gimp mail scanner/reader in the */
|
1997-11-25 06:05:25 +08:00
|
|
|
/* future. It will probabaly need that header. */
|
|
|
|
|
|
|
|
fprintf (mailpipe, "To: %s \n", mail_info.receipt);
|
|
|
|
fprintf (mailpipe, "Subject: %s \n", mail_info.subject);
|
2005-04-20 08:40:32 +08:00
|
|
|
if (strlen (mail_info.from) > 0)
|
|
|
|
fprintf (mailpipe, "From: %s \n", mail_info.from);
|
|
|
|
|
2017-03-22 00:45:50 +08:00
|
|
|
fprintf (mailpipe, "X-Mailer: GIMP Useless Mail plug-in %s\n", GIMP_VERSION);
|
1999-03-19 17:12:36 +08:00
|
|
|
|
2008-02-05 17:42:34 +08:00
|
|
|
fprintf (mailpipe, "MIME-Version: 1.0\n");
|
|
|
|
fprintf (mailpipe, "Content-type: multipart/mixed; "
|
|
|
|
"boundary=GUMP-MIME-boundary\n");
|
2005-03-02 10:20:02 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
fprintf (mailpipe, "\n\n");
|
2005-03-02 10:20:02 +08:00
|
|
|
|
2008-02-05 17:42:34 +08:00
|
|
|
fprintf (mailpipe, "--GUMP-MIME-boundary\n");
|
|
|
|
fprintf (mailpipe, "Content-type: text/plain; charset=UTF-8\n\n");
|
2005-03-02 10:20:02 +08:00
|
|
|
|
2001-09-17 20:01:27 +08:00
|
|
|
if (mesg_body)
|
2007-05-31 01:57:26 +08:00
|
|
|
fprintf (mailpipe, "%s", mesg_body);
|
2005-03-02 10:20:02 +08:00
|
|
|
|
1998-07-29 06:22:56 +08:00
|
|
|
fprintf (mailpipe, "\n\n");
|
2005-03-02 10:20:02 +08:00
|
|
|
|
2008-02-05 17:42:34 +08:00
|
|
|
{
|
2016-05-28 02:50:35 +08:00
|
|
|
gchar *content = sendmail_content_type (mail_info.filename);
|
2003-07-02 20:03:08 +08:00
|
|
|
|
2008-02-05 17:42:34 +08: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",
|
|
|
|
mail_info.filename);
|
|
|
|
fprintf (mailpipe, "Content-description: %s\n\n", mail_info.filename);
|
2003-07-02 20:03:08 +08:00
|
|
|
|
2008-02-05 17:42:34 +08:00
|
|
|
g_free (content);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2007-01-12 22:34:09 +08:00
|
|
|
static gboolean
|
2016-05-28 02:50:35 +08:00
|
|
|
sendmail_to64 (const gchar *filename,
|
|
|
|
FILE *outfile,
|
|
|
|
GError **error)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2007-01-12 22:34:09 +08: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 23:38:38 +08:00
|
|
|
{
|
2007-01-12 22:34:09 +08:00
|
|
|
gsize step = MIN (1024, len - c);
|
|
|
|
|
2008-02-05 17:42:34 +08:00
|
|
|
bytes = g_base64_encode_step (in + c, step, TRUE, out, &state, &save);
|
2007-01-12 22:34:09 +08:00
|
|
|
fwrite (out, 1, bytes, outfile);
|
|
|
|
|
|
|
|
c += step;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-01-16 23:38:38 +08:00
|
|
|
|
2007-01-12 22:34:09 +08:00
|
|
|
bytes = g_base64_encode_close (TRUE, out, &state, &save);
|
|
|
|
fwrite (out, 1, bytes, outfile);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2009-07-20 18:39:09 +08:00
|
|
|
g_mapped_file_unref (infile);
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2007-01-12 22:34:09 +08:00
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2005-03-02 10:20:02 +08:00
|
|
|
|
|
|
|
static FILE *
|
|
|
|
sendmail_pipe (gchar **cmd,
|
2008-02-05 17:42:34 +08:00
|
|
|
GPid *pid)
|
2005-03-02 10:20:02 +08:00
|
|
|
{
|
|
|
|
gint fd;
|
|
|
|
GError *err = NULL;
|
|
|
|
|
2016-05-28 06:51:24 +08:00
|
|
|
if (! g_spawn_async_with_pipes (NULL, cmd, NULL,
|
|
|
|
G_SPAWN_DO_NOT_REAP_CHILD |
|
|
|
|
G_SPAWN_SEARCH_PATH,
|
2008-10-20 14:04:39 +08:00
|
|
|
NULL, NULL, pid, &fd, NULL, NULL, &err))
|
2005-03-02 10:20:02 +08:00
|
|
|
{
|
|
|
|
g_message (_("Could not start sendmail (%s)"), err->message);
|
|
|
|
g_error_free (err);
|
|
|
|
|
|
|
|
*pid = -1;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-04-27 04:31:01 +08:00
|
|
|
return fdopen (fd, "wb");
|
2005-03-02 10:20:02 +08:00
|
|
|
}
|
2016-05-28 02:50:35 +08:00
|
|
|
#endif
|