summaryrefslogtreecommitdiffstats
path: root/source/xap/pan/495bfb2eb9228b5b5cef8b50e11af577e4b473f8.patch
blob: 6b876d1ede67d8725cd5af8c1cbed873874c63f3 (plain) (blame)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
From 495bfb2eb9228b5b5cef8b50e11af577e4b473f8 Mon Sep 17 00:00:00 2001
From: Detlef Graef <detlef.graef@yahoo.de>
Date: Sun, 5 Jul 2020 08:47:54 +0200
Subject: [PATCH] Fix for GMime3 build (Posting error). Issues #103 and #114

---
 pan/gui/post-ui.cc | 176 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 126 insertions(+), 50 deletions(-)

diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index 8769ec5..eb21384 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -1598,86 +1598,178 @@ namespace
 GMimeMessage*
 PostUI :: new_message_from_ui (Mode mode, bool copy_body)
 {
+#ifdef HAVE_GMIME_30
 
   GMimeMessage * msg(0);
-  msg = g_mime_message_new (false);
+  msg = g_mime_message_new (true);
+  const char * charset_cstr = _charset.c_str();
 
   // headers from the ui: From
   const Profile profile (get_current_profile ());
   std::string s;
   profile.get_from_header (s);
-#ifdef HAVE_GMIME_30
-  g_mime_message_add_mailbox (msg, GMIME_ADDRESS_TYPE_SENDER, NULL, s.c_str());
+  g_mime_message_add_mailbox (msg, GMIME_ADDRESS_TYPE_FROM, profile.username.c_str(), profile.address.c_str());
+
+  // headers from the ui: Subject
+  const char * cpch (gtk_entry_get_text (GTK_ENTRY(_subject_entry)));
+  if (cpch) {
+    g_mime_message_set_subject (msg, cpch, charset_cstr);
+  }
+
+  // headers from the ui: To
+  const StringView to (gtk_entry_get_text (GTK_ENTRY(_to_entry)));
+  if (!to.empty())
+    pan_g_mime_message_add_recipients_from_string (msg, GMIME_ADDRESS_TYPE_TO, to.str);
+
+  // headers from the ui: Newsgroups
+  const StringView groups (gtk_entry_get_text (GTK_ENTRY(_groups_entry)));
+  if (!groups.empty())
+    g_mime_object_set_header ((GMimeObject *) msg, "Newsgroups", groups.str, charset_cstr);
+
+  // headers from the ui: Followup-To
+  const StringView followupto (gtk_entry_get_text (GTK_ENTRY(_followupto_entry)));
+  if (!followupto.empty())
+    g_mime_object_set_header ((GMimeObject *) msg, "Followup-To", followupto.str, charset_cstr);
+
+  // headers from the ui: Reply-To
+  const StringView replyto (gtk_entry_get_text (GTK_ENTRY(_replyto_entry)));
+  if (!replyto.empty())
+    g_mime_object_set_header ((GMimeObject *) msg, "Reply-To", replyto.str, charset_cstr);
+
+  // headers from posting profile(via prefs): X-Face
+  if (!profile.xface.empty())
+  {
+    std::string f;
+    f += " " + profile.xface;
+    g_mime_object_set_header ((GMimeObject *) msg, "X-Face", f.c_str(), charset_cstr);
+  }
+
+  // add the 'hidden headers' (references)
+  const gchar * h_key_str;
+  foreach_const (str2str_t, _hidden_headers, it)
+    if ((mode==DRAFTING) || (it->first.find ("X-Draft-")!=0))
+    {
+      h_key_str = it->first.c_str();
+      if ( g_ascii_strncasecmp (h_key_str, "Content", 7) )
+      {
+        g_mime_object_set_header ((GMimeObject *) msg, it->first.c_str(), it->second.c_str(), charset_cstr);
+      }
+    }  
+
+  // build headers from the 'more headers' entry field
+  std::map<std::string,std::string> headers;
+  GtkTextBuffer * buf (_headers_buf);
+  GtkTextIter start, end;
+  gtk_text_buffer_get_bounds (buf, &start, &end);
+  char * pch = gtk_text_buffer_get_text (buf, &start, &end, false);
+  StringView key, val, v(pch);
+  v.trim ();
+  while (v.pop_token (val, '\n') && val.pop_token(key,':')) {
+    key.trim ();
+    val.eat_chars (1);
+    val.trim ();
+    std::string key_str (key.to_string());
+    if (extra_header_is_editable (key, val))
+      g_mime_object_set_header ((GMimeObject *) msg, key.to_string().c_str(),
+                                val.to_string().c_str(), charset_cstr);
+  }
+  g_free (pch);
+
+  // User-Agent
+  if ((mode==POSTING || mode == UPLOADING) && _prefs.get_flag (USER_AGENT_PREFS_KEY, true))
+    g_mime_object_set_header ((GMimeObject *) msg, "User-Agent", get_user_agent(), charset_cstr);
+
+  // Message-ID for single text-only posts
+  if (mode==DRAFTING || ((mode==POSTING || mode==UPLOADING) && _prefs.get_flag (MESSAGE_ID_PREFS_KEY, false))) {
+    const std::string message_id = generate_message_id(profile);
+    pan_g_mime_message_set_message_id (msg, message_id.c_str());
+  }
+
+  // body & charset
+  {
+    std::string body;
+    if (copy_body) body = get_body();
+
+    GMimeStream *  stream =  g_mime_stream_mem_new_with_buffer (body.c_str(), body.size());
+
+    const std::string charset ((mode==POSTING && !_charset.empty()) ? _charset : "UTF-8");
+    if (charset != "UTF-8") {
+      // add a wrapper to convert from UTF-8 to $charset
+      GMimeStream * tmp = g_mime_stream_filter_new (stream);
+      g_object_unref (stream);
+      GMimeFilter * filter = g_mime_filter_charset_new ("UTF-8", charset.c_str());
+      g_mime_stream_filter_add (GMIME_STREAM_FILTER(tmp), filter);
+      g_object_unref (filter);
+      stream = tmp;
+    }
+    GMimeDataWrapper * content_object = g_mime_data_wrapper_new_with_stream (stream, GMIME_CONTENT_ENCODING_DEFAULT);
+    g_object_unref (stream);
+    GMimePart * part = g_mime_part_new ();
+    g_mime_part_set_content (part, content_object);
+
+    pch = g_strdup_printf ("text/plain; charset=%s", charset.c_str());
+    GMimeContentType * type = g_mime_content_type_parse (NULL, pch);
+    g_free (pch);
+    g_mime_object_set_content_type ((GMimeObject *) part, type); // part owns type now. type isn't refcounted.
+
+    if (mode != UPLOADING) g_mime_part_set_content_encoding (part, _enc);
+
+    g_object_unref (content_object);
+    g_mime_message_set_mime_part (msg, GMIME_OBJECT(part));
+    g_object_unref (part);
+  }
+
+  return msg;
+
 #else
+
+  GMimeMessage * msg(0);
+  msg = g_mime_message_new (false);
+
+  // headers from the ui: From
+  const Profile profile (get_current_profile ());
+  std::string s;
+  profile.get_from_header (s);
   g_mime_message_set_sender (msg, s.c_str());
-#endif
 
   // headers from the ui: Subject
   const char * cpch (gtk_entry_get_text (GTK_ENTRY(_subject_entry)));
   if (cpch) {
-#ifdef HAVE_GMIME_30
-    g_mime_message_set_subject (msg, cpch, NULL);
-#else
     g_mime_message_set_subject (msg, cpch);
-#endif
   }
 
   // headers from the ui: To
   const StringView to (gtk_entry_get_text (GTK_ENTRY(_to_entry)));
   if (!to.empty())
-#ifdef HAVE_GMIME_30
-    pan_g_mime_message_add_recipients_from_string (msg, GMIME_ADDRESS_TYPE_TO, to.str);
-#else
     pan_g_mime_message_add_recipients_from_string (msg, GMIME_RECIPIENT_TYPE_TO, to.str);
-#endif
 
   // headers from the ui: Newsgroups
   const StringView groups (gtk_entry_get_text (GTK_ENTRY(_groups_entry)));
   if (!groups.empty())
-#ifdef HAVE_GMIME_30
-    g_mime_object_set_header ((GMimeObject *) msg, "Newsgroups", groups.str, NULL);
-#else
     g_mime_object_set_header ((GMimeObject *) msg, "Newsgroups", groups.str);
-#endif
 
   // headers from the ui: Followup-To
   const StringView followupto (gtk_entry_get_text (GTK_ENTRY(_followupto_entry)));
   if (!followupto.empty())
-#ifdef HAVE_GMIME_30
-    g_mime_object_set_header ((GMimeObject *) msg, "Followup-To", followupto.str, NULL);
-#else
     g_mime_object_set_header ((GMimeObject *) msg, "Followup-To", followupto.str);
-#endif
 
   // headers from the ui: Reply-To
   const StringView replyto (gtk_entry_get_text (GTK_ENTRY(_replyto_entry)));
   if (!replyto.empty())
-#ifdef HAVE_GMIME_30
-    g_mime_object_set_header ((GMimeObject *) msg, "Reply-To", replyto.str, NULL);
-#else
     g_mime_object_set_header ((GMimeObject *) msg, "Reply-To", replyto.str);
-#endif
 
   // headers from posting profile(via prefs): X-Face
   if (!profile.xface.empty())
   {
     std::string f;
     f += " " + profile.xface;
-#ifdef HAVE_GMIME_30
-    g_mime_object_set_header ((GMimeObject *) msg, "X-Face", f.c_str(), NULL);
-#else
     g_mime_object_set_header ((GMimeObject *) msg, "X-Face", f.c_str());
-#endif
   }
 
   // add the 'hidden headers'
   foreach_const (str2str_t, _hidden_headers, it)
     if ((mode==DRAFTING) || (it->first.find ("X-Draft-")!=0))
-#ifdef HAVE_GMIME_30
-      g_mime_object_set_header ((GMimeObject *) msg, it->first.c_str(), it->second.c_str(), NULL);
-#else
       g_mime_object_set_header ((GMimeObject *) msg, it->first.c_str(), it->second.c_str());
-#endif
 
   // build headers from the 'more headers' entry field
   std::map<std::string,std::string> headers;
@@ -1693,23 +1785,14 @@ PostUI :: new_message_from_ui (Mode mode, bool copy_body)
     val.trim ();
     std::string key_str (key.to_string());
     if (extra_header_is_editable (key, val))
-#ifdef HAVE_GMIME_30
-      g_mime_object_set_header ((GMimeObject *) msg, key.to_string().c_str(),
-                                val.to_string().c_str(), NULL);
-#else
       g_mime_object_set_header ((GMimeObject *) msg, key.to_string().c_str(),
                                 val.to_string().c_str());
-#endif
   }
   g_free (pch);
 
   // User-Agent
   if ((mode==POSTING || mode == UPLOADING) && _prefs.get_flag (USER_AGENT_PREFS_KEY, true))
