Class | TMail::TMailScanner
In: | ext/tmailscanner/tmail/tmailscanner.c
Parent: | Object

                             ruby interface

### Methods

debug debug= new scan

### Constants

Version | = | tmp

### Public Class methods

new(p1, p2, p3)

Document-method: mails_s_new

Creates a new mail

[Source]

    /*
     * Document-method: mails_s_new
     *
     * Creates a new mail
     *
     */
    static VALUE
    mails_s_new(klass, str, ident, cmt)
        VALUE klass, str, ident, cmt;
    {
        struct scanner *sc;
        const char *tmp;

        sc = ALLOC_N(struct scanner, 1);

        StringValue(str);
        sc->pbeg = RSTRING_PTR(str);
        sc->p    = sc->pbeg;
        sc->pend = sc->p + RSTRING_LEN(str);

        sc->flags = 0;
        Check_Type(ident, T_SYMBOL);
        tmp = rb_id2name(SYM2ID(ident));
        if      (strcmp(tmp, "RECEIVED")     == 0) sc->flags |= MODE_RECV;
        else if (strcmp(tmp, "CTYPE")        == 0) sc->flags |= MODE_MIME;
        else if (strcmp(tmp, "CENCODING")    == 0) sc->flags |= MODE_MIME;
        else if (strcmp(tmp, "CDISPOSITION") == 0) sc->flags |= MODE_MIME;

        tmp = rb_get_kcode();
        if (strcmp(tmp, "EUC") == 0 || strcmp(tmp, "SJIS") == 0) {
            sc->flags |= MODE_ISO2022;
        }

        sc->comments = Qnil;
        if (! NIL_P(cmt)) {
            Check_Type(cmt, T_ARRAY);
            sc->comments = cmt;
        }

        return Data_Wrap_Struct(TMailScanner, 0, mails_free, sc);
    }

### Public Instance methods

debug()

Document-method: mails_debug_get

TODO: Documentation needed

[Source]

    /*
     * Document-method: mails_debug_get
     *
     * TODO: Documentation needed
     *
     */
    static VALUE
    mails_debug_get(self)
        VALUE self;
    {
        struct scanner *sc;

        GET_SCANNER(self, sc);
        if (sc->flags & MODE_DEBUG)
            return Qtrue;
        else
            return Qfalse;
    }

debug=(p1)

Document-method: mails_debug_set

TODO: Documentation needed

[Source]

    /*
     * Document-method: mails_debug_set
     *
     * TODO: Documentation needed
     *
     */
    static VALUE
    mails_debug_set(self, flag)
        VALUE self, flag;
    {
        struct scanner *sc;

        GET_SCANNER(self, sc);
        if (RTEST(flag))
            sc->flags |= MODE_DEBUG;
        else
            sc->flags &= ~MODE_DEBUG;
        return Qnil;
    }

scan()

Document-method: mails_scan

TODO: Documentation needed

[Source]

    /*
     * Document-method: mails_scan
     *
     * TODO: Documentation needed
     *
     */
    static VALUE
    mails_scan(self)
        VALUE self;
    {
        struct scanner *sc;
        VALUE arr;

    #define PASS(s,v) pass_token(sc,s,v,arr)
        GET_SCANNER(self, sc);
        if (!sc->p) {
            rb_raise(ScanError, "Mails#scan called before reset");
        }
        arr = rb_assoc_new(Qnil, Qnil);

        while (sc->p < sc->pend) {
            D(puts("new loop"));
            D(printf("char='%c'\n", *sc->p));
            if (IS_LWSP(*sc->p)) {
                D(puts("lwsp"));
                skip_lwsp(sc);
                if (sc->p >= sc->pend)
                    break;
            }

            if (MIME_MODE_P(sc)) {
                if (IS_TOKENCHAR(*sc->p) ||
                        (ISO2022_MODE_P(sc) && (*sc->p == ESC)) ||
                        IS_JCHAR(*sc->p)) {
                    D(puts("token"));
                    PASS(tok_token, scan_token(sc));
                    continue;
                }
            }
            else {
                if (IS_ATOMCHAR(*sc->p) ||
                        (ISO2022_MODE_P(sc) && (*sc->p == ESC)) ||
                        IS_JCHAR(*sc->p)) {
                    VALUE tmp;
                    D(puts("atom"));
                    tmp = scan_atom(sc);
                    PASS(atomsym(sc, tmp), tmp);
                    continue;
                }
            }

            if (*sc->p == '"') {
                D(puts("quoted"));
                PASS(tok_quoted, scan_quoted_word(sc));
                D(puts("quoted"));
            }
            else if (*sc->p == '(') {
                VALUE c;
                D(puts("comment"));
                c = scan_comment(sc);
                if (! NIL_P(sc->comments))
                    rb_ary_push(sc->comments, c);
            }
            else if (*sc->p == '[') {
                D(puts("domlit"));
                PASS(tok_domlit, scan_domain_literal(sc));
            }
            else {
                VALUE ch;
                D(puts("char"));
                ch = rb_str_new(sc->p, 1);
                sc->p++;
                PASS(ch, ch);
            }
        }

        PASS(Qfalse, rb_str_new("$", 1));
        return Qnil;
    }

[Validate]