Repository: python-telegram-bot/python-telegram-bot (Python)

Issue:
Can't change filename when send document after upgrading to v11.1.0
### Steps to reproduce
1. Generate a pickle file "test" (I didn't test other common files yet)

2. Send this file to user

`bot.send_document(chat_id=user_chat_id, document=open('./test', 'rb'), filename="test")`

or

`bot.send_document(chat_id=user_chat_id, document=open('./test', 'rb'))`

### Expected behaviour
User will receive a file named **test**

### Actual behaviour
User received a file named **application.octet-stream**

### Configuration
**Operating System:** 

Debian (Server, where I first found this issue)

Ubuntu(Local, **I test on v10.1.0, everything is fine**, so I upgrade to v11.1.0, then I have the same issue as Debian Server)

**Version of Python, python-telegram-bot & dependencies:**

``$ python -m telegram``

*My Local Ubuntu After Upgrade:*
python-telegram-bot 11.1.0
certifi 2018.08.24
future 0.16.0
Python 3.6.6 (default, Sep 12 2018, 18:26:19)  [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]

The pictures shows results of python-telegram-bot v10.1.0 (the first one) and v11.1.0 (the second one) :

![screenshot from 2018-09-29 14-16-06](https://user-images.githubusercontent.com/16657782/46246951-2382a080-c3f4-11e8-9f01-b4dd90960ccd.png)




Discussion:
Alright, I see what's going on here. Apparently our codes doesn't think filenames without a `.` in them are valid, and therefore it overrides it with the mimetype.
The reason you're only seeing this bug on the v11.1 is because before the code would only run if the file was deemed "not-an-image".
This should be a fairly trivial change though, thanks a lot for the report :D
@jsmnbom Thank you for your reply!



Patch:
diff --git a/telegram/files/inputfile.py b/telegram/files/inputfile.py
index 0d614db3439..977c325c525 100644
--- a/telegram/files/inputfile.py
+++ b/telegram/files/inputfile.py
@@ -70,7 +70,7 @@ def __init__(self, obj, filename=None, attach=None):
                     self.filename)[0] or DEFAULT_MIME_TYPE
             else:
                 self.mimetype = DEFAULT_MIME_TYPE
-        if not self.filename or '.' not in self.filename:
+        if not self.filename:
             self.filename = self.mimetype.replace('/', '.')
 
     @property


Test patch:
diff --git a/tests/data/telegram b/tests/data/telegram
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/test_inputfile.py b/tests/test_inputfile.py
index fd34c841b6a..1c667d3df0b 100644
--- a/tests/test_inputfile.py
+++ b/tests/test_inputfile.py
@@ -63,3 +63,34 @@ def test_mimetypes(self):
         assert (InputFile(BytesIO(b'blah'), filename='tg.notaproperext').mimetype ==
                 'application/octet-stream')
         assert InputFile(BytesIO(b'blah')).mimetype == 'application/octet-stream'
+
+    def test_filenames(self):
+        assert InputFile(open('tests/data/telegram.jpg', 'rb')).filename == 'telegram.jpg'
+        assert InputFile(open('tests/data/telegram.jpg', 'rb'),
+                         filename='blah').filename == 'blah'
+        assert InputFile(open('tests/data/telegram.jpg', 'rb'),
+                         filename='blah.jpg').filename == 'blah.jpg'
+        assert InputFile(open('tests/data/telegram', 'rb')).filename == 'telegram'
+        assert InputFile(open('tests/data/telegram', 'rb'),
+                         filename='blah').filename == 'blah'
+        assert InputFile(open('tests/data/telegram', 'rb'),
+                         filename='blah.jpg').filename == 'blah.jpg'
+
+        class MockedFileobject(object):
+            # A open(?, 'rb') without a .name
+            def __init__(self, f):
+                self.f = open(f, 'rb')
+
+            def read(self):
+                return self.f.read()
+
+        assert InputFile(MockedFileobject('tests/data/telegram.jpg')).filename == 'image.jpeg'
+        assert InputFile(MockedFileobject('tests/data/telegram.jpg'),
+                         filename='blah').filename == 'blah'
+        assert InputFile(MockedFileobject('tests/data/telegram.jpg'),
+                         filename='blah.jpg').filename == 'blah.jpg'
+        assert InputFile(MockedFileobject('tests/data/telegram')).filename == 'application.octet-stream' # flake8: noqa
+        assert InputFile(MockedFileobject('tests/data/telegram'),
+                         filename='blah').filename == 'blah'
+        assert InputFile(MockedFileobject('tests/data/telegram'),
+                         filename='blah.jpg').filename == 'blah.jpg'