Module: Gurgitate::Deliver

Included in:
Gurgitate
Defined in:
lib/gurgitate/deliver.rb,
lib/gurgitate/deliver/mh.rb,
lib/gurgitate/deliver/mbox.rb,
lib/gurgitate/deliver/maildir.rb

Defined Under Namespace

Modules: MBox, MH, Maildir Classes: MailboxFound

Instance Method Summary collapse

Instance Method Details

#save(mailbox) ⇒ Object

Saves a message to mailbox, after detecting what the mailbox’s format is.

mailbox

A string containing the path of the mailbox to save the message to. If it is of the form “=mailbox”, it saves the message to Maildir/mailbox. Otherwise, it simply saves the message to the file mailbox.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/gurgitate/deliver.rb', line 27

def save(mailbox)

    if mailbox[0,1]=='=' and @maildir != nil then
        if @folderstyle == Maildir and mailbox !~ /^=\./ then
            mailbox["="]=@maildir+"/."
        else
            mailbox["="]=@maildir+"/"
        end
    end

    if mailbox[0,1] != '/' then
        log("Cannot save to relative filenames!  Saving to spool file");
        mailbox=spoolfile
    end

    begin
        [MBox,Maildir,MH].each do |mod|
            if mod::check_mailbox(mailbox) then
                extend mod
                raise MailboxFound
            end
        end

        # Huh, nothing could find anything.  Oh well,
        # let's default to whatever's in @folderstyle.  (I
        # guess we'll be making a new mailbox, eh?)

        if Module === @folderstyle then
            #
            # Careful we don't get the wrong instance variable 
            folderstyle=@folderstyle 

            extend folderstyle
        else
            # No hints from the user either.  Let's guess!
            # I'll use the same heuristic that Postfix uses--if the
            # mailbox name ends with a /, then make it a Maildir,
            # otherwise make it a mail file
            if mailbox =~ /\/$/ then
                extend Maildir
            else
                extend MBox
            end
        end
        
    rescue MailboxFound
        # Don't need to do anything--we only have to worry
        # about it if there wasn't a mailbox there.
        nil
    end

    begin
        deliver_message(mailbox)
    rescue SystemCallError
        self.log "Gack!  Something went wrong: " + $!.to_s
        raise
        # exit 75
    end
end