### Home Classes Methods

### In Files

- ext/tmailscanner/tmail/tmailscanner.c

### Parent

Object

### Methods

- ::new
- #debug
- #debug=
- #scan

### Files

- CHANGES
- LICENSE
- NOTES
- README
- Rakefile
- MANIFEST
- Makefile
- depend
- Makefile
- COPYING
- README

### Class/Module Index

Quicksearch

- TMail
- TMail::Address
- TMail::AddressGroup
- TMail::AddressHeader
- TMail::Attachment
- TMail::ContentDispositionHeader
- TMail::ContentTransferEncodingHeader
- TMail::ContentTypeHeader
- TMail::DateTimeHeader
- TMail::EncryptedHeader
- TMail::FilePort
- TMail::HeaderField
- TMail::KeywordsHeader
- TMail::Mail
- TMail::MailFlags
- TMail::Maildir
- TMail::MaildirLoader
- TMail::MaildirPort
- TMail::MboxLoader
- TMail::MessageIdHeader
- TMail::MhLoader
- TMail::MhMailbox
- TMail::MhPort
- TMail::MimeVersionHeader
- TMail::Parser
- TMail::Port
- TMail::ReceivedHeader
- TMail::ReferencesHeader
- TMail::ReturnPathHeader
- TMail::SingleAddressHeader
- TMail::StringPort
- TMail::StructuredHeader
- TMail::SyntaxError
- TMail::TMailScanner
- TMail::TextUtils
- TMail::UNIXMbox
- TMail::UnstructuredHeader
- CharDet
- CharDet::Big5DistributionAnalysis
- CharDet::Big5Prober
- CharDet::CharDistributionAnalysis
- CharDet::CharSetGroupProber
- CharDet::CharSetProber
- CharDet::CodingStateMachine
- CharDet::EUCJPContextAnalysis
- CharDet::EUCJPDistributionAnalysis
- CharDet::EUCJPProber
- CharDet::EUCKRDistributionAnalysis
- CharDet::EUCKRProber
- CharDet::EUCTWDistributionAnalysis
- CharDet::EUCTWProber
- CharDet::EscCharSetProber
- CharDet::GB2312DistributionAnalysis
- CharDet::GB2312Prober
- CharDet::HebrewProber
- CharDet::JapaneseContextAnalysis
- CharDet::Latin1Prober
- CharDet::MBCSGroupProber
- CharDet::MultiByteCharSetProber
- CharDet::SBCSGroupProber
- CharDet::SJISContextAnalysis
- CharDet::SJISDistributionAnalysis
- CharDet::SJISProber
- CharDet::SingleByteCharSetProber
- CharDet::UTF8Prober
- CharDet::UniversalDetector

No matching classes.

# TMail::TMailScanner

### Constants

Version

### Public Class Methods

new(p1, p2, p3) click to toggle source

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() click to toggle source

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) click to toggle source

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() click to toggle source

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]

Generated with the Darkfish Rdoc Generator 2.