rem: _prot->SyncMailbox(nodes[directory]); } else { BString mb; if (directory == dest_node) mb = msg->FindString("name"); else { mb = nodes[directory]; mb << '/' << msg->FindString("name"); } if (_prot->CreateMailbox(mb.String()) < B_OK) break; nodes[node] = strdup(mb.String()); _prot->mailboxes += mb.String(); _prot->SyncMailbox(mb.String()); node_ref ref; ref.device = device; ref.node = node; watch_node(&ref,B_WATCH_DIRECTORY,this); } break; case B_ENTRY_REMOVED: _prot->CheckForDeletedMessages(); if ((is_dir) && (nodes[node] != NULL)) { _prot->DeleteMailbox(nodes[node]); _prot->mailboxes -= nodes[node]; free((void *)nodes[node]); nodes[node] = NULL; node_ref ref; ref.device = device; ref.node = node; watch_node(&ref,B_STOP_WATCHING,this); } break;
add: break; }
context: 		void MessageReceived(BMessage *msg) {			switch (msg->what) {				case 'INIT': {					if (_prot->InitCheck() < B_OK)						return;										((BMailChainRunner *)(Looper()))->ReportProgress(0,0,"Synchronizing Mailboxes");										BStringList subdirs;					GetSubFolders(&_dest,&subdirs);					BStringList to_delete;					BStringList to_add;					subdirs.NotThere(_prot->mailboxes,&to_add);					if (subdirs.CountItems() != 0) // --- If it's a virgin mailfolder, the user probably just configured his machineand probably *doesn't* want all his mail folders deleted :)						subdirs.NotHere(_prot->mailboxes,&to_delete);					for (int32 i = 0; i < to_add.CountItems(); i++) {						if (_prot->CreateMailbox(to_add[i]) != B_OK)							continue;						_prot->mailboxes += to_add[i];						_prot->SyncMailbox(to_add[i]);					}										_prot->CheckForDeletedMessages(); //--- Refresh the manifest list, delete messages in locally deleted folders										for (int32 i = 0; i < to_delete.CountItems(); i++) {						if (to_delete[i][0] == 0)							continue;						if (_prot->DeleteMailbox(to_delete[i]) == B_OK)							_prot->mailboxes -= to_delete[i];					}										entry_ref ref;					BEntry entry;					_dest.GetEntry(&entry);					entry.GetRef(&ref);					BPath path(&ref), work_path(path);					BNode node(&ref);					node_ref watcher;					node.GetNodeRef(&watcher);					watch_node(&watcher,B_WATCH_DIRECTORY,this);										for (int32 i = 0; i < _prot->mailboxes.CountItems(); i++) {												work_path = path;						work_path.Append(_prot->mailboxes[i]);						node.SetTo(work_path.Path());						node.GetNodeRef(&watcher);						nodes[watcher.node] = strdup(_prot->mailboxes[i]);						if (_prot->mailboxes[i][0] == 0)							continue; //--- We've covered this in the parent monitor						watch_node(&watcher,B_WATCH_DIRECTORY,this);						_prot->SyncMailbox(_prot->mailboxes[i]);					}					((BMailChainRunner *)(Looper()))->ResetProgress();				} break;						case B_NODE_MONITOR: {				int32 opcode;				if (msg->FindInt32("opcode",&opcode) < B_OK)					break;								int64 directory, node(msg->FindInt64("node"));				dev_t device(msg->FindInt32("device"));											bool is_dir;				{					node_ref item_ref;					item_ref.node = node;					item_ref.device = device;					BDirectory dir(&item_ref);					is_dir = (dir.InitCheck() == B_OK);				}								if (opcode == B_ENTRY_MOVED) {					ino_t from, to;					msg->FindInt64("from directory",&from);					msg->FindInt64("to directory",&to);					const char *from_mb(nodes[from]), *to_mb(nodes[to]);					if (to == dest_node)						to_mb = "";					if (from == dest_node)						from_mb = "";					if (from_mb == NULL) {						msg->AddInt64("directory",to);						opcode = B_ENTRY_CREATED;					} else if (to_mb == NULL) {						msg->AddInt64("directory",from);						if (is_dir)							opcode = B_ENTRY_REMOVED;					} else {						if (!is_dir) {							{								node_ref item_ref;								item_ref.node = to;								item_ref.device = device;								BDirectory dir(&item_ref);								BNode node(&dir,msg->FindString("name"));								//--- Why in HELL can't you make a BNode from a node_ref?																if (node.InitCheck() != B_OK)									break; //-- We're late, it's already gone elsewhere. Ignore for now.																BString id;								node.ReadAttrString("MAIL:unique_id",&id);								id.Truncate(id.FindLast('/'));								if (id == to_mb)									break; //-- Already where it belongs, no need to do anything							}															snooze(uint64(5e5));							_prot->SyncMailbox(to_mb);															//node.WriteAttrString("MAIL:unique_id",&id);														_prot->CheckForDeletedMessages();						} else {							BString mb;							if (to_mb[0] == 0)								mb = msg->FindString("name");							else {								mb = to_mb;								mb << '/' << msg->FindString("name");							}							if (strcmp(mb.String(),nodes[node]) == 0)								break;							if (_prot->CreateMailbox(mb.String()) < B_OK)								break;							_prot->mailboxes += mb.String();							_prot->SyncMailbox(mb.String());							_prot->CheckForDeletedMessages();							_prot->DeleteMailbox(nodes[node]);							_prot->mailboxes -= nodes[node];							free((void *)nodes[node]);							nodes[node] = strdup(mb.String());						}						break;					}				}														msg->FindInt64("directory",&directory);				switch (opcode) {					case B_ENTRY_CREATED:						if (!is_dir) {							const char *dir = nodes[directory];							snooze(500000);														if (dir == NULL)								dir = "";															if (!_prot->mailboxes.HasItem(dir))								break;														{								node_ref item_ref;								item_ref.node = directory;								item_ref.device = device;								BDirectory dir(&item_ref);								BNode node(&dir,msg->FindString("name"));								//--- Why in HELL can't you make a BNode from a node_ref?																if (node.InitCheck() != B_OK)									break; //-- We're late, it's already gone elsewhere. Ignore for now.							}														_prot->SyncMailbox(nodes[directory]);						} else {							BString mb;							if (directory == dest_node)								mb = msg->FindString("name");							else {								mb = nodes[directory];								mb << '/' << msg->FindString("name");							}							if (_prot->CreateMailbox(mb.String()) < B_OK)								break;							nodes[node] = strdup(mb.String());							_prot->mailboxes += mb.String();							_prot->SyncMailbox(mb.String());							node_ref ref;							ref.device = device;							ref.node = node;							watch_node(&ref,B_WATCH_DIRECTORY,this);						}						break;					case B_ENTRY_REMOVED:						_prot->CheckForDeletedMessages();						if ((is_dir) && (nodes[node] != NULL)) {							_prot->DeleteMailbox(nodes[node]);							_prot->mailboxes -= nodes[node];							free((void *)nodes[node]);							nodes[node] = NULL;							node_ref ref;							ref.device = device;							ref.node = node;							watch_node(&ref,B_STOP_WATCHING,this);						}						break;				}								} break;			}		}