OK, so I have finally put everything back together. Here is a summary of my experience on this subject. Hopefully this will come useful to someone else.
A loud clang from the side window. The window no longer stops in the right position when raising it. Instead it continues outside the rubber lining of the roof, making it impossible to shut the door properly.
The side window has two L-formed metal parts glued to its lower front corner. Even though the parts are glued on opposite sides of the glass, they are both turned the same way (inward) to support each other. These metal parts serve as a stopper that prevents the window from raising above a certain point when they hit another L-shaped metal plate that is mounted on the inside of the door. The clang occurs when one or both window stoppers come loose from the glass and fall into the door.
How to repair:
Either buy a new side window (they are not terribly expensive) or try to glue the stoppers back on the old side window. In the first case you have to remove the window fully from the door.
In the second case, it could be sufficient to remove the door lining only and then remove the large loudspeaker in the door. When the window is in its bottommost position you can access the corner of the glass where the stoppers are supposed to be fastened through the loudspeaker hole. The stoppers themselves will be lying somewhere in the bottom of door since they can't go anywhere else. I did my repair by removing the glass and glueing the stoppers back outside but with hindsight it would have been much easier just to glue them back in situ. The problem with the in situ repair is that it may be hard to clean the glass properly before glueing, especially the outward side since it is somewhat hard to reach. It is easy to see where to attach the stoppers since their locations are apparent from residue of the original glue, a greenish stuff that can be sanded off the glass.
Before I sanded off the original glue, I used masking tape to indicate where to glue the stoppers back. As soon as the original glue is gone, there is otherwise no way to see where the stoppers should go. People have had a lot of trouble glueing these stoppers since they won't stick for long. I went for the best epoxy I could find, JB Weld, and was careful to follow the instructions as best as I could. However, I had the same problem as many others have had; after a couple of days, the metal pieces just fell off again. I believe it could have something to with that epoxy is quite brittle and not flexible enough for this application. I then heard of an adhesive tape from 3M called VHB (Very High Bonding?). Apparently it is used for all kinds of applications, such as glueing wings of airplanes, so I gave it a shot and this has worked so far. It is very easy to use: just clean the surfaces, cut the tape with a pair of scissors, attach the tape to the stopper, remove the protecting film from the other side of the tape, attach to the glass and press. Full strength after 24 hours.
While I was at it anyway, I also bought some 3M spray glue that I used to get the protective foil back inside the door (behind the door lining is a transparent plastic foil that protects the door insides from water). The foil inside my door was damaged, probably from earlier repairs, so I just bought a new one from Mercedes for a couple of dollars and attached it using the spray glue. This particular spray glue works like stickies and allows you to remove the foil later without ruining it. 3M is really a great company (I am not affiliated with them but I love their products)
Inside the door there are actually two travel stops, one forward and one rear. The forward one is the aforementioned one, which prevents the forward lower corner of the window to travel past it. The rear one is similar, also L-shaped. Both travel stops can be adjusted vertically so that the window stops in the precisely right position, against the rubber lining of the roof. Adjust the stops by loosening a nut and moving the stops up or down to the right position. Beware: if you loosen the nut to much, the L-shaped part inside will fall off into the door. It can be tricky to get back. The rear one can be reattached by inserting your hand inside the door from below (if you are not too ham-fisted). To get the front one back, I had to pull it up inside the door using a sewing thread, which was a little tricky. Another caveat is that the part is top-heavy. Even if you don't loosen the nut enough for the travel stop to fall out, it may still become so loose that it rotates around its axis and ends up in an incorrect position. This happened to me and I just could not understand why the window didn't stop as expected or where the scraping sound came from… So ensure that the door's travel stop is properly aligned before you tighten the nut! This can be done by simply reaching with your hand inside the door from below. See the attached picture for an illustration of the forward stoppers.