Commit cf25c7bad7

cf25c7bad755a7b79596721ab36f551f4d8107bf

parent: 66dea52d21

Unsigned

cmc <hello@cleberg.net> · 2025-02-25 02:59 UTC

fix indentation in email-migration post

Layout: unified · split

content/blog/2025-02-24-email-migration.org +19 −18
@@ -83,23 +83,23 @@ import shutil
83 83
84# Loop through all files in the current folder 84# Loop through all files in the current folder
85for file in glob.glob("*.eml"): 85for file in glob.glob("*.eml"):
86 # Create boolean to check if we should move the file 86 # Create boolean to check if we should move the file
87 move = False 87 move = False
88 88
89 # Open the current file 89 # Open the current file
90 f = open(file, 'r') 90 f = open(file, 'r')
91 91
92 # For each line in file, find the From header 92 # For each line in file, find the From header
93 for line in f: 93 for line in f:
94 if line.startswith("From:"): 94 if line.startswith("From:"):
95 # If we find ourself, mark the message for move 95 # If we find ourself, mark the message for move
96 if "user@example.com" in line: 96 if "user@example.com" in line:
97 move = True 97 move = True
98 98
99 # Close the file 99 # Close the file
100 f.close() 100 f.close()
101 101
102 # Move the file, if marked for move 102 # Move the file, if marked for move
103 if move == True: 103 if move == True:
104 filepath = os.path.join("/Users/YOUR_USERNAME/.maildir/migadu/Archive/cur/", file) 104 filepath = os.path.join("/Users/YOUR_USERNAME/.maildir/migadu/Archive/cur/", file)
105 new_filepath = os.path.join("/Users/YOUR_USERNAME/.maildir/migadu/Sent/cur/", file) 105 new_filepath = os.path.join("/Users/YOUR_USERNAME/.maildir/migadu/Sent/cur/", file)
@@ -164,24 +164,24 @@ import shutil
164 164
165# Loop through all files in the sub-folders under Archive 165# Loop through all files in the sub-folders under Archive
166for file in glob.glob("*.eml"): 166for file in glob.glob("*.eml"):
167 # Create boolean to check if we should move the file 167 # Create boolean to check if we should move the file
168 move = False 168 move = False
169 169
170 # Open the current file 170 # Open the current file
171 f = open(file, 'r') 171 f = open(file, 'r')
172 172
173 # For each line in file, find the X-Pm-Date header 173 # For each line in file, find the X-Pm-Date header
174 for line in f: 174 for line in f:
175 if line.startswith("X-Pm-Date"): 175 if line.startswith("X-Pm-Date"):
176 # Split the line into a list by spaces; 176 # Split the line into a list by spaces;
177 # Then select the item that contains the year 177 # Then select the item that contains the year
178 year = line.split(" ")[4] 178 year = line.split(" ")[4]
179 move = True 179 move = True
180 180
181 # Close the file 181 # Close the file
182 f.close() 182 f.close()
183 183
184 # Move the file, if marked for move 184 # Move the file, if marked for move
185 if move == True: 185 if move == True:
186 filepath = os.path.join("/Users/YOUR_USERNAME/.maildir/migadu/Archive/cur/", file) 186 filepath = os.path.join("/Users/YOUR_USERNAME/.maildir/migadu/Archive/cur/", file)
187 new_filepath = os.path.join(f"/Users/YOUR_USERNAME/.maildir/migadu/Archive/{year}/cur/", file) 187 new_filepath = os.path.join(f"/Users/YOUR_USERNAME/.maildir/migadu/Archive/{year}/cur/", file)
@@ -220,9 +220,10 @@ import shutil
220 220
221# Loop through all files in the sub-folders under Archive 221# Loop through all files in the sub-folders under Archive
222for file in glob.glob("*/cur/*"): 222for file in glob.glob("*/cur/*"):
223 # Remove the characters at the end of the file name created by =mu= 223 # Remove the characters at the end of the file name created by =mu=
224 new_file = file.split(",U=",1)[0] 224 new_file = file.split(",U=",1)[0]
225 # Move the file to the new file name 225
226 # Move the file to the new file name
226 shutil.move(file, new_file) 227 shutil.move(file, new_file)
227#+end_src 228#+end_src
228 229