// File: /workspace/github_c_makefile_star2_O2/inflex[P]ripMIME/mime.c
// Function: MIME_handle_rfc822
int MIME_handle_rfc822( FFGET_FILE *f, char *unpackdir, struct MIMEH_header_info *h, int current_recursion_level, struct SS_object *ss )
{
    /** Decode a RFC822 encoded stream of data from *f  **/
    int result = 0;
    if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: Decoding RFC822 message\n",FL);
    /** If there is no filename, then we have a "standard"
     ** embedded message, which can be just read off as a
     ** continuous stream (simply with new boundaries
     **/
    DMIME LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: Filename='%s', encoding = %d",FL, h->filename, h->content_transfer_encoding);

    //  if ((0)&&( h->content_transfer_encoding != _CTRANS_ENCODING_B64)&&( h->filename[0] == '0' )) 20041217-1635:PLD:
    if (( h->content_transfer_encoding != _CTRANS_ENCODING_B64)&&( h->filename[0] == '\0' ))
    {
        /** Handle a simple plain text wrapped RFC822 email with no encoding applied to it **/
        char *p;

        // If this is a simple 'wrapped' RFC822 email which has no encoding applied to it
        //      (ie, it's just the existing email with a new set of headers around it
        //      then rather than saving it to a file, we'll just peel off these outter
        //      layer of headers and get into the core of the message.  This is why we
        //      call unpack_stage2() because this function just reads the next set of
        //      headers and decodes.
        DMIME LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: Non base64 encoding AND no filename, embedded message\n",FL);
        h->boundary_located = 0;
        result = MIME_unpack_stage2(f, unpackdir, h, current_recursion_level , ss);
        p = BS_top();
        if (p) PLD_strncpy(h->boundary, p,sizeof(h->boundary));
    } else {
        /** ...else... if the section has a filename or B64 type encoding, we need to put it through extra decoding **/
        if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: Embedded message has a filename, decoding to file %s",FL,h->filename);
        result = MIME_decode_encoding( f, unpackdir, h, ss );
        if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: Result of extracting %s is %d",FL,h->filename, result);
        if (result == 0) {
            /** Because we're calling MIME_unpack_single again [ie, recursively calling it
              we need to now adjust the input-filename so that it correctly is prefixed
              with the directory we unpacked to. **/

            if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: Now attempting to extract contents of '%s'",FL,h->filename);
            snprintf(scratch,sizeof(scratch),"%s/%s",unpackdir, h->filename);
            snprintf(h->filename,sizeof(h->filename),"%s",scratch);

            if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: Now attempting to extract contents of '%s'",FL,scratch);
            result = MIME_unpack_single( unpackdir, scratch, current_recursion_level, ss );
            result = 0;
        }
    } /** else-if transfer-encoding != B64 && filename was empty **/
    if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: done handling '%s' result = %d",FL,h->filename, result);
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r14
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
cmpl $0x0, 0x19851(%rip)     # 0x20300
jle 0x6afc
leaq 0xc61f(%rip), %rdi      # 0x130d7
leaq 0xa920(%rip), %rsi      # 0x113df
movl $0xa33, %edx            # imm = 0xA33
xorl %eax, %eax
callq 0xc2a1
cmpl $0x0, 0x1982e(%rip)     # 0x20300
jle 0x6afc
leaq 0x5efd(%rbx), %rcx
movl 0x166f8(%rbx), %r8d
leaq 0xc627(%rip), %rdi      # 0x13110
leaq 0xa8ef(%rip), %rsi      # 0x113df
movl $0xa38, %edx            # imm = 0xA38
xorl %eax, %eax
callq 0xc2a1
cmpl $0x64, 0x166f8(%rbx)
jne 0x6b0d
movl 0x197f5(%rip), %eax     # 0x20300
jmp 0x6b20
cmpb $0x0, 0x5efd(%rbx)
movl 0x197e6(%rip), %eax     # 0x20300
je 0x6c45
testl %eax, %eax
jle 0x6b45
leaq 0x5efd(%rbx), %rcx
leaq 0xc672(%rip), %rdi      # 0x131a4
leaq 0xa8a6(%rip), %rsi      # 0x113df
movl $0xa4d, %edx            # imm = 0xA4D
xorl %eax, %eax
callq 0xc2a1
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x561f
movl %eax, %r12d
cmpl $0x0, 0x197a0(%rip)     # 0x20300
jle 0x6b86
leaq 0x5efd(%rbx), %rcx
leaq 0xc689(%rip), %rdi      # 0x131f9
leaq 0xa868(%rip), %rsi      # 0x113df
movl $0xa4f, %edx            # imm = 0xA4F
movl %r12d, %r8d
xorl %eax, %eax
callq 0xc2a1
testl %r12d, %r12d
jne 0x6c9e
movl %ebp, 0x4(%rsp)
cmpl $0x0, 0x19766(%rip)     # 0x20300
jle 0x6bbd
leaq 0x5efd(%rbx), %rcx
leaq 0xc68d(%rip), %rdi      # 0x13237
leaq 0xa82e(%rip), %rsi      # 0x113df
movl $0xa55, %edx            # imm = 0xA55
xorl %eax, %eax
callq 0xc2a1
leaq 0x5efd(%rbx), %r13
leaq 0x1cb95(%rip), %rbp     # 0x23760
leaq 0xa83a(%rip), %rdx      # 0x1140c
xorl %r12d, %r12d
movl $0x400, %esi            # imm = 0x400
movq %rbp, %rdi
movq %r15, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x2140
leaq 0x1046f(%rip), %rdx     # 0x17060
movl $0x1001, %esi           # imm = 0x1001
movq %r13, %rdi
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2140
cmpl $0x0, 0x196f6(%rip)     # 0x20300
jle 0x6c2d
leaq 0xc624(%rip), %rdi      # 0x13237
leaq 0xa7c5(%rip), %rsi      # 0x113df
leaq 0x1cb3f(%rip), %rcx     # 0x23760
movl $0xa59, %edx            # imm = 0xA59
xorl %eax, %eax
callq 0xc2a1
leaq 0x1cb2c(%rip), %rsi     # 0x23760
movq %r15, %rdi
movl 0x4(%rsp), %edx
movq %r14, %rcx
callq 0x5d29
jmp 0x6c9e
testl %eax, %eax
jle 0x6c63
leaq 0xc4fd(%rip), %rdi      # 0x1314d
leaq 0xa788(%rip), %rsi      # 0x113df
movl $0xa46, %edx            # imm = 0xA46
xorl %eax, %eax
callq 0xc2a1
andl $0x0, 0x59f8(%rbx)
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movl %ebp, %ecx
movq %r14, %r8
callq 0x61b4
movl %eax, %r12d
callq 0xce57
testq %rax, %rax
je 0x6c9e
leaq 0x31fe(%rbx), %rdi
movl $0x27f7, %edx           # imm = 0x27F7
movq %rax, %rsi
callq 0xba3e
cmpl $0x0, 0x1965b(%rip)     # 0x20300
jle 0x6cce
addq $0x5efd, %rbx           # imm = 0x5EFD
leaq 0xc5cd(%rip), %rdi      # 0x13282
leaq 0xa723(%rip), %rsi      # 0x113df
movl $0xa5e, %edx            # imm = 0xA5E
movq %rbx, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0xc2a1
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq