aboutsummaryrefslogtreecommitdiffstats
path: root/spec/script/handle-mail-replies_spec.rb
blob: 90a8de27cf24054b40a40bd2f896bf0e4155a455 (plain)
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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.H
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require "external_command"

def mail_reply_test(email_filename)
    Dir.chdir Rails.root do
        xc = ExternalCommand.new("script/handle-mail-replies", "--test")
        xc.run(load_file_fixture(email_filename))

        xc.err.should == ""
        return xc
    end
end

describe "When filtering" do
    it "should not fail when not in test mode" do
        xc = ExternalCommand.new("script/handle-mail-replies")
        xc.run(load_file_fixture("track-response-exim-bounce.email"))
        xc.err.should == ""
    end

    it "should detect an Exim bounce" do
        r = mail_reply_test("track-response-exim-bounce.email")
        r.status.should == 1
        r.out.should == "user@example.com\n"
    end

    it "should detect a WebShield delivery error message" do
        r = mail_reply_test("track-response-webshield-bounce.email")
        r.status.should == 1
        r.out.should == "failed.user@example.co.uk\n"
    end

    it "should detect a MS Exchange non-permanent delivery error message" do
        r = mail_reply_test("track-response-ms-bounce.email")
        r.status.should == 1
        r.out.should == ""
    end

    it "should pass on a non-bounce message" do
        r = mail_reply_test("incoming-request-bad-uuencoding.email")
        r.status.should == 0
        r.out.should == ""
    end

    it "should detect a multipart bounce" do
        r = mail_reply_test("track-response-multipart-report.email")
        r.status.should == 1
        r.out.should == "FailedUser@example.com\n"
    end

    it "should detect a generic out-of-office" do
        r = mail_reply_test("track-response-generic-oof.email")
        r.status.should == 2
    end

    it "should detect an Exchange-style out-of-office" do
        r = mail_reply_test("track-response-exchange-oof-1.email")
        r.status.should == 2
    end

    it "should detect a Lotus Domino-style out-of-office" do
        r = mail_reply_test("track-response-lotus-oof-1.email")
        r.status.should == 2
    end

    it "should detect a Messagelabs-style out-of-office" do
        r = mail_reply_test("track-response-messagelabs-oof-1.email")
        r.status.should == 2
    end

    it "should detect an out-of-office that has an X-POST-MessageClass header" do
        r = mail_reply_test("track-response-messageclass-oof.email")
        r.status.should == 2
    end

    it "should detect an Outlook(?)-style out-of-office" do
        r = mail_reply_test("track-response-outlook-oof.email")
        r.status.should == 2
    end

    it "should detect an ABCMail-style out-of-office" do
        r = mail_reply_test("track-response-abcmail-oof.email")
        r.status.should == 2
    end
end
pan class="n">priv->ic->acc; for (i = 0; i < G_N_ELEMENTS(fb_props_strs); i++) { str = set_getstr(&acct->set, fb_props_strs[i]); if (str == NULL) { ret = FALSE; } g_value_init(&val, G_TYPE_STRING); g_value_set_string(&val, str); g_object_set_property(G_OBJECT(priv->api), fb_props_strs[i], &val); g_value_unset(&val); } str = set_getstr(&acct->set, "mid"); if (str != NULL) { uint = g_ascii_strtoull(str, NULL, 10); g_value_init(&val, G_TYPE_UINT64); g_value_set_uint64(&val, uint); g_object_set_property(G_OBJECT(priv->api), "mid", &val); g_value_unset(&val); } else { ret = FALSE; } str = set_getstr(&acct->set, "uid"); if (str != NULL) { id = FB_ID_FROM_STR(str); g_value_init(&val, FB_TYPE_ID); g_value_set_int64(&val, id); g_object_set_property(G_OBJECT(priv->api), "uid", &val); g_value_unset(&val); } else { ret = FALSE; } fb_api_rehash(priv->api); return ret; } void fb_data_save(FbData *fata) { account_t *acct; const gchar *str; FbDataPrivate *priv; gchar *dup; guint i; guint64 uint; GValue val = G_VALUE_INIT; g_return_if_fail(FB_IS_DATA(fata)); priv = fata->priv; acct = priv->ic->acc; for (i = 0; i < G_N_ELEMENTS(fb_props_strs); i++) { g_value_init(&val, G_TYPE_STRING); g_object_get_property(G_OBJECT(priv->api), fb_props_strs[i], &val); str = g_value_get_string(&val); set_setstr(&acct->set, fb_props_strs[i], (gchar *) str); g_value_unset(&val); } g_value_init(&val, G_TYPE_UINT64); g_object_get_property(G_OBJECT(priv->api), "mid", &val); uint = g_value_get_uint64(&val); g_value_unset(&val); dup = g_strdup_printf("%" G_GINT64_FORMAT, uint); set_setstr(&acct->set, "mid", dup); g_free(dup); g_value_init(&val, G_TYPE_INT64); g_object_get_property(G_OBJECT(priv->api), "uid", &val); uint = g_value_get_int64(&val); g_value_unset(&val); dup = g_strdup_printf("%" FB_ID_FORMAT, uint); set_setstr(&acct->set, "uid", dup); g_free(dup); } void fb_data_add_groupchat(FbData *fata, struct groupchat *gc) { FbDataPrivate *priv; g_return_if_fail(FB_IS_DATA(fata)); priv = fata->priv; g_hash_table_replace(priv->gcs, gc, gc); } void fb_data_remove_groupchat(FbData *fata, struct groupchat *gc) { FbDataPrivate *priv; g_return_if_fail(FB_IS_DATA(fata)); priv = fata->priv; g_hash_table_remove(priv->gcs, gc); } void fb_data_add_thread_head(FbData *fata, FbId tid) { FbDataPrivate *priv; FbId *dtid; g_return_if_fail(FB_IS_DATA(fata)); priv = fata->priv; dtid = g_memdup(&tid, sizeof tid); g_queue_push_head(priv->tids, dtid); } void fb_data_add_thread_tail(FbData *fata, FbId tid) { FbDataPrivate *priv; FbId *dtid; g_return_if_fail(FB_IS_DATA(fata)); priv = fata->priv; dtid = g_memdup(&tid, sizeof tid); g_queue_push_tail(priv->tids, dtid); } void fb_data_clear_threads(FbData *fata) { FbDataPrivate *priv; FbId *tid; g_return_if_fail(FB_IS_DATA(fata)); priv = fata->priv; while (!g_queue_is_empty(priv->tids)) { tid = g_queue_pop_head(priv->tids); g_free(tid); } } FbId fb_data_get_thread(FbData *fata, guint n) { FbDataPrivate *priv; FbId *tid; g_return_val_if_fail(FB_IS_DATA(fata), 0); priv = fata->priv; tid = g_queue_peek_nth(priv->tids, n); if (tid == NULL) { return 0; } return *tid; } void fb_data_add_timeout(FbData *fata, const gchar *name, guint interval, b_event_handler func, gpointer data) { FbDataPrivate *priv; gchar *key; guint id; g_return_if_fail(FB_IS_DATA(fata)); priv = fata->priv; fb_data_clear_timeout(fata, name, TRUE); key = g_strdup(name); id = b_timeout_add(interval, func, data); g_hash_table_replace(priv->evs, key, GUINT_TO_POINTER(id)); } void fb_data_clear_timeout(FbData *fata, const gchar *name, gboolean remove) { FbDataPrivate *priv; gpointer ptr; guint id; g_return_if_fail(FB_IS_DATA(fata)); priv = fata->priv; ptr = g_hash_table_lookup(priv->evs, name); id = GPOINTER_TO_UINT(ptr); if ((id > 0) && remove) { b_event_remove(id); } g_hash_table_remove(priv->evs, name); } FbApi * fb_data_get_api(FbData *fata) { FbDataPrivate *priv; g_return_val_if_fail(FB_IS_DATA(fata), NULL); priv = fata->priv; return priv->api; } struct im_connection * fb_data_get_connection(FbData *fata) { FbDataPrivate *priv; g_return_val_if_fail(FB_IS_DATA(fata), NULL); priv = fata->priv; return priv->ic; } void fb_data_add_message(FbData *fata, FbApiMessage *msg) { FbDataPrivate *priv; g_return_if_fail(FB_IS_DATA(fata)); priv = fata->priv; g_queue_push_tail(priv->msgs, msg); } void fb_data_remove_message(FbData *fata, FbApiMessage *msg) { FbDataPrivate *priv; g_return_if_fail(FB_IS_DATA(fata)); priv = fata->priv; g_queue_remove(priv->msgs, msg); } GSList * fb_data_take_messages(FbData *fata, FbId uid) { FbApiMessage *msg; FbDataPrivate *priv; GList *l; GList *prev; GSList *msgs = NULL; g_return_val_if_fail(FB_IS_DATA(fata), NULL); priv = fata->priv; l = priv->msgs->tail; while (l != NULL) { msg = l->data; prev = l->prev; if (msg->uid == uid) { msgs = g_slist_prepend(msgs, msg); g_queue_delete_link(priv->msgs, l); } l = prev; } return msgs; }