// File: /workspace/github_c_makefile_star2_O1/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, 0x1a586(%rip)     # 0x21300
jle 0x6d96
leaq 0xd324(%rip), %rdi      # 0x140a7
leaq 0xb655(%rip), %rsi      # 0x123df
movl $0xa33, %edx            # imm = 0xA33
xorl %eax, %eax
callq 0xc960
cmpl $0x0, 0x1a563(%rip)     # 0x21300
jle 0x6dc7
leaq 0x5efd(%rbx), %rcx
movl 0x166f8(%rbx), %r8d
leaq 0xd32c(%rip), %rdi      # 0x140e0
leaq 0xb624(%rip), %rsi      # 0x123df
movl $0xa38, %edx            # imm = 0xA38
xorl %eax, %eax
callq 0xc960
cmpl $0x64, 0x166f8(%rbx)
je 0x6ddd
cmpb $0x0, 0x5efd(%rbx)
je 0x6f07
cmpl $0x0, 0x1a51c(%rip)     # 0x21300
jle 0x6e07
leaq 0x5efd(%rbx), %rcx
leaq 0xd380(%rip), %rdi      # 0x14174
leaq 0xb5e4(%rip), %rsi      # 0x123df
movl $0xa4d, %edx            # imm = 0xA4D
xorl %eax, %eax
callq 0xc960
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x5888
movl %eax, %r12d
cmpl $0x0, 0x1a4de(%rip)     # 0x21300
jle 0x6e48
leaq 0x5efd(%rbx), %rcx
leaq 0xd397(%rip), %rdi      # 0x141c9
leaq 0xb5a6(%rip), %rsi      # 0x123df
movl $0xa4f, %edx            # imm = 0xA4F
movl %r12d, %r8d
xorl %eax, %eax
callq 0xc960
testl %r12d, %r12d
jne 0x6f68
movl %ebp, 0x4(%rsp)
cmpl $0x0, 0x1a4a4(%rip)     # 0x21300
jle 0x6e7f
leaq 0x5efd(%rbx), %rcx
leaq 0xd39b(%rip), %rdi      # 0x14207
leaq 0xb56c(%rip), %rsi      # 0x123df
movl $0xa55, %edx            # imm = 0xA55
xorl %eax, %eax
callq 0xc960
leaq 0x5efd(%rbx), %r13
leaq 0x1d8d3(%rip), %rbp     # 0x24760
leaq 0xb578(%rip), %rdx      # 0x1240c
xorl %r12d, %r12d
movl $0x400, %esi            # imm = 0x400
movq %rbp, %rdi
movq %r15, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x2140
leaq 0x111da(%rip), %rdx     # 0x1808d
movl $0x1001, %esi           # imm = 0x1001
movq %r13, %rdi
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2140
cmpl $0x0, 0x1a434(%rip)     # 0x21300
jle 0x6eef
leaq 0xd332(%rip), %rdi      # 0x14207
leaq 0xb503(%rip), %rsi      # 0x123df
leaq 0x1d87d(%rip), %rcx     # 0x24760
movl $0xa59, %edx            # imm = 0xA59
xorl %eax, %eax
callq 0xc960
leaq 0x1d86a(%rip), %rsi     # 0x24760
movq %r15, %rdi
movl 0x4(%rsp), %edx
movq %r14, %rcx
callq 0x5fde
jmp 0x6f68
cmpl $0x0, 0x1a3f2(%rip)     # 0x21300
jle 0x6f2a
leaq 0xd206(%rip), %rdi      # 0x1411d
leaq 0xb4c1(%rip), %rsi      # 0x123df
movl $0xa46, %edx            # imm = 0xA46
xorl %eax, %eax
callq 0xc960
movl $0x0, 0x59f8(%rbx)
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movl %ebp, %ecx
movq %r14, %r8
callq 0x6463
movl %eax, %r12d
callq 0xd613
testq %rax, %rax
je 0x6f68
leaq 0x31fe(%rbx), %rdi
movl $0x27f7, %edx           # imm = 0x27F7
movq %rax, %rsi
callq 0xbfb6
cmpl $0x0, 0x1a391(%rip)     # 0x21300
jle 0x6f98
addq $0x5efd, %rbx           # imm = 0x5EFD
leaq 0xd2d3(%rip), %rdi      # 0x14252
leaq 0xb459(%rip), %rsi      # 0x123df
movl $0xa5e, %edx            # imm = 0xA5E
movq %rbx, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0xc960
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq