// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x28e0, %rsp           # imm = 0x28E0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x28b4(%rbp)
movl $0x1, -0x28b8(%rbp)
movl $0x0, -0x28c0(%rbp)
leaq -0x24b0(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x400, %esi            # imm = 0x400
leaq 0x12c11(%rip), %rdx     # 0x1b8e0
movb $0x0, %al
callq 0x2130
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x8d0f
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x8d0f
movq 0x1d2e2(%rip), %rax     # 0x25fd8
movq (%rax), %rax
movq %rax, -0x20a0(%rbp)
movl $0x1, -0x28c0(%rbp)
jmp 0x8da1
movq -0x18(%rbp), %rdi
leaq 0x1380b(%rip), %rsi     # 0x1c525
callq 0x21e0
cmpl $0x0, %eax
jne 0x8d37
movq 0x1d2ad(%rip), %rax     # 0x25fd8
movq (%rax), %rax
movq %rax, -0x20a0(%rbp)
jmp 0x8d4e
movq -0x18(%rbp), %rdi
leaq 0x14952(%rip), %rsi     # 0x1d694
callq 0x2330
movq %rax, -0x20a0(%rbp)
cmpq $0x0, -0x20a0(%rbp)
jne 0x8d9f
movq -0x18(%rbp), %rax
movq %rax, -0x28c8(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x23a0
movq -0x28c8(%rbp), %rcx
movq %rax, %r8
leaq 0x12b79(%rip), %rdi     # 0x1b8f9
leaq 0x10748(%rip), %rsi     # 0x194cf
movl $0xbcb, %edx            # imm = 0xBCB
movb $0x0, %al
callq 0x117c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9021
jmp 0x8da1
leaq -0x24b0(%rbp), %rdi
leaq 0x1101c(%rip), %rsi     # 0x19dcb
callq 0x2330
movq %rax, -0x20a8(%rbp)
cmpq $0x0, -0x20a8(%rbp)
jne 0x8e0f
leaq -0x24b0(%rbp), %rax
movq %rax, -0x28d0(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x23a0
movq -0x28d0(%rbp), %rcx
movq %rax, %r8
leaq 0x12b4c(%rip), %rdi     # 0x1b93c
leaq 0x106d8(%rip), %rsi     # 0x194cf
movl $0xbd3, %edx            # imm = 0xBD3
movb $0x0, %al
callq 0x117c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9021
movq -0x20a0(%rbp), %rsi
leaq -0x2098(%rbp), %rdi
callq 0x9760
leaq -0x28b0(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
leaq -0x2098(%rbp), %rdx
callq 0x9ab0
cmpq $0x0, %rax
je 0x8f89
cmpl $0x1, -0x28b8(%rbp)
jne 0x8f3a
leaq -0x28b0(%rbp), %rdi
leaq 0x12b21(%rip), %rsi     # 0x1b980
movl $0x5, %edx
callq 0x22a0
cmpl $0x0, %eax
jne 0x8f3a
movq -0x20a8(%rbp), %rdi
callq 0x20e0
movq -0x10(%rbp), %rdi
leaq -0x24b0(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x78b0
leaq -0x24b0(%rbp), %rdi
callq 0x2080
movl %eax, -0x28bc(%rbp)
cmpl $-0x1, -0x28bc(%rbp)
jne 0x8eee
leaq -0x24b0(%rbp), %rax
movq %rax, -0x28d8(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x23a0
movq -0x28d8(%rbp), %rcx
movq %rax, %r8
leaq 0x12aab(%rip), %rdi     # 0x1b986
leaq 0x105ed(%rip), %rsi     # 0x194cf
movl $0xbea, %edx            # imm = 0xBEA
movb $0x0, %al
callq 0x117c0
leaq -0x24b0(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl -0x28b4(%rbp), %r8d
addl $0x1, %r8d
movl %r8d, -0x28b4(%rbp)
movl $0x400, %esi            # imm = 0x400
leaq 0x12ab6(%rip), %rdx     # 0x1b9cd
movb $0x0, %al
callq 0x2130
leaq -0x24b0(%rbp), %rdi
leaq 0x10e9f(%rip), %rsi     # 0x19dcb
callq 0x2330
movq %rax, -0x20a8(%rbp)
jmp 0x8f56
movq -0x20a8(%rbp), %rdi
leaq -0x28b0(%rbp), %rdx
leaq 0x1605b(%rip), %rsi     # 0x1efaa
movb $0x0, %al
callq 0x2200
movsbl -0x28b0(%rbp), %eax
cmpl $0xa, %eax
je 0x8f6e
movsbl -0x28b0(%rbp), %eax
cmpl $0xd, %eax
jne 0x8f7a
movl $0x1, -0x28b8(%rbp)
jmp 0x8f84
movl $0x0, -0x28b8(%rbp)
jmp 0x8e22
cmpl $0x0, -0x28c0(%rbp)
jne 0x8f9e
movq -0x20a0(%rbp), %rdi
callq 0x20e0
movq -0x20a8(%rbp), %rdi
callq 0x20e0
movq -0x10(%rbp), %rdi
leaq -0x24b0(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x78b0
leaq -0x24b0(%rbp), %rdi
callq 0x2080
movl %eax, -0x28bc(%rbp)
cmpl $-0x1, -0x28bc(%rbp)
jne 0x901a
leaq -0x24b0(%rbp), %rax
movq %rax, -0x28e0(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x23a0
movq -0x28e0(%rbp), %rcx
movq %rax, %r8
leaq 0x1297f(%rip), %rdi     # 0x1b986
leaq 0x104c1(%rip), %rsi     # 0x194cf
movl $0xc17, %edx            # imm = 0xC17
movb $0x0, %al
callq 0x117c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x28e0, %rsp           # imm = 0x28E0
popq %rbp
retq
nopl (%rax)