mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:32:46 +00:00 
			
		
		
		
	 5e1499d104
			
		
	
	
		5e1499d104
		
	
	
	
	
		
			
			This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).
This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
		
	
			
		
			
				
	
	
		
			76 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
 | |
|  * Copyright (c) 2022, the SerenityOS developers.
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include "AccountHolder.h"
 | |
| 
 | |
| AccountHolder::AccountHolder()
 | |
| {
 | |
|     m_mailbox_tree_model = MailboxTreeModel::create(*this);
 | |
| }
 | |
| 
 | |
| void AccountHolder::add_account_with_name_and_mailboxes(ByteString name, Vector<IMAP::ListItem> const& mailboxes)
 | |
| {
 | |
|     auto account = AccountNode::create(move(name));
 | |
| 
 | |
|     // This holds all of the ancestors of the current leaf folder.
 | |
|     Vector<NonnullRefPtr<MailboxNode>> folder_stack;
 | |
| 
 | |
|     for (auto& mailbox : mailboxes) {
 | |
|         // mailbox.name is converted to StringView to get access to split by string.
 | |
|         auto subfolders = StringView(mailbox.name).split_view(mailbox.reference);
 | |
| 
 | |
|         // Use the last part of the path as the display name.
 | |
|         // For example: "[Mail]/Subfolder" will be displayed as "Subfolder"
 | |
|         auto mailbox_node = MailboxNode::create(account, mailbox, subfolders.last());
 | |
| 
 | |
|         if (subfolders.size() > 1) {
 | |
|             VERIFY(!folder_stack.is_empty());
 | |
| 
 | |
|             // This gets the parent folder of the leaf folder that we just created above.
 | |
|             // For example, with "[Mail]/Subfolder/Leaf", "subfolders" will have three items:
 | |
|             //   - "[Mail]" at index 0.
 | |
|             //   - "Subfolder" at index 1. This is the parent folder of the leaf folder.
 | |
|             //   - "Leaf" at index 2. This is the leaf folder.
 | |
|             // Notice that the parent folder is always two below the size of "subfolders".
 | |
|             // This assumes that there was two listings before this, in this exact order:
 | |
|             // 1. "[Mail]"
 | |
|             // 2. "[Mail]/Subfolder"
 | |
|             auto& parent_folder = folder_stack.at(subfolders.size() - 2);
 | |
| 
 | |
|             // Only keep the ancestors of the current leaf folder.
 | |
|             folder_stack.shrink(subfolders.size() - 1);
 | |
| 
 | |
|             parent_folder->add_child(mailbox_node);
 | |
|             VERIFY(!mailbox_node->has_parent());
 | |
|             mailbox_node->set_parent(parent_folder);
 | |
| 
 | |
|             // FIXME: This assumes that the server has the "CHILDREN" capability.
 | |
|             if (mailbox.flags & (unsigned)IMAP::MailboxFlag::HasChildren)
 | |
|                 folder_stack.append(mailbox_node);
 | |
|         } else {
 | |
|             // FIXME: This assumes that the server has the "CHILDREN" capability.
 | |
|             if (mailbox.flags & (unsigned)IMAP::MailboxFlag::HasChildren) {
 | |
|                 if (!folder_stack.is_empty() && folder_stack.first()->select_name() != mailbox.name) {
 | |
|                     // This is a new root folder, clear the stack as there are no ancestors of the current leaf folder at this point.
 | |
|                     folder_stack.clear();
 | |
|                 }
 | |
| 
 | |
|                 folder_stack.append(mailbox_node);
 | |
|             }
 | |
| 
 | |
|             account->add_mailbox(move(mailbox_node));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     m_accounts.append(move(account));
 | |
|     rebuild_tree();
 | |
| }
 | |
| 
 | |
| void AccountHolder::rebuild_tree()
 | |
| {
 | |
|     m_mailbox_tree_model->invalidate();
 | |
| }
 |