+ g_object_unref (iter);
+ iter = NULL;
+
+ /* If some messages would have to be downloaded, ask the user to
+ * make a connection. It's generally easier to do this here (in the mainloop)
+ * than later in a thread:
+ */
+ if (tny_list_get_length (not_opened_cached_headers) > 0) {
+ gboolean connected = modest_platform_connect_and_wait (GTK_WINDOW (win));
+
+ /* Don't go further if a connection would be necessary but none is available: */
+ if (!connected) {
+ g_object_unref (not_opened_headers);
+ g_object_unref (not_opened_cached_headers);
+ return;
+ }
+ }
+
+ /* Register the headers before actually creating the windows: */
+ TnyIterator *iter_not_opened = tny_list_create_iterator (not_opened_headers);
+ while (!tny_iterator_is_done (iter_not_opened)) {
+ TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
+ modest_window_mgr_register_header (mgr, header);
+ g_object_unref (header);
+
+ tny_iterator_next (iter_not_opened);
+ }
+ g_object_unref (iter_not_opened);
+ iter_not_opened = NULL;
+
+ TnyIterator *iter_cached = tny_list_create_iterator (not_opened_cached_headers);
+ while (!tny_iterator_is_done (iter_cached)) {
+ TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_cached));
+ modest_window_mgr_register_header (mgr, header);
+ g_object_unref (header);
+
+ tny_iterator_next (iter_cached);
+ }
+ g_object_unref (iter_cached);
+ iter_cached = NULL;
+