JAMES-4007 Prevent channel inactivity to clear literal while IMAP APPEND is in progress
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
index 4adab34..3e3e26d 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
@@ -221,7 +221,12 @@
 
                     try {
                         parseImapMessage(ctx, null, attachment, Pair.of(reader, size), readerIndex)
-                            .ifPresent(ctx::fireChannelRead);
+                            .ifPresent(message -> {
+                                ctx.fireChannelRead(message);
+                                // Remove ongoing subscription: now on lifecycle of the message will be managed by ImapChannelUpstreamHandler.
+                                // Not doing this causes IDLEd IMAP connections to clear IMAP append literal while they are processed.
+                                attachment.remove(SUBSCRIPTION);
+                            });
                     } catch (DecodingException e) {
                         ctx.fireExceptionCaught(e);
                     }
@@ -237,6 +242,7 @@
 
                     });
             attachment.put(SUBSCRIPTION, (Disposable) () -> {
+                // Clear the file if the connection is reset while buffering the litteral.
                 subscribe.dispose();
                 fileChunkConsumer.discard();
             });