-#ifdef HAVE_GMIME_30
-    g_mime_object_set_header ((GMimeObject *) msg, "User-Agent", get_user_agent(), NULL);
-#else
     g_mime_object_set_header ((GMimeObject *) msg, "User-Agent", get_user_agent());
-#endif
 
   // Message-ID for single text-only posts
   if (mode==DRAFTING || ((mode==POSTING || mode==UPLOADING) && _prefs.get_flag (MESSAGE_ID_PREFS_KEY, false))) {
@@ -1738,19 +1821,10 @@ PostUI :: new_message_from_ui (Mode mode, bool copy_body)
     g_object_unref (stream);
     GMimePart * part = g_mime_part_new ();
     pch = g_strdup_printf ("text/plain; charset=%s", charset.c_str());
-
-#ifdef HAVE_GMIME_30
-    GMimeContentType * type = g_mime_content_type_parse (NULL, pch);
-#else
     GMimeContentType * type = g_mime_content_type_new_from_string (pch);
-#endif
     g_free (pch);
     g_mime_object_set_content_type ((GMimeObject *) part, type); // part owns type now. type isn't refcounted.
-#ifdef HAVE_GMIME_30
-    g_mime_part_set_content(part, content_object);
-#else
     g_mime_part_set_content_object (part, content_object);
-#endif
     if (mode != UPLOADING) g_mime_part_set_content_encoding (part, _enc);
     g_object_unref (content_object);
     g_mime_message_set_mime_part (msg, GMIME_OBJECT(part));
@@ -1758,6 +1832,8 @@ PostUI :: new_message_from_ui (Mode mode, bool copy_body)
   }
 
   return msg;
+  
+#endif
 }
 
 void
-- 
GitLab