MailPad開発記 DAY 9 - CcBcc機能

なかなかSTARTTLSコマンドを最初に発信する方法がわからない...
ということで、今日はCcBccに対応させてみます。
libsylphに添付されているドキュメントのcompose.txtを見てみると、


gint compose_set_headers (ComposeInfo *compose,
const gchar *to,
const gchar *cc,
const gchar *bcc,
const gchar *replyto,
const gchar *subject);

ComposeInfoに作成するメッセージのヘッダ情報を指定します。
文字コードUTF-8 である必要があります。

compose: ComposeInfo構造体へのポインタ
to: To(宛先)
cc: Cc(カーボンコピー)
bcc: Bcc(ブラインドカーボンコピー)
replyto: Reply-To(返信先)
subject: Subject(件名)
戻り値: 成功した場合は0、失敗した場合は-1を返します。

とあります。
この機能を利用すればよさそうです。

callbacks.c

void
do_compose(const PrefsAccount *ac,
const gchar *to,
const gchar *cc,
const gchar *bcc
const gchar *subject,
const gchar *body)
{
ComposeInfo *compose;

compose = compose_info_new((PrefsAccount *) ac, COMPOSE_NEW);

compose_set_headers(compose, to, cc, bcc, NULL, subject);
compose_set_body(compose, body);
compose_set_encoding(compose, CS_UTF_8, NULL);

compose_write_to_file(compose, "UMPC.txt", NULL);

compose_info_free(compose);
}


callbacks.c

void
on_button_clicked (GtkButton *button,
gpointer user_data)
{
syl_init();
set_debug_mode(TRUE);

GtkEntry *entry_to = (GtkEntry*)lookup_widget((GtkWidget*)button, (gchar *)"entry_to");
GtkEntry *entry_cc = (GtkEntry*)lookup_widget((GtkWidget*)button, (gchar *)"entry_cc");
GtkEntry *entry_bcc = (GtkEntry*)lookup_widget((GtkWidget*)button, (gchar *)"entry_bcc");
GtkEntry *entry_subject = (GtkEntry*)lookup_widget((GtkWidget*)button, (gchar *)"entry_subject");
GtkTextView *textview = (GtkTextView*)lookup_widget((GtkWidget*)button, (gchar *)"textview");

gchar *to = (gchar*)gtk_entry_get_text(entry_to);
gchar *cc = (gchar*)gtk_entry_get_text(entry_cc);
gchar *bcc = (gchar*)gtk_entry_get_text(entry_bcc);
gchar *subject = (gchar*)gtk_entry_get_text(entry_subject);

GtkTextBuffer *textbuffer = gtk_text_view_get_buffer(textview);
GtkTextIter start, end;
gtk_text_buffer_get_start_iter(textbuffer,&start);
gtk_text_buffer_get_end_iter(textbuffer,&end);
gchar *body = gtk_text_buffer_get_text(textbuffer,&start,&end,TRUE);

PrefsAccount *ac = set_account((GtkWidget *)button);
do_compose(ac, to, cc, bcc, subject, body);
if(ac->pop_before_smtp) pop_message(ac);
send_message(ac, to, "UMPC.txt");

syl_cleanup();
}

関数の引数を増やしてしまっていますが そこは勘弁してください。
また、entry_cc、entry_bccが空のときの対処もしたほうがよさそうです。