File: send.c

package info (click to toggle)
balsa 0.4.6.2-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 2,264 kB
  • ctags: 2,404
  • sloc: ansic: 26,471; sh: 4,773; makefile: 345; sed: 93
file content (112 lines) | stat: -rw-r--r-- 2,970 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* Balsa E-Mail Client
 * Copyright (C) 1997-98 Stuart Parmenter
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (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
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
 * 02111-1307, USA.
 */

#include "config.h"

#include <stdio.h>
#include <string.h>
#include <gnome.h>

#include "balsa-app.h"
#include "mailbox.h"
#include "misc.h"
#include "mailbackend.h"
#include "send.h"

gboolean
send_message (Message * message, gchar * smtp_server, glong debug)
{
  FILE *tempfp = NULL;
  HEADER *msg;
  gchar *text;
  gchar buffer[PATH_MAX];
  gchar *tmp;

  msg = mutt_new_header ();

  if (!msg->env)
    msg->env = mutt_new_envelope ();

  msg->content = mutt_new_body ();

  msg->content->type = TYPETEXT;
  msg->content->subtype = safe_strdup ("plain");
  msg->content->unlink = 1;
  msg->content->use_disp = 0;

  mutt_mktemp (buffer);
  msg->content->filename = g_strdup (buffer);
  tempfp = safe_fopen (buffer, "w+");

  msg->env->userhdrs = mutt_new_list ();
  {
    LIST* sptr = UserHeader;
    LIST* dptr = msg->env->userhdrs;
    LIST* delptr = 0;
    while (sptr)
      {
	dptr->data = g_strdup(sptr->data);
	sptr       = sptr->next;
	delptr     = dptr;
	dptr->next = mutt_new_list();
	dptr       = dptr->next;
      }
    g_free(delptr->next);
    delptr->next = 0;
  }
#if 0  
  msg->env->userhdrs = UserHeader;
#endif
  tmp = address_to_gchar (message->from);
  msg->env->from = rfc822_parse_adrlist (msg->env->from, tmp);
  g_free (tmp);
  msg->env->subject = g_strdup (message->subject);

  msg->env->to = rfc822_parse_adrlist (msg->env->to, make_string_from_list (message->to_list));
  msg->env->cc = rfc822_parse_adrlist (msg->env->cc, make_string_from_list (message->cc_list));
  msg->env->bcc = rfc822_parse_adrlist (msg->env->bcc, make_string_from_list (message->bcc_list));


  text = ((Body *) (g_list_first (message->body_list)->data))->buffer;
  fputs (text, tempfp);
  fclose (tempfp);
  tempfp = NULL;

  mutt_update_encoding (msg->content);

  switch (balsa_app.outbox->type)
    {
    case MAILBOX_MAILDIR:
    case MAILBOX_MH:
    case MAILBOX_MBOX:
      mutt_send_message (msg, MAILBOX_LOCAL(balsa_app.outbox)->path);
      break;
    case MAILBOX_IMAP:
      mutt_send_message (msg, MAILBOX_IMAP(balsa_app.outbox)->path);
      break;
    default:
      break;
    }

  unlink (msg->content->filename);

  mutt_free_header (&msg);

  return TRUE;
}