// File: /workspace/github_c_makefile_star2_O2/inflex[P]ripMIME/mime.c
// Function: MIME_unpack_mailbox
int MIME_unpack_mailbox( char *unpackdir, char *mpname, int current_recursion_level, struct SS_object *ss )
{
    FFGET_FILE f;
    FILE *fi;
    FILE *fo;
    char fname[1024];
    char line[1024];
    int mcount=0;
    int lastlinewasblank=1;
    int result;
    int input_is_stdin=0;

    snprintf(fname,sizeof(fname),"%s/tmp.email000.mailpack",unpackdir);
    if ((mpname[0] == '-')&&(mpname[1] == '\0'))
    {
        fi = stdin;
        input_is_stdin=1;
    } else {
        //      fi = fopen(mpname,"r");
        if (strcmp(mpname,"-")==0) fi = stdin; else fi = fopen(mpname,"r"); // 20040208-1715:PLD
        if (!fi)
        {
            LOGGER_log("%s:%d:MIME_unpack_mailbox:ERROR: Cannot open '%s' for reading (%s)",FL, mpname,strerror(errno));
            return -1;
        }
    }

    fo = fopen(fname,"w");
    if (!fo)
    {
        LOGGER_log("%s:%d:MIME_unpack_mailbox:ERROR: Cannot open '%s' for writing  (%s)",FL, fname,strerror(errno));
        return -1;
    }

    FFGET_setstream(&f, fi);
    while (FFGET_fgets(line,sizeof(line),&f))
    {
        // If we have the construct of "\n\rFrom ", then we
        //      can be -pretty- sure that a new email is about
        //      to start

        if ((lastlinewasblank==1)&&(strncasecmp(line,"From ",5)==0))
        {
            // Close the mailpack
            fclose(fo);
            // Now, decode the mailpack
            //MIME_unpack_single(unpackdir, fname, current_recursion_level, ss);
            // 20040317-2358:PLD
            MIME_unpack_single(unpackdir, fname, current_recursion_level ,ss );
            // Remove the now unpacked mailpack
            result = remove(fname);
            if (result == -1)
            {
                LOGGER_log("%s:%d:MIME_unpack_mailbox:ERROR: removing temporary mailpack '%s' (%s)",FL, fname,strerror(errno));
            }
            // Create a new mailpack filename, and keep on going...
            snprintf(fname,sizeof(fname),"%s/tmp.email%03d.mailpack",unpackdir,++mcount);
            fo = fopen(fname,"w");
        }
        else
        {
            fprintf(fo,"%s",line);
        }

        // If the line is blank, then note this down because
        //  if our NEXT line is a From, then we know that
        //      we have reached the end of the email
        //
        if ((line[0] == '\n') || (line[0] == '\r'))
        {
            lastlinewasblank=1;
        }
        else lastlinewasblank=0;
    } // While fgets()

    // Don't attempt to close STDIN if that's where the mailpack/mailbox
    //      has come from.  Although this should really cause problems,
    //      it's better to be safe than sorry.

    if (input_is_stdin == 0)
    {
        fclose(fi);
    }

    // Now, even though we have run out of lines from our main input file
    //  it DOESNT mean we dont have some more decoding to do, in fact
    //      quite the opposite, we still have one more file to decode
    // Close the mailpack
    fclose(fo);

    // Now, decode the mailpack
    //MIME_unpack_single(unpackdir, fname, current_recursion_level, ss);
    // 20040317-2358:PLD
    MIME_unpack_single(unpackdir, fname, current_recursion_level , ss );
    // Remove the now unpacked mailpack
    result = remove(fname);
    if (result == -1)
    {
        LOGGER_log("%s:%d:MIME_unpack_mailbox:ERROR: removing temporary mailpack '%s' (%s)",FL, fname,strerror(errno));
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2898, %rsp           # imm = 0x2898
movq %rcx, 0x10(%rsp)
movl %edx, (%rsp)
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xcc50(%rip), %rdx      # 0x13a19
leaq 0x20(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rcx
xorl %eax, %eax
callq 0x2140
cmpb $0x2d, (%rbx)
jne 0x6df2
cmpb $0x0, 0x1(%rbx)
je 0x6e33
cmpb $0x0, 0x1(%rbx)
je 0x7034
leaq 0xe70b(%rip), %rsi      # 0x15504
movq %rbx, %rdi
callq 0x2350
movq %rax, %r15
movb $0x1, %bpl
testq %r15, %r15
jne 0x6e3f
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xcc13(%rip), %rdi      # 0x13a32
leaq 0xa5b9(%rip), %rsi      # 0x113df
movl $0xbcb, %edx            # imm = 0xBCB
movq %rbx, %rcx
jmp 0x7013
movq 0x1819e(%rip), %rax     # 0x1efd8
movq (%rax), %r15
xorl %ebp, %ebp
leaq 0xb0e5(%rip), %rsi      # 0x11f2b
leaq 0x20(%rsp), %rdi
callq 0x2350
testq %rax, %rax
je 0x6fef
movq %rax, %rbx
movl %ebp, 0x4(%rsp)
movq %r14, 0x8(%rsp)
leaq 0x828(%rsp), %r12
movq %r12, %rdi
movq %r15, 0x18(%rsp)
movq %r15, %rsi
callq 0x7573
pushq $0x1
popq %r14
leaq 0x420(%rsp), %r13
leaq 0x20(%rsp), %rbp
xorl %r15d, %r15d
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdx
callq 0x76f2
testq %rax, %rax
je 0x6f7b
testl %r14d, %r14d
je 0x6ec5
movq %r13, %rdi
leaq 0xcc00(%rip), %rsi      # 0x13ab9
pushq $0x5
popq %rdx
callq 0x22b0
testl %eax, %eax
je 0x6ed5
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2160
jmp 0x6f5f
movq %rbx, %rdi
callq 0x20f0
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movl (%rsp), %edx
movq 0x10(%rsp), %rcx
callq 0x5d29
movq %rbp, %rdi
callq 0x2090
cmpl $-0x1, %eax
jne 0x6f2e
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xcbaa(%rip), %rdi      # 0x13abf
leaq 0xa4c3(%rip), %rsi      # 0x113df
movl $0xbea, %edx            # imm = 0xBEA
movq %rbp, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xc2a1
incl %r15d
movl $0x400, %esi            # imm = 0x400
movq %rbp, %rdi
leaq 0xcbc6(%rip), %rdx      # 0x13b06
movq %rbx, %rcx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x2140
movq %rbp, %rdi
leaq 0xafd4(%rip), %rsi      # 0x11f2b
callq 0x2350
movq %rax, %rbx
movb 0x420(%rsp), %al
cmpb $0xd, %al
sete %cl
cmpb $0xa, %al
sete %al
orb %cl, %al
movzbl %al, %r14d
jmp 0x6e91
cmpb $0x0, 0x4(%rsp)
je 0x6f8c
movq 0x18(%rsp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x20f0
leaq 0x20(%rsp), %rbx
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movl (%rsp), %edx
movq 0x10(%rsp), %rcx
callq 0x5d29
movq %rbx, %rdi
callq 0x2090
xorl %ebx, %ebx
cmpl $-0x1, %eax
jne 0x7020
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xcaef(%rip), %rdi      # 0x13abf
leaq 0xa408(%rip), %rsi      # 0x113df
xorl %ebx, %ebx
leaq 0x20(%rsp), %rcx
movl $0xc17, %edx            # imm = 0xC17
movq %rax, %r8
xorl %eax, %eax
callq 0xc2a1
jmp 0x7020
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xca73(%rip), %rdi      # 0x13a75
leaq 0xa3d6(%rip), %rsi      # 0x113df
leaq 0x20(%rsp), %rcx
movl $0xbd3, %edx            # imm = 0xBD3
movq %rax, %r8
xorl %eax, %eax
callq 0xc2a1
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x2898, %rsp           # imm = 0x2898
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x17f9d(%rip), %rax     # 0x1efd8
movq (%rax), %r15
jmp 0x6e04