diff --git a/src/chatview.cpp b/src/chatview.cpp
index 6b783afc4e2c7cdc725f06f39df5e0d783e8adc5..85f484abe0bb217b823ca60890c733c416d4f8e4 100644
--- a/src/chatview.cpp
+++ b/src/chatview.cpp
@@ -252,8 +252,12 @@ webkit_chat_container_script_dialog(GtkWidget* webview, gchar *interaction, Chat
                 auto wantedFilename = filename + info.displayName;
                 auto duplicate = 0;
                 while (std::ifstream(wantedFilename).good()) {
-                    wantedFilename = filename + "(" + std::to_string(duplicate) + ")" + info.displayName;
                     ++duplicate;
+                    auto extensionIdx = info.displayName.find_last_of(".");
+                    if (extensionIdx == std::string::npos)
+                        wantedFilename = filename + info.displayName + " (" + std::to_string(duplicate) + ")";
+                    else
+                        wantedFilename = filename + info.displayName.substr(0, extensionIdx) + " (" + std::to_string(duplicate) + ")" + info.displayName.substr(extensionIdx);
                 }
                 model->acceptTransfer(priv->conversation_->uid, interactionId, wantedFilename);
             } catch (...) {