Email
如何將 Maildir 移動到另一個使用者的子目錄?
當員工離開公司時,我想將他們的整個 Maildir 移動為“老員工”帳戶中的文件夾。
鑑於 Maildir 專門使用文件系統,我覺得應該可以做到
mv ~fred/Maildir ~oldemployees/Maildir/fred
或類似。如果我這樣做,我如何觸發郵件客戶端注意到有一個新目錄?
在我們的帶有 Dovecot 的 IMAP 伺服器上,我這樣做,將整個 Maildir 層次結構複製到另一個使用者郵箱的子文件夾中:
定義變數,以便可以複製/粘貼其餘部分
olduser=martina olddir=/home/$olduser/Maildir newuser=jasmin newgroup=users newdir=/home/$newuser/Maildir newfolder="Martina" newdest="$newdir/.$newfolder"
將所有文件夾和子文件夾移動到另一個使用者的子文件夾中
mkdir -v "$newdest" for d in cur new tmp; do mv -vi "$olddir/$d" "$newdest/"; done # Move only folders which contain mails, # and exclude some special folders like Trash, etc. cd $olddir for d in .??*; do if [[ "$d" =~ ^.(Junk|Trash)$ ]] || [ -z "$(find "$d"/{cur,new,tmp} -type f)" ]; then echo ignore "$d"; continue; fi; mv -vi "$d" "$newdest/$d"; done # subscribe new user to new folders find "$newdir" -maxdepth 1 -type d -name ".$newfolder*" -printf "%f\n" | while read d; do echo ${d/#./}; done | cat - "$newdir/subscriptions" | sort -u > "$newdir/subscriptions.new" mv "$newdir/subscriptions.new" "$newdir/subscriptions" # fix ownership/permissions chmod -R u=rwX,go= "$newdir" chown -R $newuser:$newgroup "$newdir" # Check ownership/permissions find "$newdir" -not -perm 700 -type d -ls find "$newdir" -not -perm 600 -type f -ls find "$newdir" -not -user $newuser -ls find "$newdir" -not -group $newgroup -ls