Logo Search packages:      
Sourcecode: pan version File versions  Download package

GMimeMessage * BodyPane::create_followup_or_reply ( bool  is_reply  ) 

HEADERS

BODY

Definition at line 1543 of file body-pane.cc.

References pan::StringView::len, pan::StringView::str, pan::StringView::trim(), and pan::GNKSA::trim_references().

{
  GMimeMessage * msg (0);

  if (_message)
  {
    msg = g_mime_message_new (false);

    // fallback character encodings
    const char * group_charset (_charset.c_str());
    const GMimeContentType * type (g_mime_object_get_content_type (GMIME_OBJECT(_message)));
    const char * message_charset (type ? g_mime_content_type_get_parameter (type, "charset") : 0);

    ///
    ///  HEADERS
    ///

    // To:, Newsgroups:
    const std::string from       (get_header (_message, "From",        message_charset, group_charset));
    const std::string newsgroups (get_header (_message, "Newsgroups",  message_charset, group_charset));
    const std::string fup_to     (get_header (_message, "Followup-To", message_charset, group_charset));
    const std::string reply_to   (get_header (_message, "Reply-To",    message_charset, group_charset));
    if (is_reply || fup_to=="poster") {
      const std::string& to (reply_to.empty() ? from : reply_to);
      g_mime_message_add_recipients_from_string (msg, GMIME_RECIPIENT_TYPE_TO, to.c_str());
    } else {
      const std::string& groups (fup_to.empty() ? newsgroups : fup_to);
      g_mime_message_add_header (msg, "Newsgroups", groups.c_str());
    }

    // Subject:
    StringView v = g_mime_message_get_header (_message, "Subject");
    std::string h = header_to_utf8 (v, message_charset, group_charset);
    std::string val (normalize_subject_re (h));
    if (val.find ("Re:") != 0) // add "Re: " if we don't have one
      val.insert (0, "Re: ");
    g_mime_message_set_subject (msg, val.c_str());

    // attribution lines

    const char * cpch = g_mime_message_get_header (_message, "From");
    h = header_to_utf8 (cpch, message_charset, group_charset);
    g_mime_message_add_header (msg, "X-Draft-Attribution-Author", h.c_str());

    cpch = g_mime_message_get_message_id (_message);
    h = header_to_utf8 (cpch, message_charset, group_charset);
    g_mime_message_add_header (msg, "X-Draft-Attribution-Id", h.c_str());

    char * tmp = g_mime_message_get_date_string (_message);
    h = header_to_utf8 (tmp, message_charset, group_charset);
    g_mime_message_add_header (msg, "X-Draft-Attribution-Date", h.c_str());
    g_free (tmp);

    // references
    const char * header = "References";
    v = g_mime_message_get_header (_message, header);
    val.assign (v.str, v.len);
    if (!val.empty())
      val += ' ';
    val += "<";
    val += g_mime_message_get_message_id (_message);
    val += ">";
    val = GNKSA :: trim_references (val);
    g_mime_message_add_header (msg, header, val.c_str());

    ///
    ///  BODY
    ///

    GtkTextIter start, end;
    if (gtk_text_buffer_get_selection_bounds (_buffer, &start, &end))
    {
      // go with the user-selected region w/o modifications.
      // since it's in the text pane it's already utf-8...
      h = gtk_text_buffer_get_text (_buffer, &start, &end, false);
    }
    else
    {
      // get the body; remove the sig
      h = get_utf8_body (_message, group_charset);
      StringView v (h);
      int sig_index (0);
      if (GNKSA::find_signature_delimiter (h, sig_index) != GNKSA::SIG_NONE)
        v.len = sig_index;
      v.trim ();
      h = std::string (v.str, v.len);
    }

    // quote the body
    std::string s;
    for (const char *c(h.c_str()); c && *c; ++c) {
      if (c==h.c_str() || c[-1]=='\n')
        s += (*c=='>' ? ">" : "> ");
      s += *c;
    }

    // set the clone's content object with our modified body
    GMimeStream * stream = g_mime_stream_mem_new ();
    g_mime_stream_write_string (stream, s.c_str());
    GMimeDataWrapper * wrapper = g_mime_data_wrapper_new_with_stream (stream, GMIME_PART_ENCODING_8BIT);
    GMimePart * part = g_mime_part_new ();
    GMimeContentType * new_type = g_mime_content_type_new_from_string ("text/plain; charset=UTF-8");
    g_mime_part_set_content_type (part, new_type);
    g_mime_part_set_content_object (part, wrapper);
    g_mime_part_set_encoding (part, GMIME_PART_ENCODING_8BIT);
    g_mime_message_set_mime_part (msg, GMIME_OBJECT(part));
    g_object_unref (wrapper);
    g_object_unref (part);
    g_object_unref (stream);
//std::cerr << LINE_ID << " here is the modified clone\n [" << g_mime_message_to_string(msg) << ']' << std::endl;
  }

  return msg;
}


Generated by  Doxygen 1.6.0   Back to index